SmartContract
Custom contract dynamic class with feature detection
import { ThirdwebSDK } from "@thirdweb-dev/sdk"; const sdk = new ThirdwebSDK(provider);const contract = await sdk.getContract("{{contract_address}}"); // call any function in your contractawait contract.call("myCustomFunction", [param1, param2]); // if your contract follows an ERC standard, contract.ercXYZ will be presentconst allNFTs = await contract.erc721.getAll(); // if your contract extends a particular contract extension, the corresponding function will be availableconst tx = await contract.erc721.mint({ name: "Cool NFT", image: readFileSync("some_image.png"),});
class SmartContract<> implements UpdateableNetwork {}
function constructor(network: NetworkInput, address: string, abi: Array<objectInputType<{ inputs: ZodDefault<ZodArray<ZodObject<extendShape<{ name: ZodDefault<ZodString>; type: ZodString }, { components: ZodOptional<ZodArray<ZodObject<..., ..., ..., ..., ...>, "many">>; stateMutability: ZodOptional<ZodString> }>, "strip", ZodAny, objectOutputType<extendShape<{ name: ZodDefault<ZodString>; type: ZodString }, { components: ZodOptional<ZodArray<..., ...>>; stateMutability: ZodOptional<ZodString> }>, ZodAny, "strip">, objectInputType<extendShape<{ name: ZodDefault<ZodString>; type: ZodString }, { components: ZodOptional<ZodArray<..., ...>>; stateMutability: ZodOptional<ZodString> }>, ZodAny, "strip">>, "many">>; name: ZodDefault<ZodString>; outputs: ZodDefault<ZodArray<ZodObject<extendShape<{ name: ZodDefault<ZodString>; type: ZodString }, { components: ZodOptional<ZodArray<ZodObject<..., ..., ..., ..., ...>, "many">>; stateMutability: ZodOptional<ZodString> }>, "strip", ZodAny, objectOutputType<extendShape<{ name: ZodDefault<ZodString>; type: ZodString }, { components: ZodOptional<ZodArray<..., ...>>; stateMutability: ZodOptional<ZodString> }>, ZodAny, "strip">, objectInputType<extendShape<{ name: ZodDefault<ZodString>; type: ZodString }, { components: ZodOptional<ZodArray<..., ...>>; stateMutability: ZodOptional<ZodString> }>, ZodAny, "strip">>, "many">>; type: ZodString }, ZodAny, "strip">>, storage: ThirdwebStorage<IpfsUploadBatchOptions>, options: undefined | ({ clientId?: string; gasless?: ({ experimentalChainlessSupport?: boolean; openzeppelin: { domainName?: string; domainSeparatorVersion?: string; domainVersion?: string; relayerForwarderAddress?: string; relayerUrl: string; useEOAForwarder?: boolean } }) | ({ biconomy: { apiId: string; apiKey: string; deadlineSeconds?: number } }) | ({ engine: { domainName?: string; domainSeparatorVersion?: string; domainVersion?: string; relayerForwarderAddress?: string; relayerUrl: string }; experimentalChainlessSupport?: boolean }); gasSettings?: { maxPriceInGwei?: number; speed?: "standard" | "fast" | "fastest" }; gatewayUrls?: Array<string>; readonlySettings?: { chainId?: number; rpcUrl: string }; rpcBatchSettings?: { sizeLimit?: number; timeLimit?: number }; secretKey?: string; supportedChains?: Array<{ chainId: number; nativeCurrency: { decimals: number; name: string; symbol: string }; rpc: Array<string>; slug: string }> }), chainId: number, contractWrapper: ContractWrapper<TContract>) : SmartContract<TContract>
let abi: Array<objectInputType<{ inputs: ZodDefault<ZodArray<ZodObject<extendShape<{ name: ZodDefault<ZodString>; type: ZodString }, { components: ZodOptional<ZodArray<ZodObject<..., ..., ..., ..., ...>, "many">>; stateMutability: ZodOptional<ZodString> }>, "strip", ZodAny, objectOutputType<extendShape<{ name: ZodDefault<ZodString>; type: ZodString }, { components: ZodOptional<ZodArray<..., ...>>; stateMutability: ZodOptional<ZodString> }>, ZodAny, "strip">, objectInputType<extendShape<{ name: ZodDefault<ZodString>; type: ZodString }, { components: ZodOptional<ZodArray<..., ...>>; stateMutability: ZodOptional<ZodString> }>, ZodAny, "strip">>, "many">>; name: ZodDefault<ZodString>; outputs: ZodDefault<ZodArray<ZodObject<extendShape<{ name: ZodDefault<ZodString>; type: ZodString }, { components: ZodOptional<ZodArray<ZodObject<..., ..., ..., ..., ...>, "many">>; stateMutability: ZodOptional<ZodString> }>, "strip", ZodAny, objectOutputType<extendShape<{ name: ZodDefault<ZodString>; type: ZodString }, { components: ZodOptional<ZodArray<..., ...>>; stateMutability: ZodOptional<ZodString> }>, ZodAny, "strip">, objectInputType<extendShape<{ name: ZodDefault<ZodString>; type: ZodString }, { components: ZodOptional<ZodArray<..., ...>>; stateMutability: ZodOptional<ZodString> }>, ZodAny, "strip">>, "many">>; type: ZodString }, ZodAny, "strip">>
let options: | undefined | { clientId?: string; gasless?: | { experimentalChainlessSupport?: boolean; openzeppelin: { domainName?: string; domainSeparatorVersion?: string; domainVersion?: string; relayerForwarderAddress?: string; relayerUrl: string; useEOAForwarder?: boolean; }; } | { biconomy: { apiId: string; apiKey: string; deadlineSeconds?: number; }; } | { engine: { domainName?: string; domainSeparatorVersion?: string; domainVersion?: string; relayerForwarderAddress?: string; relayerUrl: string; }; experimentalChainlessSupport?: boolean; }; gasSettings?: { maxPriceInGwei?: number; speed?: "standard" | "fast" | "fastest"; }; gatewayUrls?: Array<string>; readonlySettings?: { chainId?: number; rpcUrl: string }; rpcBatchSettings?: { sizeLimit?: number; timeLimit?: number }; secretKey?: string; supportedChains?: Array<{ chainId: number; nativeCurrency: { decimals: number; name: string; symbol: string; }; rpc: Array<string>; slug: string; }>; };
Call any function on this contract
// read functions will return the data from the contractconst myValue = await contract.call("myReadFunction");console.log(myValue); // write functions will return the transaction receiptconst tx = await contract.call("myWriteFunction", [arg1, arg2]);const receipt = tx.receipt; // Optionally override transaction optionsawait contract.call("myWriteFunction", [arg1, arg2], { gasLimit: 1000000, // override default gas limit value: ethers.utils.parseEther("0.1"), // send 0.1 ether with the contract call};
function call( functionName: string & TMethod, args?: Parameters<TContract["functions"][TMethod]>, overrides?: CallOverrides,): Promise<ReturnType<TContract["functions"][TMethod]>>;
Prepare a transaction for sending
function prepare( method: string & TMethod, args: Array<any> & Parameters<TContract["functions"][TMethod]>, overrides?: CallOverrides,
Omit<TransactionResultWithMetadata<unknown>, "data">>;
let interceptor: ContractInterceptor<TContract>;
let metadata: ContractMetadata<BaseContract, { deploy: ZodObject<extendShape<extendShape<{ app_uri: ZodOptional<ZodString>; defaultAdmin: ZodOptional<ZodUnion<[ZodType<string, ZodTypeDef, string>, ZodType<`0x${...}`, ZodTypeDef, (...) | (...)>]>>; description: ZodOptional<ZodString>; external_link: ZodOptional<ZodString>; image: ZodOptional<ZodUnion<[ZodUnion<[..., ...]>, ZodString]>>; name: ZodString; social_urls: ZodOptional<ZodRecord<ZodString, ZodString>> }, { merkle: ZodOptional<ZodDefault<ZodRecord<ZodString, ZodString>>>; symbol: ZodOptional<ZodDefault<ZodString>> }>, { platform_fee_basis_points: ZodOptional<ZodDefault<ZodNumber>>; platform_fee_recipient: ZodOptional<ZodDefault<ZodUnion<[ZodType<string, ZodTypeDef, string>, ZodType<`0x${...}`, ZodTypeDef, (...) | (...)>]>>>; primary_sale_recipient: ZodOptional<ZodDefault<ZodUnion<[ZodType<string, ZodTypeDef, string>, ZodType<`0x${...}`, ZodTypeDef, (...) | (...)>]>>>; trusted_forwarders: ZodOptional<ZodDefault<ZodArray<ZodUnion<[ZodType<..., ..., ...>, ZodType<..., ..., ...>]>, "many">>> }>, "strip", ZodTypeAny, { app_uri?: string; defaultAdmin?: string; description?: string; external_link?: string; image?: any; merkle?: Record<string, string>; name: string; platform_fee_basis_points?: number; platform_fee_recipient?: string; primary_sale_recipient?: string; social_urls?: Record<string, string>; symbol?: string; trusted_forwarders?: Array<string> }, { app_uri?: string; defaultAdmin?: string; description?: string; external_link?: string; image?: any; merkle?: Record<string, string>; name: string; platform_fee_basis_points?: number; platform_fee_recipient?: string; primary_sale_recipient?: string; social_urls?: Record<string, string>; symbol?: string; trusted_forwarders?: Array<string> }>; input: ZodObject<extendShape<{ app_uri: ZodOptional<ZodString>; defaultAdmin: ZodOptional<ZodUnion<[ZodType<string, ZodTypeDef, string>, ZodType<`0x${string}`, ZodTypeDef, (`${...}.eth`) | (`${...}.cb.id`)>]>>; description: ZodOptional<ZodString>; external_link: ZodOptional<ZodString>; image: ZodOptional<ZodUnion<[ZodUnion<[ZodTypeAny, ZodObject<..., ..., ..., ..., ...>]>, ZodString]>>; name: ZodString; social_urls: ZodOptional<ZodRecord<ZodString, ZodString>> }, { merkle: ZodOptional<ZodDefault<ZodRecord<ZodString, ZodString>>>; symbol: ZodOptional<ZodDefault<ZodString>> }>, "strip", ZodAny, objectOutputType<extendShape<{ app_uri: ZodOptional<ZodString>; defaultAdmin: ZodOptional<ZodUnion<[ZodType<string, ZodTypeDef, string>, ZodType<`0x${...}`, ZodTypeDef, (...) | (...)>]>>; description: ZodOptional<ZodString>; external_link: ZodOptional<ZodString>; image: ZodOptional<ZodUnion<[ZodUnion<[..., ...]>, ZodString]>>; name: ZodString; social_urls: ZodOptional<ZodRecord<ZodString, ZodString>> }, { merkle: ZodOptional<ZodDefault<ZodRecord<ZodString, ZodString>>>; symbol: ZodOptional<ZodDefault<ZodString>> }>, ZodAny, "strip">, objectInputType<extendShape<{ app_uri: ZodOptional<ZodString>; defaultAdmin: ZodOptional<ZodUnion<[ZodType<string, ZodTypeDef, string>, ZodType<`0x${...}`, ZodTypeDef, (...) | (...)>]>>; description: ZodOptional<ZodString>; external_link: ZodOptional<ZodString>; image: ZodOptional<ZodUnion<[ZodUnion<[..., ...]>, ZodString]>>; name: ZodString; social_urls: ZodOptional<ZodRecord<ZodString, ZodString>> }, { merkle: ZodOptional<ZodDefault<ZodRecord<ZodString, ZodString>>>; symbol: ZodOptional<ZodDefault<ZodString>> }>, ZodAny, "strip">>; output: ZodObject<extendShape<extendShape<{ app_uri: ZodOptional<ZodString>; defaultAdmin: ZodOptional<ZodUnion<[ZodType<string, ZodTypeDef, string>, ZodType<`0x${...}`, ZodTypeDef, (...) | (...)>]>>; description: ZodOptional<ZodString>; external_link: ZodOptional<ZodString>; image: ZodOptional<ZodUnion<[ZodUnion<[..., ...]>, ZodString]>>; name: ZodString; social_urls: ZodOptional<ZodRecord<ZodString, ZodString>> }, { image: ZodOptional<ZodString> }>, { merkle: ZodOptional<ZodDefault<ZodRecord<ZodString, ZodString>>>; symbol: ZodOptional<ZodDefault<ZodString>> }>, "strip", ZodAny, objectOutputType<extendShape<extendShape<{ app_uri: ZodOptional<ZodString>; defaultAdmin: ZodOptional<ZodUnion<[ZodType<..., ..., ...>, ZodType<..., ..., ...>]>>; description: ZodOptional<ZodString>; external_link: ZodOptional<ZodString>; image: ZodOptional<ZodUnion<[ZodUnion<...>, ZodString]>>; name: ZodString; social_urls: ZodOptional<ZodRecord<ZodString, ZodString>> }, { image: ZodOptional<ZodString> }>, { merkle: ZodOptional<ZodDefault<ZodRecord<ZodString, ZodString>>>; symbol: ZodOptional<ZodDefault<ZodString>> }>, ZodAny, "strip">, objectInputType<extendShape<extendShape<{ app_uri: ZodOptional<ZodString>; defaultAdmin: ZodOptional<ZodUnion<[ZodType<..., ..., ...>, ZodType<..., ..., ...>]>>; description: ZodOptional<ZodString>; external_link: ZodOptional<ZodString>; image: ZodOptional<ZodUnion<[ZodUnion<...>, ZodString]>>; name: ZodString; social_urls: ZodOptional<ZodRecord<ZodString, ZodString>> }, { image: ZodOptional<ZodString> }>, { merkle: ZodOptional<ZodDefault<ZodRecord<ZodString, ZodString>>>; symbol: ZodOptional<ZodDefault<ZodString>> }>, ZodAny, "strip">> }>
let publishedMetadata: ContractPublishedMetadata;
let abi: Array<objectOutputType<{ inputs: ZodDefault<ZodArray<ZodObject<extendShape<{ name: ZodDefault<ZodString>; type: ZodString }, { components: ZodOptional<ZodArray<ZodObject<..., ..., ..., ..., ...>, "many">>; stateMutability: ZodOptional<ZodString> }>, "strip", ZodAny, objectOutputType<extendShape<{ name: ZodDefault<ZodString>; type: ZodString }, { components: ZodOptional<ZodArray<..., ...>>; stateMutability: ZodOptional<ZodString> }>, ZodAny, "strip">, objectInputType<extendShape<{ name: ZodDefault<ZodString>; type: ZodString }, { components: ZodOptional<ZodArray<..., ...>>; stateMutability: ZodOptional<ZodString> }>, ZodAny, "strip">>, "many">>; name: ZodDefault<ZodString>; outputs: ZodDefault<ZodArray<ZodObject<extendShape<{ name: ZodDefault<ZodString>; type: ZodString }, { components: ZodOptional<ZodArray<ZodObject<..., ..., ..., ..., ...>, "many">>; stateMutability: ZodOptional<ZodString> }>, "strip", ZodAny, objectOutputType<extendShape<{ name: ZodDefault<ZodString>; type: ZodString }, { components: ZodOptional<ZodArray<..., ...>>; stateMutability: ZodOptional<ZodString> }>, ZodAny, "strip">, objectInputType<extendShape<{ name: ZodDefault<ZodString>; type: ZodString }, { components: ZodOptional<ZodArray<..., ...>>; stateMutability: ZodOptional<ZodString> }>, ZodAny, "strip">>, "many">>; type: ZodString }, ZodAny, "strip">>
Account Factory
Create accounts and fetch data about them.
// Predict the address of the account that will be created for an admin.const deterministicAddress = await contract.accountFactory.predictAccountAddress( admin, extraData, ); // Create accountsconst tx = await contract.accountFactory.createAccount( admin, extraData,);// the same as `deterministicAddress`const accountAddress = tx.address; // Get all accounts created by the factoryconst allAccounts = await contract.accountFactory.getAllAccounts(); // Get all accounts on which a signer has been given authority.const associatedAccounts = await contract.accountFactory.getAssociatedAccounts(signer); // Get all signers who have been given authority on a account.const associatedSigners = await contract.accountFactory.getAssociatedSigners(accountAddress); // Check whether a account has already been created for a given admin.const isAccountDeployed = await contract.accountFactory.isAccountDeployed(admin, extraData);
Auto-detects AppURI standard functions.
let chainId: number;
Direct listings
Create and manage direct listings in your marketplace.
// Data of the listing you want to createconst listing = { // address of the contract the asset you want to list is on assetContractAddress: "0x...", // token ID of the asset you want to list tokenId: "0", // how many of the asset you want to list quantity: 1, // address of the currency contract that will be used to pay for the listing currencyContractAddress: NATIVE_TOKEN_ADDRESS, // The price to pay per unit of NFTs listed. pricePerToken: 1.5, // when should the listing open up for offers startTimestamp: new Date(Date.now()), // how long the listing will be open for endTimestamp: new Date(Date.now() + 5 * 24 * 60 * 60 * 1000), // Whether the listing is reserved for a specific set of buyers. isReservedListing: false,}; const tx = await contract.directListings.createListing(listing);const receipt = tx.receipt; // the transaction receiptconst id = tx.id; // the id of the newly created listing // And on the buyers side:// The ID of the listing you want to buy fromconst listingId = 0;// Quantity of the asset you want to buyconst quantityDesired = 1; await contract.directListings.buyFromListing( listingId, quantityDesired,);
Auctions
Create and manage auctions in your marketplace.
// Data of the auction you want to createconst auction = { // address of the contract of the asset you want to auction assetContractAddress: "0x...", // token ID of the asset you want to auction tokenId: "0", // how many of the asset you want to auction quantity: 1, // address of the currency contract that will be used to pay for the auctioned tokens currencyContractAddress: NATIVE_TOKEN_ADDRESS, // the minimum bid that will be accepted for the token minimumBidAmount: "1.5", // how much people would have to bid to instantly buy the asset buyoutBidAmount: "10", // If a bid is made less than these many seconds before expiration, the expiration time is increased by this. timeBufferInSeconds: "1000", // A bid must be at least this much bps greater than the current winning bid bidBufferBps: "100", // 100 bps stands for 1% // when should the auction open up for bidding startTimestamp: new Date(Date.now()), // end time of auction endTimestamp: new Date(Date.now() + 5 * 24 * 60 * 60 * 1000),}; const tx = await contract.englishAuctions.createAuction(auction);const receipt = tx.receipt; // the transaction receiptconst id = tx.id; // the id of the newly created auction // And on the buyers side:// The auction ID of the asset you want to bid onconst auctionId = 0;// The total amount you are willing to bid for auctioned tokensconst bidAmount = 1; await contract.englishAuctions.makeBid(auctionId, bidAmount);
Auto-detects ERC1155 standard functions.
Auto-detects ERC20 standard functions.
Offers
Make and manage offers.
// Data of the offer you want to makeconst offer = { // address of the contract the asset you want to make an offer for assetContractAddress: "0x...", // token ID of the asset you want to buy tokenId: "0", // how many of the asset you want to buy quantity: 1, // address of the currency contract that you offer to pay in currencyContractAddress: NATIVE_TOKEN_ADDRESS, // Total price you offer to pay for the mentioned token(s) totalPrice: "1.5", // Offer valid until endTimestamp: new Date(),}; const tx = await contract.offers.makeOffer(offer);const receipt = tx.receipt; // the transaction receiptconst id = tx.id; // the id of the newly created offer // And on the seller's side:// The ID of the offer you want to acceptconst offerId = 0;await contract.offers.acceptOffer(offerId);