Guest User

Untitled

a guest
Jan 16th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. const web3 = new Web3();
  2. web3.setProvider(new
  3. web3.providers.HttpProvider("https://mainnet.infura.io/XXXXXX"));
  4. var count = web3.eth.getTransactionCount(from_addr);
  5. var contract = web3.eth.contract(abi).at(contract_addr);
  6.  
  7. var data = contract.transfer.getData(to_addr, 10, {from: from_addr});
  8. var gasPrice = web3.eth.gasPrice;
  9. var gasLimit = 90000;
  10.  
  11. var rawTransaction = {
  12. "from": from_addr,
  13. "nonce": web3.toHex(count),
  14. "gasPrice": web3.toHex(gasPrice),
  15. "gasLimit": web3.toHex(gasLimit),
  16. "to": to_addr,
  17. "value": 0,
  18. "data": data,
  19. "chainId": 0x01
  20. };
  21.  
  22. var privKey = new Buffer(priv_key, 'hex');
  23. var tx = new Tx(rawTransaction);
  24.  
  25. tx.sign(privKey);
  26. var serializedTx = tx.serialize();
  27.  
  28. web3.eth.sendRawTransaction('0x' + serializedTx.toString('hex'), function(err, hash) {
  29. if (!err)
  30. console.log(hash);
  31. else
  32. console.log(err);
  33. });
Add Comment
Please, Sign In to add comment