Skip to main content

NftController Actions

8 actions registered.

NameDeprecated
addNft
addNftVerifyOwnership
checkAndUpdateAllNftsOwnershipStatus
checkAndUpdateSingleNftOwnershipStatus
getState
isNftOwner
removeAndIgnoreNft
removeNft

NftController:addNft​

Package: @metamask/assets-controllers

Adds an NFT and respective NFT contract to the stored NFT and NFT contracts lists.

Parameters:

NameDescription
tokenAddressHex address of the NFT contract.
tokenIdThe NFT identifier.
networkClientIdThe networkClientId that can be used to identify the network client to use for this request.
optionsan object of arguments
options.nftMetadataNFT optional metadata.
options.userAddressThe address of the current user.
options.sourceWhether the NFT was detected, added manually or suggested by a dapp. Defaults to Source.Custom; pass Source.Detected when refreshing existing NFTs.

Returns: Promise resolving to the current NFT list.

Handler signature:

(tokenAddress: string, tokenId: string, networkClientId: NetworkClientId, { nftMetadata, userAddress, source, }?: {
nftMetadata?: NftMetadata;
userAddress?: string;
source?: Source;
}) => Promise<void>

NftController:addNftVerifyOwnership​

Package: @metamask/assets-controllers

Verifies currently selected address owns entered NFT address/tokenId combo and adds the NFT and respective NFT contract to the stored NFT and NFT contracts lists.

Parameters:

NameDescription
addressHex address of the NFT contract.
tokenIdThe NFT identifier.
networkClientIdThe networkClientId that can be used to identify the network client to use for this request.
optionsan object of arguments
options.userAddressThe address of the current user.
options.sourceWhether the NFT was detected, added manually or suggested by a dapp. Defaults to Source.Custom; pass Source.Detected when refreshing existing NFTs.

Handler signature:

(address: string, tokenId: string, networkClientId: NetworkClientId, { userAddress, source, }?: {
userAddress?: string;
source?: Source;
}) => Promise<void>

NftController:checkAndUpdateAllNftsOwnershipStatus​

Package: @metamask/assets-controllers

Checks whether NFTs associated with current selectedAddress/chainId combination are still owned by the user And updates the isCurrentlyOwned value on each accordingly. Uses Multicall3 to batch all ownership checks into a single RPC request when available.

Parameters:

NameDescription
networkClientIdThe networkClientId that can be used to identify the network client to use for this request.
optionsan object of arguments
options.userAddressThe address of the account where the NFT ownership status is checked/updated.

Handler signature:

(networkClientId: NetworkClientId, { userAddress, }?: {
userAddress?: string;
}) => Promise<void>

NftController:checkAndUpdateSingleNftOwnershipStatus​

Package: @metamask/assets-controllers

Checks whether input NFT is still owned by the user and updates the isCurrentlyOwned value on the NFT object accordingly.

Parameters:

NameDescription
nftThe NFT object to check and update.
networkClientIdThe networkClientId that can be used to identify the network client to use for this request.
accountParamsThe userAddress to check ownership against.
accountParams.userAddressthe address passed through the confirmed transaction flow to ensure assets are stored to the correct account

Returns: the NFT with the updated isCurrentlyOwned value

Handler signature:

(nft: Nft, networkClientId: NetworkClientId, { userAddress }?: {
userAddress?: string;
}) => Promise<Nft>

NftController:getState​

Package: @metamask/assets-controllers

Handler signature:

() => NftControllerState

NftController:isNftOwner​

Package: @metamask/assets-controllers

Checks the ownership of a ERC-721 or ERC-1155 NFT for a given address.

Parameters:

NameDescription
ownerAddressUser public address.
nftAddressNFT contract address.
tokenIdNFT token ID.
networkClientIdThe networkClientId that can be used to identify the network client to use for this request.
optionsOptional parameters.
options.standardThe NFT standard ('ERC721' or 'ERC1155'). When provided, only the relevant ownership check is performed, halving the number of RPC subcalls.

Returns: Promise resolving the NFT ownership.

Handler signature:

(ownerAddress: string, nftAddress: string, tokenId: string, networkClientId: NetworkClientId, { standard }?: {
standard?: string | null;
}) => Promise<boolean>

NftController:removeAndIgnoreNft​

Package: @metamask/assets-controllers

Removes an NFT from the stored token list and saves it in ignored NFTs list.

Parameters:

NameDescription
addressHex address of the NFT contract.
tokenIdToken identifier of the NFT.
networkClientIdThe networkClientId that can be used to identify the network client to use for this request.
optionsan object of arguments
options.userAddressThe address of the account where the NFT is being removed.

Handler signature:

(address: string, tokenId: string, networkClientId: NetworkClientId, { userAddress }?: {
userAddress?: string;
}) => void

NftController:removeNft​

Package: @metamask/assets-controllers

Removes an NFT from the stored token list.

Parameters:

NameDescription
addressHex address of the NFT contract.
tokenIdToken identifier of the NFT.
networkClientIdThe networkClientId that can be used to identify the network client to use for this request.
optionsan object of arguments
options.userAddressThe address of the account where the NFT is being removed.

Handler signature:

(address: string, tokenId: string, networkClientId: NetworkClientId, { userAddress }?: {
userAddress?: string;
}) => void