I'm currently writing a function using Web3 to send our tokens, it's currently sending ETH instead. Since we're doing this straight on the main network (We like taking risks), the transaction fees are adding up.
If anyone can help us see how to send our token rather than ETH it would be really appreciated.
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);
});
I've pretty much copied and pasted this question: How to send ERC20 token using Web3 API?. They seemed to have found the way to send tokens whereas I'm still sending ETH.
Any advice would be much appreciated.
Thanks