'How to allow NFTs to show up in the NEAR Wallet
I've created an NFT contract and it seems as though none of the NFTs that I've minted show up in the collectibles tab. I was wondering what the criteria were for having NFTs in the wallet and how an arbitrary NFT contract could achieve this?
Solution 1:[1]
The way NFTs are displayed is that the wallet keeps track of a list of "likely" NFT contracts that you might own NFTs on. When you navigate to the collectibles tab, the wallet will then call the nft_tokens_for_owner enumeration method to display your NFTs. This means that in order to have your NFTs show up, you need two things:
- Your contract should implement the nft_tokens_for_owner function as per the enumeration standard.
- Your contract should be able to be flagged as a "likely" NFT contract.
Let's go through the first requirement. Your NFT contract should implement the nft_tokens_for_owner function and when called, it should return an object that contains a metadata field as per the metadata standard. An example response of the Token object that should be returned is shown below: { token_id: 'token-1', owner_id: 'eth-denver-testing2.testnet', metadata: { title: 'My Non Fungible Team Token', description: 'The Team Most Certainly Goes :)', media: 'https://bafybeiftczwrtyr3k7a2k4vutd3amkwsmaqyhrdzlhvpt33dyjivufqusq.ipfs.dweb.link/goteam-gif.gif', media_hash: null, copies: null, issued_at: null, expires_at: null, starts_at: null, updated_at: null, extra: null, reference: null, reference_hash: null }, approved_account_ids: {}, royalty: {} }
Your token object should contain some metadata which includes the media field. If your contract doesn't implement the nft_tokens_for_owner function properly, it will result in something that looks like the following, where the NEAR wallet has correctly flagged your contract but it doesn't know how to display your NFT. This is explained in the NFT zero to hero tutorial's minting section.
Let's now go through the second requirement. Up until late 2021, the NEAR wallet used a hacky solution to flag NFT contracts. Basically, it looked for any method starting with nft_ where the receiver_id parameter was your account. This code can be found here (please ping me if this code changes places). This was a hacky solution since there isn't any standard for minting NFTs and so people could mint NFTs by calling a function that didn't start with nft_ or where the receiver ID wasn't in the parameter and the NFT was simply minted to the predecessor.
After late 2021, we introduced a new standard for NEP-171 tokens known as the events standard. This dictated that your smart contract should emit an event whenever an NFT is minted, burnt, or transferred. This allowed NFT contracts to have one source of truth as to when things happened and the wallet didn't need to rely on hacky "guesses" as to what contracts were considered likely NFT contracts.
TLDR:
With this in mind, your contract should either implement the events standard (recommended) or your mint function should start with nft_ and have the receiver_id parameter set to your account in order for your contract to be flagged as likely (or both).
Secondly, your contract should correctly implement the nft_tokens_for_owner function which returns a token object containing metadata that has a valid media field.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Benjamin Kurrek |