eth_sendTransaction returns hash, but then eth_getTransactionReceipt returns null.
What am I doing wrong?
cat <<EOF | curl -X POST --data @- http://127.0.0.1:8080
{
"jsonrpc":"2.0"
,"method":"eth_sendTransaction"
,"params": [{
"from": "52c39d8d9aec8f6cdc471ac4e7b7c8783eebc882",
"gas": "0x76c0",
"gasPrice": "0x0",
"value": "0x0",
"data": "6060604052603b8060116000396000f300606060405260e060020a600035046360fe47b1811460245780636d4ce63c14602e575b005b6004356000556022565b6000546060908152602090f3"
}]
,"id":1
}
EOF
{"id":1,"jsonrpc":"2.0","result":"0x4942ed47bf5ad59e65f0a8be27ca9edd7c110503d676176bc0b9fe1b8238919a"}
cat <<EOF | curl -X POST --data @- http://127.0.0.1:8080
{
"jsonrpc":"2.0"
,"method":"eth_getTransactionReceipt"
,"params":["0x4942ed47bf5ad59e65f0a8be27ca9edd7c110503d676176bc0b9fe1b8238919a"]
,"id":1
}
EOF
{"id":1,"jsonrpc":"2.0","result":null}
Are you sure that TX is confirmed already? If tx is still pending, null is valid result.
@sammy007, could you clarify please.
I do what documentation tells me to do:call
eth_sendTransaction, followed by eth_getTransactionReceipt.
If I need to be sure of something in between, could you show another call I need to make?
I have one node and there's some time between the calls, if that helps.
Thank you!
A transaction receipt is generated after the transaction had been processed. It contains things like the amount of gas used or the contract address which are calculated during processing. When you submit a transaction it takes some time before the transaction is processed and the receipt is generated. Until then null is returned as an indication that there is currently no receipt found for the given hash.
If you are on a private network make sure you are mining and the transaction enters and leaves the transaction pool. If you restart the node before the transaction is processed it's lost. If you are not make sure you are connected to the netwerk and have some peers.
In your example you are using a gas price of 0. I'm not sure if there are miners out who are accepting this but this is probably the reason your transaction is not being processed. I would recommend removing the gas price, the node will then use a default price which is currently 0.00001 ether.
I think this is on a private network (otherwise, as @bas-vk, pointed out, this probably won't work).
Please let the transaction be confirmed (mined) and try again. Please let us know if this issue is solved or not.
it is on a private network, with only one node.
I simply follow the directions in the documentation, which suggests calling these two functions in this order.
If there's something else that needs to be done in between, could you show the curl command please or update the docs?
I'm not that up-to-speed on the api to translate "let the transaction be confirmed" into the curl command, would appreciate a copy-paste line.
thanks.
First check that the transaction has been mined and therefore included in a block with eth_getTransaction(txhash). If the result of this has a block hash & block number, then it should also have a receipt, accessible with eth_getTransactionReceipt(txhash)
As pointed out earlier, null is a valid result when a receipt is not (yet) avaialble
You need to be mining on your private network. It will be null until your TX gets mined. You can wrap your TX in a callback (error first) and periodically check the TX receipt to see that your TX made it onto the chain.
What you've described is the correct behavior as planned.
What is your expectation of what it should return when the transaction is not yet mined?
On Dec 12, 2015, at 02:21, Anthony Eufemio [email protected] wrote:
You need to be mining on your private network. It will be null until your TX gets mined. You can wrap your TX in a callback (error first) and periodically check the TX receipt to see that your TX made it onto the chain.
—
Reply to this email directly or view it on GitHub.
What is your expectation of what it should return when the transaction is not yet mined?
I would expect web3.eth.getTransactionReceipt to return only when the tx was actually mined.
How can we know a transaction has been mined otherwise?
Here is what I tested:
var whenTransactionMined = function(tx, callback)
{
var check = setInterval(
() => {
web3.eth.getTransaction(tx, (e, r) => {
if (r.blockHash != 0)
{
clearInterval(check);
callback(r);
}
})
},
5000
);
};
whenTransactionMined(result, (block) => {console.log(block)});
When the tx is mined, r.blockHash is properly set.
But that's a very cumbersome way to deal with this.
Can't we have some kind of event/callback oriented way to know when the tx was mined ?
Regards,
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
The issue is still relevant.
Since geth 1.8 getTransactionReceipt RPC call started to fail with error: -32000 unknown transaction, and it happens more often.
@xuhcc This is an old issue with outdated information. Please open a new issue with detailed information if the problem still persists.
Most helpful comment
I would expect
web3.eth.getTransactionReceiptto return only when the tx was actually mined.How can we know a transaction has been mined otherwise?
Here is what I tested:
When the tx is mined, r.blockHash is properly set.
But that's a very cumbersome way to deal with this.
Can't we have some kind of event/callback oriented way to know when the tx was mined ?
Regards,