Guest User

Untitled

a guest
Mar 22nd, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. const web3 = require('web3');
  2. const EthereumTx = require('ethereumjs-tx');
  3. const address = 'publicAddress';
  4. const privateKey = Buffer.from('privateKey', 'hex');
  5.  
  6. const txParams = {
  7. nonce: web3.toHex(web3.eth.getTransactionCount(address)),
  8. to: destAddress,
  9. gasPrice: web3.toHex(21000000000),
  10. gasLimit: web3.toHex(21000),
  11. value: web3.toHex(web3.toWei(1, 'ether')),
  12. data: '',
  13. // EIP 155 chainId - mainnet: 1, ropsten: 3
  14. // chainId: 3
  15. };
  16.  
  17. const tx = new EthereumTx(txParams);
  18. tx.sign(privateKey);
  19. const serializedTx = tx.serialize();
  20. // const serializedTx = `0x${tx.serialize().toString('hex')}`;
  21. /*web3.eth.sendRawTransaction(serializedTx, (error, data) => {
  22. if (!error) {
  23. return console.log(data);
  24. }
  25. return console.log(error);
  26. });*/
Add Comment
Please, Sign In to add comment