Returns the owner for a given ERC721 token

Parameters

  1. chain_id (uint64, default: 1)
  2. token_address (address as hex string, default: 0x45ebb5fe718f40052fb2dc2463c13717b7b72768)
    1. The token address for which we want to check its owner.
  3. token_id (int256 as decimal string, default: 4811)
    1. The token id for which we want to check its owner.
  4. block_number (uint64, default: 0)
    1. Optional. Can be used to view owner at a particular block. If unset, defaults to 0 and returns latest.

Returns

owner (address as hex string)

Query

SELECT b.owner
FROM @sim.erc721_owner_changes_block b
WHERE b.token_address = lower($token_address)
  AND b.chain_id = $chain_id
  AND b.token_id = $token_id
  AND b.block_number IN (
    SELECT MAX(block_number) AS latest_block_number
    FROM @sim.erc721_owner_changes_block
    WHERE token_address = lower($token_address)
      AND chain_id = $chain_id  
      AND token_id = $token_id
      AND (
        block_number <= $block_number
        OR $block_number = 0
      )
  )