Get NFT information
info
This document assumes you have followed the deploy a contract and the mint an NFT instructions.
Repeat the mint NFT instructions again to have a collection of NFTs for testing the following SDK methods.
Get NFTs
Call the getNFTs
method to list the NFTs per user address.
const myNFTs = await sdk.api.getNFTs({
publicAddress: process.env.WALLET_PUBLIC_ADDRESS,
includeMetadata: true,
});
console.log("My NFTs: \n", myNFTs);
Example output:
My NFTs:
{
pageNumber: 1,
network: 'GOERLI',
total: 2,
account: '0xeF8692168D0C165488ae3F0105Fe096f5E81820b',
type: 'NFT',
assets: [
{
contract: '0x675e75a15940247220a980de81a4b7de7feb9f76',
tokenId: '0',
supply: '1',
type: 'ERC721',
metadata: [Object]
},
{
contract: '0x0300f3f929b558e84107b67e3fbbe9e897dadb5a',
tokenId: '0',
supply: '1',
type: 'ERC721',
metadata: [Object]
}
]
}
Get NFTs per contract address
Call the getNFTsForCollection
method to list the NFT collections and metadata per contract address.
const collectionNFT = await sdk.api.getNFTsForCollection({
contractAddress: "<CONTRACT_ADDRESS>",
});
console.log("NFT Collection: \n", collectionNFT);
console.log("NFT Metadata: \n", collectionNFT.assets[0].metadata);
Example output:
NFT Collection:
{
pageNumber: 1,
network: 'GOERLI',
total: 1,
account: '0x0300F3F929B558e84107B67e3FbBe9e897daDB5a',
type: 'NFT',
assets: [
{
contract: '0x0300f3f929b558e84107b67e3fbbe9e897dadb5a',
tokenId: '0',
supply: '1',
type: 'ERC721',
metadata: [Object]
}
]
}
NFT Metadata:
{
attributes: [ { traitType: 'Background', value: 'White' } ],
description: 'Hello world.',
image: 'https://ipfs.io/ipfs/QmbxwZsUSBT3sGUuWCMLeuMzHcgq5eK2zjxFrYnUcoV1Du',
name: 'Hello world.'
}
Get token metadata
Call the getTokenMetaData
method in the same way for more information about the contract.
const tokenMetadata = await sdk.api.getTokenMetadata({
contractAddress: "<CONTRACT_ADDRESS>",
tokenId: 0,
});
console.log("Token Metadata: \n", tokenMetadata);
Example output:
Token Metadata:
{
contract: '0x675e75a15940247220a980de81a4b7de7feb9f76',
tokenId: '0',
name: "ConsenSys NFT SDK contract demo",
description: "This is part of the ConsenSys NFT SDK demo.",
image: "https://cdn.consensys.net/uploads/consensys-2020-featured-image.jpg",
external_link: "https://consensys.net/"
}