I have a smart contract on the BSC network that has created a large number of children and stored the address of each. In the child smart contract, the UUDT token is stored. Also, each child smart contract has a withdrawal method that transfers all balances to a wallet with a fixed address. Can I have a method in the parent smart contract that calls the withdrawal method of all the children at once and in the form of a transaction? If we can have such a method, how is the gas fee of this transaction calculated?
Yes, you can batch multiple transactions in one. just make a for loop, that calls each contracts transfer function. I presume all child contract have the same layout? You could do something like:
What this does is it will call child's withdraw function and input 1000 as input.
Regarding the gas, there is a fixed price of 21000 for each transaction + the commands you use in your code, so it is definitely cheaper to batch them and pay the 21000 gas only once.