Docs

Extensions

Extensions let interact with common standards (such as ERC20, ERC721, ERC1155, etc.) in a more convenient way. You can use the built-in extensions or create your own.

Built-in extensions

StandardImport PathDescription
ERC20thirdweb/extensions/erc20ERC20 token standard extensions
ERC721thirdweb/extensions/erc721ERC721 token standard extensions
ERC1155thirdweb/extensions/erc1155ERC1155 token standard extensions

Using extensions

To use an extension, you just need to import it and call it with the necessary parameters.

Example: balanceOf() extension for ERC20 tokens

import { getContract } from "thirdweb";
import { balanceOf } from "thirdweb/extensions/erc20";
// get the contract
const contract = getContract({...});
// call the extension function
const balance = await balanceOf({
contract,
address: "0x5678...",
});

Example: transfer() extension for ERC20 tokens

import { getContract, sendTransaction } from "thirdweb";
import { transfer } from "thirdweb/extensions/erc20";
// get the contract
const contract = getContract({...});
// call the extension function to prepare the transaction
const transaction = transfer({
contract,
to: "0x1234...",
amount: "1",
});
// send the transaction
const transactionResult = await sendTransaction({
transaction,
wallet,
});

Creating your own extensions

You can create your own extensions. They are just regular functions that pre-define the behavior of a prepareContractCall() or readContract() function.