0

I'm having trouble sending tokens to many addresses simultaneously. So I have to make one tx for each recipient, it take a lot of time and i have to wait for next transaction.

Can someone help me how to do this?

web3.eth.requestAccounts().then(function(accounts){ 
    var acc = accounts[0]; 
    Contract.methods.transfer(recipient, amt).send(
        {from: acc, gas: 54151 }
    ).then(function(tx){
        if(tx){ console.log(tx); 
    } 
  }); 
});
ruud
  • 743
  • 13
  • 22
  • can you send the tokens asynchronously? – monterico Mar 22 '23 at 10:10
  • 2
    Can you show us a code example of how you send them? You can maybe send them in parallel (you don't wait for the first one to complete before sending the second, and in each callback you increment a counter, then test if the counter is equal to the number of request sent) – Kaddath Mar 22 '23 at 10:13
  • web3.eth.requestAccounts().then(function(accounts){ var acc = accounts[0]; Contract.methods.transfer(recipient, amt).send({from: acc, gas: 54151 }).then(function(tx){ if(tx){ console.log(tx); } }); }); – Ashwani Kashyap Mar 22 '23 at 13:42
  • 1
    This code should be embedded into the question, and not posted as a comment. Please use 'edit' – HoRn Mar 24 '23 at 03:23

1 Answers1

0

You can send to multiple address simultaniously if you have used your privateKey.

Without privateKey, each transaction has to be approve by sender which will take alot of time. Using privateKey will bypass this verification/approving process But this is dangerous.

If someone gets hold of your privateKey, your account will be gone, metamask or other wallets wont help