2

how can i send to account2,account3 and account4 in one time transaction

var Tx = require('ethereumjs-tx')

const Web3 = require('web3')
const web3 = new Web3('https://ropsten.infura.io')

const account1 = '0x9c56......'

const account2 = '0xb22.....'

const account3 = '0x7717d10.......'

const account4 = '0xdt7d10.......'


const privateKey1 = Buffer.from('bla bla bla', 'hex')

web3.eth.getTransactionCount(account1, (err, txCount) => {

const txObject = {
  nonce: web3.utils.toHex(txCount),
  to: account2,
  value: web3.utils.toHex(web3.utils.toWei('0.1', 'ether')),
  gasLimit: web3.utils.toHex(21000),
  gasPrice: web3.utils.toHex(web3.utils.toWei('10', 'gwei'))
}

const tx = new Tx(txObject)
tx.sign(privateKey1)

const serializedTx = tx.serialize()
const raw = '0x' + serializedTx.toString('hex')

web3.eth.sendSignedTransaction(raw, (err, txHash) => {
  console.log('txHash:', txHash)
  // Now go check etherscan to see the transaction!
})
})
1

You can't.

Transactions are only sent with from single source address to single destination address.

To send multiple transactions , create as many transactions as destinations accounts you have, in a loop.

Or, you can create a contract for this task and send single transaction to a contract, which is going to send as many transfers as required, using destination addresses you are going to pass to it on input parameter.

  • please show me example how to make a looping from that script – slank-blues Sep 12 '18 at 0:25

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.