Circumstance
I have followed all indications from this GH issue and from other SO posts. The transaction gets successfully broadcasted but no tokens are transferred.
When I check the balance before and after running the code, I get the same result: 10000, which is the original supply.
const Tx = require('ethereumjs-tx');
const config = require('../config');
const contract = require('../contract')('PaulCoin', config.contracts[0]);
const web3 = require('../web3');
const main = async () => {
try {
const count = await web3.eth.getTransactionCount(config.accounts[0]);
const nonce = web3.utils.toHex(count);
const txValue = web3.utils.toHex(parseInt(process.argv[2], 10) || 10);
const from = web3.utils.toChecksumAddress(config.accounts[0]);
const to = web3.utils.toChecksumAddress(config.accounts[1]);
const rawTx = {
nonce: nonce,
from: from,
to: to,
value: '0x0',
gasLimit: '0x30D40', // 54,000
gasPrice: '0x2CB417800', // 12 gwei
data: contract.methods.transfer(to, txValue).encodeABI(),
chainId: '0x03'
};
const privateKey = Buffer.from(config.private, 'hex');
const tx = new Tx(rawTx);
tx.sign(privateKey);
const serializedTx = tx.serialize();
const receipt = await web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex'));
console.log(`Receipt info: ${JSON.stringify(receipt, null, '\t')}`);
console.log(`From\'s balance after transfer: ${await contract.methods.balanceOf(from).call()}`);
console.log(`To\'s balance after transfer: ${await contract.methods.balanceOf(to).call()}`);
} catch (err) {
console.log(err);
}
};
main();
Environment
- node
9.3.0
- web3
1.0.0-beta.35
- infura
ropsten
- os
osx 13.13.5
a
or 10 in decimal, just as it should. You can check out the tx and the contract yourself.transfer
.to
address is ropsten.etherscan.io/address/…, which is not a contract. (There's no associated code.)