3

Problem

According to this question, it is possible to send data to a non-contract address in Ethereum.

However, if I run my code which sends ether from the first account to the second account on Ganache, I get this:

err Error: Returned error: Attempting to run transaction which calls a contract function, but recipient address 0xe7d6a2a1cbed37ee7446d78fd5e6b38aaae3f3b2 is not a contract address

Code

const Tx = require('ethereumjs-tx');

const config = require('./config');
const web3 = require('./web3');

const genRawTx = async () => {
    const count = await web3.eth.getTransactionCount(config.accounts[0]);
    const nonce = web3.utils.toHex(count);

    const txValue = web3.utils.toHex(web3.utils.toWei('0.5', 'ether'));
    const txData = web3.utils.asciiToHex('Does this work?');
    console.log('txData', txData);

    const rawTx = {
        nonce: nonce, // Nonce is the times the address has transacted, should always be higher than the last nonce 0x0#
        from: config.accounts[0],
        to: config.accounts[1],
        value: txValue, // The value we are sending '0x16345785d8a0000' which is 0.1 Ether
        gas: '0xEA60', // 0xEA60 is 60,000
        gasPrice: '0x09184e72a000', // 0x09184e72a000 is 10 szabos or 10,000 gwei
        data: txData
    };

    const privateKey = Buffer.from(config.private, 'hex');
    const tx = new Tx(rawTx);
    tx.sign(privateKey);
    const serializedTx = tx.serialize();

    web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex'), (err, data) => {
        if (err) {
            console.log('err', err);
        } else {
            console.log('data', data);
        }
    })
    .on('receipt', console.log);
};

genRawTx();

Tools

  • node 9.3.0
  • web3 1.0.0-beta.34
  • ganache 1.1.0

Is this a bug or I'm missing something?

2

Yes, it's a bug on Ganache.

If you look at the source code you'll see your error message.

There's a function _transactionIsContractCall() defined on line 849 which returns true if the transaction has some data. Which it does.

So Ganache is now thinking that you're calling a contract, so it expects something on code (the function you're calling on the contract).

But since your calling a non-contract account, you're not sending anything on code, so a new TXRejectedError is generated and the error messages is shown.

In Ethereum, you should be able to send data in every transaction, so I should categorize this as a bug.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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