Skip to content

Instantly share code, notes, and snippets.

@eum602
Created November 26, 2020 21:02
Show Gist options
  • Save eum602/bd9d5f8229e0612d10f9f7ca84be8074 to your computer and use it in GitHub Desktop.
Save eum602/bd9d5f8229e0612d10f9f7ca84be8074 to your computer and use it in GitHub Desktop.
Example of how to send ethers in ethereum
web3 = new Web3...
privKey=...
txObject = {
nonce: web3.utils.toHex(txnCount),
gasPrice: web3.utils.toHex(0),
gasLimit: web3.utils.toHex(parseInt(MAX_GAS_PER_TX)),
to: addressTo,
value: web3.utils.toHex(web3.utils.toWei(valueInEther, 'ether')),
data
};
const tx = new ethTx(txObject)
tx.sign(privKey)
const serializedTx = tx.serialize()
const rawTxHex = '0x' + serializedTx.toString('hex')
const receipt = await web3.eth.sendSignedTransaction(rawTxHex)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment