Created
November 26, 2020 21:02
-
-
Save eum602/bd9d5f8229e0612d10f9f7ca84be8074 to your computer and use it in GitHub Desktop.
Example of how to send ethers in ethereum
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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