Skip to main content

Detecting Contract Extensions

In the case where you dont know ahead of time the functionality available in a contract, use the following methods to determine what extension interfaces you can use.

getAllDetectedExtensionNames

Get an array of the names of the extensions a given smart contract supports.

import { getAllDetectedExtensionNames, ThirdwebSDK } from "@thirdweb-dev/sdk";

// ... Logic to initialize the SDK and get your contract
const sdk = new ThirdwebSDK("ethereum");
const contract = await sdk.getContract("0x...");

// Get an array of the extensions the contract supports
const extensions = getAllDetectedExtensionNames(contract.abi);
console.log(extensions);

// output:
//['ERC721','ERC721Mintable','Royalty','Permissions','Gasless',...]
Configuration

abi

The ABI of the smart contract to check.

When using the getContract method, the ABI is available on the abi property of the returned contract object.

Return Value

Returns an array of strings containing the names of the extensions the contract supports.

string[];

isExtensionEnabled

Detect whether or not a given smart contract supports a given extension.

import { isExtensionEnabled, ThirdwebSDK } from "@thirdweb-dev/sdk";

// ... Logic to initialize the SDK and get your contract
const sdk = new ThirdwebSDK("ethereum");
const contract = await sdk.getContract("0x...");

// Detect whether the contract supports e.g. the "ERC721Mintable" extension
const hasFeature = await isExtensionEnabled(contract.abi, "ERC721Mintable");
Configuration

abi

The ABI of the smart contract to check.

When using the getContract method, the ABI is available on the abi property of the returned contract object.

extensionName

The name of the extension to check support for.

View a full list of extension names on the Extensions overview page.

Return Value

Returns a boolean indicating whether or not the contract supports the given extension.

The return value will be true if the contract supports the extension, and false if it does not.

boolean;