Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2016
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. //Set Variable for PrivateKey in TestRPC
  2. var pKey1 = ""
  3.  
  4. //Require EthTx
  5. var EthTx = require("ethereumjs-tx")
  6.  
  7. //Create Buffer Encoded Class
  8. var pKey1x = new Buffer(pKey1, 'hex')
  9.  
  10. //Create Raw Transaction Data Structure
  11. var rawTx = {
  12. nonce: web3.toHex(web3.eth.getTransactionCount(acct1)),
  13. to: acct2,
  14. gasPrice: web3.toHex(2000000000000),
  15. gasLimit: web3.toHex(21000),
  16. value: web3.toHex(web3.toWei(25, 'ether')),
  17. data: ""
  18. }
  19.  
  20. //new Tx Variable and pass in rawTx
  21. var tx = new EthTx(rawTx)
  22.  
  23. //Sign with Private Key
  24. tx.sign(pKey1x)
  25.  
  26. //Serialize to String
  27. tx.serialize().toString('hex')
  28.  
  29. //Send Raw Transaction
  30. web3.eth.sendRawTransaction(`0x${tx.serialize().toString('hex')}`, (error, data) => {
  31. if(!error) { console.log(data) }
  32. })
  33.  
  34. //Inspect Transaction
  35. web3.eth.getTransaction("[[put transaction string that was returned]]")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement