Take JPG store as an example. When someone lists an NFT for sale there, or when someone buys an NFT there, a smart contract governs that transaction.

Can sql queries against the db-sync generated blockchain data "see" that? I'd like to write sql queries against the db-sync data that show the most recent transaction involving a particular smart contract, but I'm not sure what to query for...


Here is a call to opencnft's free api which allows me to know the most recent transactions involving a particular NFT policy, sorted by date. If I want to simple replicate that by using sql queries against db-sync, that's also something I am interested in:


However...that makes the NFT policy the focus of the query, whereas I am also looking for a query that would find the same resulting transaction had occurred but with the Smart Contract being used as the criteria I am querying on.

So in plain language - there are two generalized queries I am hoping to create as a basis and launching pad for other queries?

  1. select the latest transaction 'Smart Contract X' was involved in, and the assets involved in that transaction.

  2. select the latest transaction 'Policy Id X' was involved in and any Smart Contracts and/or other assets involved in the transaction.

...sort of like looking for the same thing but from two different perspectives in terms of the criteria and tables involved in building the query?

  • What data specifically are you hoping to get out of db-sync ? Commented Aug 8, 2022 at 1:51
  • That a smart contract was executed, and what assets / values were involved..? For example: If someone lists an NFT for sale on JPG store, then the policy of the JPG store smart contract is the signature I am looking for, and I am interested in what asset was listed for sale. The smart contract has an identity, the NFT being listed for sale has an identity, so I am assuming I should be able to build a query that returns the last time a smart contract was executed in a transaction, and what assets are involved in that transaction? Of course, I may have a misconception about what can be queried. Commented Aug 8, 2022 at 1:57
  • Updated with an Edit to give a comparison to opencnft.io Commented Aug 8, 2022 at 2:23

2 Answers 2


Would something like the Blockfrost API for watching transactions happening against an address work for you? Something like this maybe? You could also query for assets held by an address

Ultimately, you can query specific details using multiple queries and filters on the JSON data returned and probably achieve what you want.

  • Thanks Bharat - I have used Blockfrost, but am seeking to do everything I want to do using only my own node, db-sync, and wallet. I do already use db-sync to watch addresses. My question is more about how to query what tables to find records related to the use of a specific smart contract - my thought was to build a query that uses the ID of a smart contract as the key to query on, and hopefully to find it's most recent execution, and the tx_outs/assets associated with that, so I could say basically: show me the last time this SC ran and what assets were inputs/outputs in that transaction. Commented Aug 8, 2022 at 20:20

Maybe oura is something for you to be worth looking into. https://github.com/txpipe/oura

In a nutshell: Oura allows you to watch for patterns in the blockchain as it progresses and then if you have found a match trigger your own events. So in your case you could have different filters that would trigger the same web enpoint but offer different payloads.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.