I’m building my own NFT smart contract using AssemblyScript and following the NEP-171 standard. I created an NFT using my custom mint function, but it doesn’t appear in the collectibles section of my NEAR testnet wallet.
My implementation:
import { PersistentMap, context } from 'near-sdk-as';
@nearBindgen
class ContractMetadata {
version: string;
title: string;
symbol: string;
icon: string | null;
base_url: string | null;
ref: string | null;
ref_hash: string | null;
}
@nearBindgen
export class AssetMetadata {
name: string;
desc: string;
image: string;
image_hash: string;
quantity: number;
created_at: number;
expires_at: number;
valid_from: number;
modified_at: number;
additional: string;
external_ref: string;
external_hash: string;
}
@nearBindgen
export class Asset {
token_id: string;
holder_id: string;
meta: AssetMetadata;
constructor(id: string, metadata: AssetMetadata, holder: string) {
this.token_id = id;
this.meta = metadata;
this.holder_id = holder;
}
}
@nearBindgen
export class NFTContract {
contract_meta: ContractMetadata = {
version: 'asset-v1.0.0',
title: 'Digital Assets',
symbol: 'DIGI',
icon: null,
base_url: null,
ref: null,
ref_hash: null,
};
owner: string;
user_assets: PersistentMap<string, Array<string>> = new PersistentMap<string, Array<string>>('user_tokens');
asset_registry: PersistentMap<string, Asset> = new PersistentMap<string, Asset>('asset_data');
metadata_registry: PersistentMap<string, AssetMetadata> = new PersistentMap<string, AssetMetadata>('meta_data');
nft_tokens_for_owner(user_id: string): Array<Asset> {
const assetIds: string[] = this.user_assets.getSome(user_id);
const userAssets: Array<Asset> = new Array<Asset>();
for (let j = 0; j < assetIds.length; ++j) {
const asset: Asset = this.asset_registry.getSome(assetIds[j]);
userAssets.push(asset);
}
return userAssets;
}
create_nft(asset_id: string, meta: AssetMetadata, recipient: string): void {
const newAsset = new Asset(asset_id, meta, recipient);
const userTokens: Array<string> = new Array<string>();
userTokens.push(asset_id);
this.user_assets.set(recipient, userTokens);
this.asset_registry.set(asset_id, newAsset);
this.metadata_registry.set(asset_id, newAsset.meta);
}
}
I successfully minted a token and the transaction went through, but the NFT doesn’t show up in my wallet’s collectibles tab. Am I missing some required methods or is there something wrong with my contract structure? Do I need to implement additional NEP-171 functions for wallet visibility?