How do I get the block confirmations for a specific transaction using the JSON RPC?
This is information that would come inside the transaction JSON in bitcoin but it doesn't seem to come in ethereum.
What am I missing?
When you send a transaction, you will receive back a transaction hash.
Use the command getTransactionByHash({transaction hash}) to retrieve the transaction details. Your blockNumber should be non-null if the transaction has been mined and included into a block.
The call is documented in https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_gettransactionbyhash with the following example:
// Request
curl -X POST --data '{"jsonrpc":"2.0","method":"eth_getTransactionByHash","params":["0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238"],"id":1}'
// Result
{
"id":1,
"jsonrpc":"2.0",
"result": {
"hash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b",
"nonce":"0x",
"blockHash": "0xbeab0aa2411b7ab17f30a99d3cb9c6ef2fc5426d6ad6fd9e2a26a6aed1d1055b",
"blockNumber": "0x15df", // 5599
"transactionIndex": "0x1", // 1
"from":"0x407d73d8a49eeb85d32cf465507dd71d507100c1",
"to":"0x85h43d8a49eeb85d32cf465507dd71d507100c1",
"value":"0x7f110" // 520464
"gas": "0x7f110" // 520464
"gasPrice":"0x09184e72a000",
"input":"0x603880600c6000396000f300603880600c6000396000f3603880600c6000396000f360",
}
}
Then call eth_blockNumber (https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_blocknumber) to get the current block height. Your number of confirmations is the eth_blockNumber result minus the eth_getTransaction blockNumber result.
The answer given by BokkyPooBah is perfect and as for how does that relate to the confirmations, I raised the same question here: How does (current block number - block number of a given transaction) gives the confirmation count?.
You might also refer to the comments for the question: Ethereum network transaction confirmation coverage. The idea is that, if your transaction was included in block number 100 (just assume) and the current block number is 160, it means 60 random miners accepted the block 100 as valid and added to that chain and so you can say that you have 60 confirmations. This is all about consensus.