0

I've set up a private network and generated around 100 addresses. Exactly 80 of those addresses have a balance of 10 or more ETH, while the rest of the addresses have balances of 0. I've also preallocated 10,000 ETH to a separate address (let's call it base) in genesis.json.

I would like to send 5 ETH from base address to every address that has a balance >= 10 ETH. I've seen examples for ERC20 tokens around but couldn't find anything using the actual currency of a chain instead of a token.

Also, is it possible to check balances and send the desired amount to all the addresses created on the network without me having to save every one addresses in a separate file and load them up when sending?

Any help would be greatly appreciated. Thank you!

0

You can definitely send Ethers (the base currency) to any address. And you can impose any conditions before sending.

You only need the address of the receiver and not their keystore file or anything. A sample code is given for refrence.

_self.SENDETHER=function(from,to,password,amount){
    return new Promise(function(fullfill,reject){
      web.eth.getBalance(to)
        .then(function(recepientEthBal){
          if(recepientEthBal > 10){ // any condition can be imposed here
            web3.eth.personal.unlockAccount(from, password).then(function (result) {
              web3.eth.sendTransaction({from:from,to:to,value:web3.utils.toWei(amount,"ether")})
                .on('transactionHash', function(txHash){
                    console.log("Transaction hash : "+txHash);
                    fullfill(txHash);
                }).catch(function(err){
                    console.log(err);
                    reject("Unable to send transaction");
                });
              }).catch(function(err){ //catch of unlock account
                  console.log(err);
                  reject("Unable to unlock sender's account with given passphrase");
              });
          }
        })
        .catch(function(err){
          console.log(err);
          reject(err);
       })     
  });
}
  • Thanks for your answer. However what I'm trying to do is, first to collect all the addresses ever created on the network and second filter out the ones with a balance >=10. I know i can do that using web3.js connected to a node i have exposed the RPC. My question is, if there are several nodes on the network and let's say one of them doesn't expose the RPC can I still get the accounts created on that node? – Pewpew May 6 '18 at 22:47

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.