Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Set Variable for PrivateKey in TestRPC
- var pKey1 = ""
- //Require EthTx
- var EthTx = require("ethereumjs-tx")
- //Create Buffer Encoded Class
- var pKey1x = new Buffer(pKey1, 'hex')
- //Create Raw Transaction Data Structure
- var rawTx = {
- nonce: web3.toHex(web3.eth.getTransactionCount(acct1)),
- to: acct2,
- gasPrice: web3.toHex(2000000000000),
- gasLimit: web3.toHex(21000),
- value: web3.toHex(web3.toWei(25, 'ether')),
- data: ""
- }
- //new Tx Variable and pass in rawTx
- var tx = new EthTx(rawTx)
- //Sign with Private Key
- tx.sign(pKey1x)
- //Serialize to String
- tx.serialize().toString('hex')
- //Send Raw Transaction
- web3.eth.sendRawTransaction(`0x${tx.serialize().toString('hex')}`, (error, data) => {
- if(!error) { console.log(data) }
- })
- //Inspect Transaction
- web3.eth.getTransaction("[[put transaction string that was returned]]")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement