Returns the addresses that hold any token within a given ERC1155 contract
Parameters
chain_id
(uint64, default: 1)token_address
(address as hex string, default: 0x80b6fd8273d89293a097bca2abd01206c89eccb5)- The contract for which we want to check its owners.
block_number
(uint64, default: 0)- Optional. Can be used to view owner at a particular block. If unset, defaults to
0
and returns latest.
- Optional. Can be used to view owner 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:
address
(address as hex string)- The address that owns at least one token in the contract.
token_id
(int256 as decimal string)- The token's id.
balance
(int256 as decimal string)- The quantity of the specific token id owned by the address.
txn_last_changed
(address as hex string)- The most recent transaction that impacted the token_id.
block_last_changed
(int64)- The most recent block that impacted the token_id.
Query
WITH latest_block_number AS (
SELECT chain_id,
token_address,
token_id,
account_address,
MAX(block_number) AS latest_block_number
FROM @sim.erc1155_balance_changes_block
WHERE (
chain_id = $chain_id
OR $chain_id = 0
)
AND token_address = lower($token_address)
AND (
block_number <= $block_number
OR $block_number = 0
)
GROUP BY chain_id,
token_address,
token_id,
account_address
)
SELECT DISTINCT b.account_address as address,
b.token_id,
b.balance,
b.txn_hash AS txn_last_changed,
b.block_number AS block_last_changed
FROM @sim.erc1155_balance_changes_block b
INNER JOIN latest_block_number lbn ON b.token_address = lbn.token_address
AND b.token_id = lbn.token_id
AND b.account_address = lbn.account_address
AND b.block_number = lbn.latest_block_number
AND b.chain_id = lbn.chain_id
WHERE b.token_address = lower($token_address)
AND b.balance > 0
ORDER BY b.account_address,
b.token_id
LIMIT $limit OFFSET $offset