Last active
August 16, 2018 04:15
-
-
Save sunnycyk/086678eae60e550ebf4def23b6531777 to your computer and use it in GitHub Desktop.
Web3
This file contains hidden or 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
// 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