Contract Events
In addition to looking for transactions targeting a contract address, Sort also stores logs/events targeting the contract address but originated from another contract. To illustrate this, NFT contracts contain a Transfer function
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes calldata data
) external;
If an NFT is transferred as part of a sale on an exchange, Sort will store the event and make it searchable via Sort SQL.
As an example, take the Bored Apes contract. Say we want to find the most recent Transfer
event and a specific detail about the approval associated with the safeTransferFrom
-- Take the most recent transactions by sorting by the associated block, descending.
-- Narrow this by just the safeTransferFrom call
SELECT * FROM ethereum.transaction t, ethereum.block b
WHERE t.block_id = b.id AND function = 'safeTransferFrom'
AND to_address = '0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d'
ORDER BY block_number DESC
-- Now we take a transaction hash from this batch
SELECT event, contract_address, *
FROM ethereum.transaction t, ethereum.transaction_log tl
WHERE t.id = tl.transaction_id
AND transaction_hash = '0x8bc5de545e3bbc091439cfcea6fa536477851c884f4c1b97a1394b66d91639e2'
-- There's an approval, so we want to see which address conducted the approval
SELECT path, encode(bin_val::bytea, 'hex') address, tl.event, contract_address, *
FROM ethereum.transaction t, ethereum.transaction_log tl, ethereum.transaction_log_param tlp
WHERE t.id = tl.transaction_id AND tl.id = tlp.transaction_log_id
AND transaction_hash = '0x8bc5de545e3bbc091439cfcea6fa536477851c884f4c1b97a1394b66d91639e2'
AND tl.event = 'Approval'
AND tlp.path = 'owner'
-- This query then returns the owner as the "address" field that conducted the Approval
-- for the transaction_hash 0x8bc5de545e3bbc091439cfcea6fa536477851c884f4c1b97a1394b66d91639e2
Updated 30 days ago