Docs

Extensions Framework

In addition to generic read/write contract functions, the SDK by automatically detecting common patterns on your contract, known as Solidity Extensions, and provides a catalog of high level APIs that simplify the interaction with your contract.

A typical Example

Let's say you have a contract that implements a ERC721 standard. The SDK will automatically detect this pattern and provide a set of APIs that will allow you to interact with your contract in a more convenient way.

const contract = await sdk.getContract("0x...");
// read all ERC721 NFTs, along with metadata and owners
const nfts = await contract.erc721.getAll();
// get all the NFTs owned by a specific wallet address
const ownedNFTs = await contract.erc721.getOwned("0x...");
// upload metadata to IPFS and mint a new NFT
await contract.erc721.mint({
  name: "Cool NFT",
  description: "Minted NFT from code!",
  image: fs.readFileSync("path/to/image.png"), // This can be an image url or file
});

Because the contract implements the ERC721 standard, a set of APIs become available under the erc721 namespace.

  • The erc721.getAll() and erc721.getOwned() functions will handle querying the supply, fetching the metadata and owner for each NFT and return a convenient, typed NFT array.
  • The erc721.mint() will handle uploading the metadata to IPFS, and minting a new NFT with the given metadata to the connected wallet address.

This saves a lot of time and effort, as you don't have to manually implement these common functions yourself.

Detecting avilable extensions

You can check which extensions are available on a contract by calling the getAllDetectedExtensionNames() function.

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',...]

// Detect whether the contract supports a given extension
const isERC721 = await isExtensionEnabled(contract.abi, "ERC721");

Preparing transactions

Just like with contract.prepare(), you can prepare a transaction for a specific extension by calling contract.{{extension}}.{{functionName}}.prepare(args). This will return a Transaction object that you can use to encode, estimate, simulate, sign or send the transaction.

// Prepare a transaction, but DON'T send it
const tokenId = 0;
const quantity = 1;
const tx = await contract.erc1155.claim.prepare(tokenId, quantity);

// Some example use cases for the transaction
const encoded = await tx.encode(); // Encode the transaction
const gasCost = await tx.estimateGasCost(); // Estimate the gas cost
const simulatedTx = await tx.simulate(); // Simulate the transaction
const signedTx = await tx.sign(); // Sign the transaction for later use

// Submit the transaction, but don't wait for confirmations
const sentTx = await tx.send();
console.log("Submitted transaction:", sentTx.hash);

One common use case for example is to prepare and encoded 2 different transactions, then execute them atomically using multicall:

// Prepare an ERC721 burn and a ERC721 mint to be executed in one tx
const tx1 = await contract.erc721.burn.prepare(tokenId);
const tx2 = await contract.erc721.mint.prepare(nftMetadata);

// Encode both transactions and execute them via multicall
// this will only prompt the user for 1 transaction to sign instead of 2
await contract.call("multicall", [tx1.encode(), tx2.encode()]);

All Available Extensions

All extensions are available under their own namespace in the SmartContract class, and map to a corresponding Solidity Extension

Solidity ExtensionNamespaceDescription
ERC20contract.erc20Standard ERC20 functions and more
ERC20SignatureMintablecontract.erc20.signatureMint tokens with signature
ERC20ClaimPhasescontract.erc20.claimConditionsConfigure claim conditions for Drop contracts
ERC721contract.erc721Standard ERC721 functions and more
ERC721ClaimPhasescontract.erc721.signatureMint NFTs with signature
ERC721SignatureMintablecontract.erc721.claimConditionsConfigure claim conditions for Drop contracts
ERC721SharedMetadatacontract.erc721.sharedMetadataOpenEditionERC721 shared metadata
ERC721DelayedRevealcontract.erc721.revealerManage delayed reveal NFTs
ERC1155contract.erc1155Stadard ERC1155 functions and more
ERC1155SignatureMintablecontract.erc1155.signatureMint NFTs with signature
ERC1155contract.erc1155.claimConditionsConfigure claim conditions for Drop contracts
ERC4337 Factorycontract.accountFactorySmart Account Factory helpers and state
ERC4337 Accountcontract.accountSmart Account utilities
DirectListingscontract.directListingsMarketplace direct listing functionality
EnglishAuctionscontract.englishAuctionMarketplace english auction functionality
Offerscontract.offersMarketplace offers functionality
AirdropERC20contract.airdrop20Airdrop tokens
AirdropERC721contract.airdrop721Airdrop NFTs
AirdropERC1155contract.airdrop1155Airdrop NFTs
ContractMetadatacontract.metadataContract metadata upload/download
PermissionsEnumerablecontract.rolesContract roles and permissions
PlatformFeecontract.platformFeesManage platform fees
Royaltycontract.royaltiesManage royalties
Ownercontract.ownerManage owners
DynamicContractcontract.extensionsAdd/remove extensions on a dynamic contract