Skip to main content

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 wallets NFT balance (number of NFTs in this contract owned by the wallet).

const walletAddress = "{{wallet_address}}";
const balance = await contract.erc721.balanceOf(walletAddress);
Configuration

walletAddress

The wallet address to check the balance for.

Must be a string.

const balance = await contract.erc721.balanceOf(
"{{wallet_address}}",
);

Return Value

Returns a BigNumber representing the number of NFTs owned by the wallet.

BigNumber;

get

Get the metadata for an NFT in this contract using its 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 objects 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

tokenId

The token ID of the NFT to get the owner of.

Must be a BigNumber, number, or string.

Return Value

Returns a string representing the wallet address of the owner of the NFT.

string;

setApprovalForToken

Give another address approval (or remove approval) to transfer a specific one of your NFTs from this collection.

Warning

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

operator

The wallet address to approve.

Must be a string.

tokenId

The token ID of the NFT to allow the operator to transfer.

Must be a BigNumber, number, or string.

setApprovalForAll

Give another address approval (or remove approval) to transfer any of your NFTs from this collection.

Warning

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

operator

The wallet address to approve.

Must be a string.

approved

Whether to approve (true) or remove approval (false).

Must be a boolean.

transfer

Transfer an NFT from the connected wallet to another wallet.

const walletAddress = "{{wallet_address}}";
const tokenId = 0;
await contract.erc721.transfer(walletAddress, tokenId);
Configuration

walletAddress

The wallet address to transfer the NFT to.

Must be a string.

await contract.erc721.transfer(
"{{wallet_address}}",
"{{token_id}}",
);

tokenId

The token ID of the NFT to transfer.

Must be a BigNumber, number, or string.

await contract.erc721.transfer(
"{{wallet_address}}",
"{{token_id}}",
);