I want to send eth by using web3 on testnet. Source address is 0xbddf0bf3ac858d7fb8a2bdda55884d61779ba5a9. The destination is 0x8005ceb675d2ff8c989cc95354438b9fab568681.
I found the example on web3 reference page. I can imagine how to use it. However I don't know what is "data" and how to calculate the gasLimit.
var Tx = require('ethereumjs-tx');
var privateKey = new Buffer('xxx', 'hex')
var GAS = web3.eth.estimateGas({
to: "0x8005ceb675d2ff8c989cc95354438b9fab568681",
data: "WHAT IS DATA"
});
var rawTx = {
nonce: '0x00',
gasPrice: GAS,
gasLimit: 'HOW AMOUNT OF GAS SHOULD I SET',
to: '0x8005ceb675d2ff8c989cc95354438b9fab568681',
value: '0x01',
data: 'WHAT IS DATA'
}
var tx = new Tx(rawTx);
tx.sign(privateKey);
var serializedTx = tx.serialize();
web3.eth.sendRawTransaction(serializedTx.toString('hex'), function(err, hash) {
if (!err)
console.log(hash);
});
https://github.com/ethereum/wiki/wiki/JavaScript-API#web3ethsendrawtransaction
Update 1
Seems data is optional value or something…
data – all of the interesting stuff goes here
What is the ethereum transaction data structure?
In Bitcoin, transaction fee is calculated by the size of transaction. Thus, I thought "data" is related to fee…
Best Answer
To just send ETH, set
gasLimit
to 21,000 and removedata
(or set it to empty''
). The base fee of 21,000 gas assumes thatto
is not a contract.If
to
is a contract and you wanted to invoke a function onto
, you would setdata
according to the function you wanted to invoke and any arguments it needed. For this, the value ofdata
would be encoded according to the ABI. Usingweb3.eth.estimateGas
can help see how much gas is needed to execute the function and whatever functions it may also invoke.data
can also be used to simply store bytes on the blockchain. Ifto
is not a contract, you can statically compute the fee (in addition to the base 21,000 gas) as 4 gas for a zero byte, 68 gas for non-zero byte. Related: Mist: What does "intrinsic gas too low" mean?