How to get the TXid from a block API request?

I am using the REST API to get the block information, for example /v2/blocks/8185771 i get a back a JSON object containing top level “block” object with a list of transaction insid “txns” each one has all the information i need except the TxID, is there a way to get it based on the blocks in the REST API? if not can i recreate the TxID from the “sig” value plus the “txn” value? i am using PHP so no SDK

Thanks

The block API request does not return the transaction id since it’s a calculated field.
If you need to work with transaction ids, I would suggest that you would use the /v1/account/{address}/transactions with some known address.

The transaction ID can be calculated from the block itself, but it might not be a trivial operation. If I recall correctly, you would need to add few more fields which are not stored in the block before hashing the entire structure.

Would you mind sharing with us what you’re trying to do ? Using the API above might be a good starting point, but using the Indexer V2, for instance, might makes the implementation faster, more robust, and require less updates.

Hi,

I am trying to check if any of my addresses received a new transaction, and if so, log it in my local DB with the relevant information. i was using the block number to make sure i am synced and didn’t miss any transaction.

i don’t have an indexer running, but i noticed i can use firstRound and lastRound in your API endpoint suggestion to search specific blocks per address so by changing my function a bit i think i can get the info i need.

thanks for your quick reply, ill wait a bit to see if there is any other solution, will mark it as solved if no other easier solution is offered as it’s good enough for me.

The reason I suggested the usage of the indexer v2 is that the indexer is using a Postgres backend to store the data. Querying the information from a Postgres database is something that is widely supported, and could allow you to perform more complicated business operations there.