Returns the approvals (standard and operator) for all ERC721 tokens owned by a given address
Parameters
owner
(address as hex string, default: 0x000a22cdb94efbb7260ad038e1b2d377d950ed78)- The owner for which we want to check their portfolio.
chain_id
(uint64, default: 0)- Optional. Can be used to view balances from a certain chain. If unset, defaults to
0
and returns results from all chains.
- Optional. Can be used to view balances from a certain chain. If unset, defaults to
token_address
(address as hex string, default: 0x0000000000000000000000000000000000000000)- Optional. Can be used to filter results to a specific token. If unset, defaults to
address(0)
and all tokens are checked.
- Optional. Can be used to filter results to a specific token. If unset, defaults to
block_number
(uint64, default: 0)- Optional. Can be used to view allowances at a particular block. If unset, defaults to
0
and returns latest.
- Optional. Can be used to view allowances at a particular block. If unset, defaults to
limit
(uint32, default: 100)- Number of records you want returned.
offset
(uint32, default: 0)- For pagination. If you're showing ten records per page, choose offset = 9 for the second page.
Returns
Array with the following fields:
owner
(address as hex string)- The owner for which we checked the portfolio.
chain_id
(int64)- The chain for the token
token_address
(address as hex string)- The token's address.
token_name
(string)- The token's name.
token_symbol
(string)- The token's symbol.
is_for_all
(bool)true
for operator approvals (setApprovalForAll
) andfalse
for token-specific approvals (approve
). See table usage notes.
operator
(address as hex string)- The operator's address for operator approvals, else
address(0)
.
- The operator's address for operator approvals, else
token_id
(int256 as decimal string)- The token's id for token-specific approvals, else
0
.
- The token's id for token-specific approvals, else
approved_address
(address as hex string)- The approved address for token-specific approvals, else
address(0)
.
- The approved address for token-specific approvals, else
txn_last_changed
(address as hex string)- The most recent transaction that impacted the approval. Note that this will include ERC721 transfers, which reset approvals (even if none was set).
block_last_changed
(int64)- The most recent block that impacted the approval.
The array is sorted in descending order of block_last_changed
.
Query
WITH latest_block_number AS (
SELECT token_address,
chain_id,
is_for_all,
token_id,
MAX(block_number) AS latest_block_number
FROM @sim.erc721_approval_changes_block
WHERE owner = lower($owner)
AND (
chain_id = $chain_id
OR $chain_id = 0
)
AND (
token_address = lower($token_address)
OR $token_address = '0x0000000000000000000000000000000000000000'
)
AND (
block_number <= $block_number
OR $block_number = 0
)
GROUP BY token_address,
is_for_all,
token_id,
chain_id
)
SELECT a.owner,
a.chain_id,
a.token_address,
a.token_name,
a.token_symbol,
a.is_for_all,
a.operator,
a.token_id,
a.approved_address,
a.approved,
a.txn_hash as txn_last_changed,
a.block_number as block_last_changed
FROM @sim.erc721_approval_changes_block a
INNER JOIN latest_block_number lbn ON a.block_number = lbn.latest_block_number
AND a.token_address = lbn.token_address
AND a.is_for_all = lbn.is_for_all
AND a.token_id = lbn.token_id
AND a.chain_id = lbn.chain_id
WHERE a.owner = lower($owner)
ORDER BY block_last_changed desc
LIMIT $limit OFFSET $offset