Detecting Contract Extensions
In the case where you don’t 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
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");