Please login or register.

RPC Get Transaction by Hash

Is there any available call to check a transaction by its hash? I'm looking for a way to check how many confirmations a transaction has, so I'd need to query transactions by hash to check the block number it was mined on.

Replies: 7
bigreddmachine posted 8 years ago Replies: 1 | Weight: 0 | Link [ - ]

Yes. The daemon json_rpc list is not that well documented. But an example is here:

https://moneroexamples.github.io/python-json-rpc/

Depending on your need, you might be better off just using a blockchain explorer API, like this one:

http://moneroblocks.info/api

Reply to: bigreddmachine
got3nks posted 8 years ago Replies: 1 | Weight: 0 | Link [ - ]

I'd rather not rely on 3d parties. And I don't understand which example to look at for getting a transaction by its hash.

Reply to: got3nks bigreddmachine
bigreddmachine posted 8 years ago Replies: 1 | Weight: 0 | Link [ - ]

My bad. I was thinking you wanted to look up the block hash. Yeah, it's not documented there (or really all that well anywhere, tbh).

I'm currently working on a python package (pymonero) that has this implemented. I'm not ready to say that this is a stable release or anything, but if you want to take a look at it you can see how I query transactions by hash in it. The daemon-related functions are all pretty well tested.

GitHub repo here:

https://github.com/Monero-Monitor/pymonero

There is an example on the main readme for querying a transaction by hash. Let me know if the source code is too convoluted for you to see how the method works.

Reply to: bigreddmachine got3nks bigreddmachine
got3nks edited 8 years ago Replies: 1 | Weight: 0 | Link [ - ]

I can't see in your examples how to query a transaction by its hash only.. Am I missing anything?

Reply to: got3nks bigreddmachine got3nks bigreddmachine
bigreddmachine edited 8 years ago Replies: 1 | Weight: 0 | Link [ - ]

My documentation could use some work... it's mostly just there for me right now as I test things, which is probably why you're having trouble deciphering it.

This is the bit you want to look at:

Get information on any transactions in block

In that particular example, I've set it up to do a very specific task that I was interested in - to check a block for non-coinbase transactions, and if there were any, to get the tx information. BUT, that's not necessary if all you want to do is look up a tx by hash.

The function 'get_transactions' has two inputs: 'tx_hashes' and 'block'. However, 'block' is option and not actually part of the rpc call. It's just a thing I added for optional book keeping.

The most basic implementation of this is then:

import pymonero
bitmonero = pymonero.Bitmonero()
tx_hashes = 'hash...' # OR: tx_hashes = ['hash...', 'hash...', etc...]
transactions = bitmonero.get_transactions(tx_hashes)

If you want to see the output from this, the easiest way is to add something like this:

# if tx_hashes was a string:
print(transactions.to_JSON())

# if tx_hashes was an array of strings:
n_txs = len(tx_hashes)
for i in range(0, n_txs):
    print(transactions[i].to_JSON())

This is calling the following rpc POST method:

{ 
    "txs_hashes": [ < list of hashes > ],
    "decode_as_json": True
}
Reply to: bigreddmachine got3nks bigreddmachine got3nks bigreddmachine
got3nks posted 8 years ago Replies: 1 | Weight: 0 | Link [ - ]

Thank you, I was able to lookup a transaction by its hash.

curl http://localhost:18081/gettransactions -d '{"txs_hashes" : ["45f21d......"], "decode_as_json": True }'

The call doesn't return the block the transaction was mined on though. How do I make sure the transaction was not mined on an orphan block?

Reply to: got3nks bigreddmachine got3nks bigreddmachine got3nks
bigreddmachine posted 8 years ago Weight: 0 | Link [ - ]

Great question. I do not believe that is possible as of today, but should be able to be implemented. I've created a GitHub issue, so hopefully it will be addressed!

https://github.com/monero-project/bitmonero/issues/707

May I ask what your use case is?

If you are checking if a transaction that you either sent or received is in a block, I think that you should be using simplewallet's json_rpc methods:

https://github.com/monero-project/bitmonero/blob/master/src/wallet/wallet_rpc_server.h#L63