0

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
6
  • at what block was your transaction mined?
    – Nulik
    Commented Jul 28, 2018 at 16:55
  • first thing I would do, is to get the block number, get the transaction input and decode it, check that the value transferred is not 0
    – Nulik
    Commented Jul 28, 2018 at 16:57
  • Just checked now, it's not 0, but a or 10 in decimal, just as it should. You can check out the tx and the contract yourself. Commented Jul 28, 2018 at 17:09
  • Are you sure that's the right code for the contract? It doesn't appear to have a function called transfer.
    – user19510
    Commented Jul 28, 2018 at 18:09
  • Oh, actually, the transaction isn't being sent to a contract at all. The to address is ropsten.etherscan.io/address/…, which is not a contract. (There's no associated code.)
    – user19510
    Commented Jul 28, 2018 at 18:10

1 Answer 1

2

The transaction is being sent to the address 0x19149798f777a3d738777334ccbf0063a04fca3b, which is not a contract.

No ERC20 transfer occurs because no transaction was sent to an ERC20 token contract.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.