0

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?

1 Answer 1

1

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:

address(child).call(abi.encodeWithSignature("withdraw(uint256)", 1000))

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.