Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const web3 = new Web3();
- web3.setProvider(new
- web3.providers.HttpProvider("https://mainnet.infura.io/XXXXXX"));
- var count = web3.eth.getTransactionCount(from_addr);
- var contract = web3.eth.contract(abi).at(contract_addr);
- var data = contract.transfer.getData(to_addr, 10, {from: from_addr});
- var gasPrice = web3.eth.gasPrice;
- var gasLimit = 90000;
- var rawTransaction = {
- "from": from_addr,
- "nonce": web3.toHex(count),
- "gasPrice": web3.toHex(gasPrice),
- "gasLimit": web3.toHex(gasLimit),
- "to": to_addr,
- "value": 0,
- "data": data,
- "chainId": 0x01
- };
- var privKey = new Buffer(priv_key, 'hex');
- var tx = new Tx(rawTransaction);
- tx.sign(privKey);
- var serializedTx = tx.serialize();
- web3.eth.sendRawTransaction('0x' + serializedTx.toString('hex'), function(err, hash) {
- if (!err)
- console.log(hash);
- else
- console.log(err);
- });
Add Comment
Please, Sign In to add comment