Skip to content

NFT: get_approved returns None instead of NonExistentToken for nonexistent tokens #934

Closed

Description

@ozgunozerk

What happened?

NonFungibleToken::get_approved returns None for token IDs that don't exist, both never-minted IDs and burned ones. Its docs list NonFungibleTokenError::NonExistentToken for that case, but the error is never raised.

The default ContractOverrides::get_approved calls Base::get_approved, which only reads the temporary Approval(token_id) entry and never checks that the token exists. No NFT contract type overrides get_approved, so this affects Base, Enumerable, Consecutive, NonFungibleVotes and the combined types.

As a result, a caller can't tell a live token with no approval apart from a token that doesn't exist. Ownership, balances, transfers and approvals on live tokens are not affected.

Example (Consecutive):

Consecutive::mint_range(&e, &owner, 2);
Consecutive::burn(&e, &owner, 0);
Consecutive::owner_of(&e, 0);                              // panics: Error(Contract, #200)
<Consecutive as ContractOverrides>::get_approved(&e, 0);   // returns None
<Base as ContractOverrides>::get_approved(&e, 999);        // returns None, never minted

Expected behavior

get_approved panics with NonExistentToken (#200) for a token that doesn't exist, as documented on the trait. This matches owner_of and token_uri, SEP-50, and Solidity's ERC721.getApproved.

The existence check has to go through Self::owner_of (the contract type's own ownership model), not Base::owner_of. Consecutive doesn't store a per-token owner entry for batch-minted tokens, so Base::owner_of would wrongly reject them. This is the same approach RoyaltySupport::royalty_info uses (#846).

Activity

  1. ozgunozerk commented on Oct 13, 2026

    @ozgunozerk
    CollaboratorAuthor

    We will have a better solution for this for accurate errors for consecutive

  2. added this to the Release v0.8.0 milestone on Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions