I have a system where there'll be dozens of accounts, for ETH and tokens. I'll have access to the private keys of those.

From time to time I'll need to withdraw all of the coins in each account, in ETH and tokens alike, to my main wallet.

How will I implement it? Meaning, it should be done dynamically, in a script, will I'll run locally on my computer. And the gas price should be determined dynamically as well as the current balance.

1 Answer 1


Firstly you will need to have enough ETH in the wallet for the transaction, otherwise, you will not be able to send anything.

Secondly most tokens on ETH chain are following the ERC20 standard, which directs that the balances of all the holders are written in contract's storage. This means that you need to have a tokens contract address to check if you have any balance on it. You can easily solve this howeven by using some data provider, which tells you which tokens your wallet hold (etherscan).

And regarding the transfer, you could wrap up all the transactions by deploying a smart contract, that implements a function that sends the whole balance for every token defined to your main wallet. You could then write a bot using web3js to initiate transactions from different accounts.

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.