ERC721
Functionality available for contracts that implement the IERC721
interface.
balance
Get the NFT balance of the connected wallet (number of NFTs in this contract owned by the connected wallet).
const balance = await contract.erc721.balance();
Configuration
Return Value
Returns a BigNumber
representing the number of NFTs owned by the connected wallet.
BigNumber;
balanceOf
Get a wallet’s NFT balance (number of NFTs in this contract owned by the wallet).
const walletAddress = "{{wallet_address}}";
const balance = await contract.erc721.balanceOf(walletAddress);
Configuration
get
Get the metadata for an NFT in this contract using it’s token ID.
Metadata is fetched from the uri
property of the NFT.
If the metadata is hosted on IPFS, the metadata is fetched and made available as an object.
The object’s image
property will be a URL that is available through the thirdweb IPFS gateway.
const tokenId = 0;
const nft = await contract.erc721.get(tokenId);
Configuration
tokenId
The token ID of the NFT to get the metadata for.
Must be a BigNumber
, number
, or string
.
const nft = await contract.erc721.get(
"{{token_id}}",
);
Return Value
Returns an NFT
object containing the NFT metadata.
{
metadata: {
id: string;
uri: string; // The raw URI of the metadata
owner: string;
name?: string | number | undefined;
description?: string | null | undefined;
image?: string | null | undefined; // If the image is hosted on IPFS, the URL is https://gateway.ipfscdn.io/ipfs/<hash>
external_url?: string | null | undefined;
animation_url?: string | null | undefined;
background_color?: string | undefined;
properties?: {
[x: string]: unknown;
} | {
[x: string]: unknown;
}[] | undefined;
};
type: "ERC721";
}
isApproved
Get whether this wallet has approved transfers from the given operator.
This means that the operator can transfer NFTs on behalf of this wallet.
const isApproved = await contract.erc721.isApproved(
// Address of the wallet to check
"{{wallet_address}}",
// Address of the operator to check
"{{wallet_address}}",
);
Configuration
owner
The wallet address that owns the NFT.
Must be a string
.
const isApproved = await contract.erc721.isApproved(
"{{wallet_address}}",
"{{wallet_address}}",
);
operator
The wallet address of the operator to check (i.e. the wallet that does/does not have approval).
Must be a string
.
const isApproved = await contract.erc721.isApproved(
"{{wallet_address}}",
"{{wallet_address}}",
);
ownerOf
Get the wallet address of the owner of an NFT.
const owner = await contract.erc721.ownerOf("{{token_id}}");
Configuration
setApprovalForToken
Give another address approval (or remove approval) to transfer a specific one of your NFTs from this collection.
Proceed with caution. Only approve addresses you trust.
// Approve the wallet address
await contract.erc721.setApprovalForToken(
"{{wallet_address}}", // The wallet address to approve
"{{token_id}}", // The token ID of the NFT to allow them to transfer
);
Configuration
setApprovalForAll
Give another address approval (or remove approval) to transfer any of your NFTs from this collection.
Proceed with caution. Only approve addresses you trust.
await contract.erc721.setApprovalForAll(
"{{wallet_address}}", // The wallet address to approve
true, // Whether to approve (true) or remove approval (false)
);
Configuration
transfer
Transfer an NFT from the connected wallet to another wallet.
const walletAddress = "{{wallet_address}}";
const tokenId = 0;
await contract.erc721.transfer(walletAddress, tokenId);