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?