Skip to content

Instantly share code, notes, and snippets.

@sunnycyk
Last active August 16, 2018 04:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sunnycyk/086678eae60e550ebf4def23b6531777 to your computer and use it in GitHub Desktop.
Save sunnycyk/086678eae60e550ebf4def23b6531777 to your computer and use it in GitHub Desktop.
Web3
// const Web3 = require('web3')
// const Tx = require('ethereumjs-tx');
// const web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'))
// ....
const data = contractInstance.methods.myMethods(param...).encodeABI()
const tx = new Tx(null)
tx.nonce = await web3.eth.getTransactionCount(hd_wallet_address)
tx.from = hd_wallet_address
tx.gasPrice = GAS_PRICE
tx.gasLimit = GAS_LIMIT
tx.value = 10000 // if calling payable function
tx.to = CONTRACT_ADDRESS
tx.data = data
tx.sign(hd_wallet_private_key)
// Send Signed Raw Transaction
web3.eth.sendSignedTransaction('0x' + tx.serialize().toString('hex'))
.on('receipt', console.log)
.on('error', console.error)
.on('transactionHash', console.log)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment