1

I have a list of ethereum addresses and private keys, I need to write an automation script which checks for the balance in each address and transfer the balance funds to another ethereum address. My question is how I perform the fund transfer with address and privateKey using web3js

Thanks in Advance

1

If you want to programmatically create transactions for accounts where you have the private key, you can call the web3.eth.accounts.signTransaction function to create a transaction using web3.js:

web3.eth.accounts.signTransaction(tx, privateKey [, callback]);

This will return a rawTransaction string which can be directly sent to the network using web3.eth.sendSignedTransaction:

web3.eth.sendSignedTransaction(signedTransactionData [, callback])

Getting the balance of the account should be even simpler. Just call web3.eth.getBalance for the public address you have for that account:

web3.eth.getBalance(address [, defaultBlock] [, callback])

I hope this helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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