Search code examples
nearprotocol

How can I fetch all NFTs within a NEAR account?


Assuming all NFTs adhered to the NEP-171 specification, how can I list all NFTs within an account such as example.near?

I see at https://docs.rs/near-contract-standards/latest/near_contract_standards/macro.impl_non_fungible_token_enumeration.html that it ought to be possible.


Solution

  • Using the NEAR CLI, run something like NEAR_ENV=testnet near view <the contract ID> nft_tokens_for_owner '{"account_id": "<the account ID>"}'.

    See https://nomicon.io/Standards/NonFungibleToken/Enumeration.html#interface.

    from_index defaults to 0 and limit defaults to unlimited.

    Example:

    NEAR_ENV=testnet near view dev-1643292007908-55838431863482 nft_tokens_for_owner '{"account_id": "example.testnet"}'