Multiwrap
When using the Multiwrap smart contract, additional top-level functionality is available to use.
To access the top-level functionality, provide the multiwrap
contract type when creating the contract instance:
const contract = await sdk.getContract(
"{{contract_address}}",
"multiwrap", // Provide the "multiwrap" contract type
);
As each multiwrap NFT is a newly created NFT, in addition to functionalities listed, the multiwrap contract also implements the following extensions for you to use:
balance
Get the NFT balance of the connected wallet (number of NFTs in this contract owned by the connected wallet).
const balance = await contract.erc721.balance();
Configuration
Return Value
Returns a BigNumber
representing the number of NFTs owned by the connected wallet.
BigNumber;
balanceOf
Get a wallet’s NFT balance (number of NFTs in this contract owned by the wallet).
const walletAddress = "{{wallet_address}}";
const balance = await contract.erc721.balanceOf(walletAddress);
Configuration
get
Get the metadata for an NFT in this contract using it’s token ID.
Metadata is fetched from the uri
property of the NFT.
If the metadata is hosted on IPFS, the metadata is fetched and made available as an object.
The object’s image
property will be a URL that is available through the thirdweb IPFS gateway.
const tokenId = 0;
const nft = await contract.erc721.get(tokenId);
Configuration
tokenId
The token ID of the NFT to get the metadata for.
Must be a BigNumber
, number
, or string
.
const nft = await contract.erc721.get(
"{{token_id}}",
);
Return Value
Returns an NFT
object containing the NFT metadata.
{
metadata: {
id: string;
uri: string; // The raw URI of the metadata
owner: string;
name?: string | number | undefined;
description?: string | null | undefined;
image?: string | null | undefined; // If the image is hosted on IPFS, the URL is https://gateway.ipfscdn.io/ipfs/<hash>
external_url?: string | null | undefined;
animation_url?: string | null | undefined;
background_color?: string | undefined;
properties?: {
[x: string]: unknown;
} | {
[x: string]: unknown;
}[] | undefined;
};
type: "ERC721";
}
get - Contract Metadata
Get the metadata of a smart contract.
const metadata = await contract.metadata.get();
Configuration
Return Value
While the actual return type is any
, you can expect an object containing
properties that follow the
contract level metadata standards, outlined below:
{
name: string; // Name of your smart contract
description?: string; // Short description of your smart contract
image?: string; // Image of your smart contract (any URL, or IPFS URI)
symbol?: string; // Symbol of your smart contract (ticker, e.g. "ETH")
external_link?: string; // Link to view this smart contract on your website
seller_fee_basis_points?: number // The fee you charge on secondary sales, e.g. 100 = 1% seller fee.
fee_recipient?: string; // Wallet address that receives the seller fee
}
get - Owner
Retrieve the wallet address of the owner of the smart contract.
const owner = await contract.owner.get();
Configuration
get - Permissions
Get a list of wallet addresses that are members of a given role.
const members = await contract.roles.get("{{role_name}}");
Configuration
getAll
Get the metadata and current owner of all NFTs in the contract.
By default, returns the first 100
NFTs (in order of token ID). Use queryParams
to paginate the results.
const nfts = await contract.erc721.getAll();
Configuration
queryParams (optional)
Provide an optional object to configure the query. Useful for paginating the results.
const queryParams = {
// The number of NFTs to return
count: 100, // Default is 100
// The index to start from
start: 0, // Default is 0
};
const nfts = await contract.erc721.getAll(queryParams);
Return Value
Returns an array of NFT
objects.
{
metadata: {
id: string;
uri: string; // The raw URI of the metadata
owner: string;
name?: string | number | undefined;
description?: string | null | undefined;
image?: string | null | undefined; // If the image is hosted on IPFS, the URL is https://gateway.ipfscdn.io/ipfs/<hash>
external_url?: string | null | undefined;
animation_url?: string | null | undefined;
background_color?: string | undefined;
properties?: {
[x: string]: unknown;
} | {
[x: string]: unknown;
}[] | undefined;
};
type: "ERC1155" | "ERC721";
}[]
getAll - Permissions
Retrieve all of the roles and associated wallets.
const allRoles = await contract.roles.getAll();
Configuration
Return Value
An object containing role names as keys and an array of wallet addresses as the value.
<Record<any, string[]>>
grant - Permissions
Make a wallet a member of a given role.
const txResult = await contract.roles.grant(
"{{role_name}}",
"{{wallet_address}}",
);
Configuration
revoke - Permissions
Revoke a given role from a wallet.
const txResult = await contract.roles.revoke(
"{{role_name}}",
"{{wallet_address}}",
);
Configuration
getAllOwners
Get all wallet addresses that own an NFT in this contract.
const owners = await contract.erc721.getAllOwners();
Configuration
Return Value
Returns an array of objects containing a tokenId
and owner
address.
tokenId
is the ID of the NFT.owner
is the wallet address of the owner that owns the NFT.
{
tokenId: number;
owner: string;
}
[];
getDefaultRoyaltyInfo
Gets the royalty recipient and BPS (basis points) of the smart contract.
const royaltyInfo = await contract.royalties.getDefaultRoyaltyInfo();
Configuration
Return Value
Returns an object containing the royalty recipient address and BPS (basis points) of the smart contract.
{
seller_fee_basis_points: number;
fee_recipient: string;
}
getOwned
Get the metadata of all NFTs a wallet owns from this contract.
// Address of the wallet to get the NFTs of
const address = "{{wallet_address}}"; // Optional - Defaults to the connected wallet
const nfts = await contract.erc721.getOwned(address);
Configuration
address (optional)
The address of the wallet to get the NFTs of. If not provided, defaults to the connected wallet address.
const nfts = await contract.erc721.getOwned(
"{{wallet_address}}",
);
Return Value
Returns an array of NFT
objects.
{
metadata: {
id: string;
uri: string; // The raw URI of the metadata
owner: string;
name?: string | number | undefined;
description?: string | null | undefined;
image?: string | null | undefined; // If the image is hosted on IPFS, the URL is https://gateway.ipfscdn.io/ipfs/<hash>
external_url?: string | null | undefined;
animation_url?: string | null | undefined;
background_color?: string | undefined;
properties?: {
[x: string]: unknown;
} | {
[x: string]: unknown;
}[] | undefined;
};
type: "ERC1155" | "ERC721";
}[]
getOwnedTokenIds
Get the token IDs of all NFTs a wallet owns from this contract.
const ownedTokenIds = await contract.erc721.getOwnedTokenIds(
"{{wallet_address}}",
);
Configuration
getTokenRoyaltyInfo
Gets the royalty recipient and BPS (basis points) of a particular token in the contract.
const royaltyInfo = await contract.royalties.getTokenRoyaltyInfo(
"{{token_id}}",
);
Configuration
getWrappedContents
Get the contents that are wrapped inside of a multiwrap NFT.
const contents = await contract.getWrappedContents("{{token_id}}");
Configuration
tokenId
The token ID of the multiwrap NFT to get the contents of.
Must be a string
, number
, or BigNumber
.
unwrap
Unwrap a multiwrap NFT and get the contents out of it.
Note: this process burns the multiwrap NFT.
const txResult = await contract.unwrap("{{token_id}}");
Configuration
isApproved
Get whether this wallet has approved transfers from the given operator.
This means that the operator can transfer NFTs on behalf of this wallet.
const isApproved = await contract.erc721.isApproved(
// Address of the wallet to check
"{{wallet_address}}",
// Address of the operator to check
"{{wallet_address}}",
);
Configuration
owner
The wallet address that owns the NFT.
Must be a string
.
const isApproved = await contract.erc721.isApproved(
"{{wallet_address}}",
"{{wallet_address}}",
);
operator
The wallet address of the operator to check (i.e. the wallet that does/does not have approval).
Must be a string
.
const isApproved = await contract.erc721.isApproved(
"{{wallet_address}}",
"{{wallet_address}}",
);
ownerOf
Get the wallet address of the owner of an NFT.
const owner = await contract.erc721.ownerOf("{{token_id}}");
Configuration
set - Contract Metadata
Overwrite the metadata of a contract, an object following the contract level metadata standards.
This operation ignores any existing metadata and replaces it with the new metadata provided.
const txResult = await contract.metadata.set({
name: "My Contract",
description: "My contract description",
});
Configuration
metadata
Provide an object containing the metadata of your smart contract following the contract level metadata standards.
{
name: string; // Name of your smart contract
description?: string; // Short description of your smart contract
image?: string; // Image of your smart contract (any URL, or IPFS URI)
symbol?: string; // Symbol of your smart contract (ticker, e.g. "ETH")
external_link?: string; // Link to view this smart contract on your website
seller_fee_basis_points?: number // The fee you charge on secondary sales, e.g. 100 = 1% seller fee.
fee_recipient?: string; // Wallet address that receives the seller fee
}
set - Owner
Set the owner address of the contract.
const txResult = await contract.owner.set("{{wallet_address}}");
Configuration
owner
The wallet address of the new owner.
Must be a string
.
const txResult = await contract.owner.set(
"{{wallet_address}}",
);
setAll - Permissions
Overwrite all roles with new members.
This overwrites all members, INCLUDING YOUR OWN WALLET ADDRESS!
This means you can permanently remove yourself as an admin, which is non-reversible.
Please use this method with caution.
const txResult = await contract.roles.setAll({
admin: ["0x12", "0x123"],
minter: ["0x1234"],
});
Configuration
roles
An object containing role names as keys and an array of wallet addresses as the value.
const txResult = await contract.roles.setAll(
{
admin: ["0x12", "0x123"], // Grant these two wallets the admin role
minter: ["0x1234"], // Grant this wallet the minter role
},
);
setApprovalForAll
Give another address approval (or remove approval) to transfer any of your NFTs from this collection.
Proceed with caution. Only approve addresses you trust.
await contract.erc721.setApprovalForAll(
"{{wallet_address}}", // The wallet address to approve
true, // Whether to approve (true) or remove approval (false)
);
Configuration
setApprovalForToken
Give another address approval (or remove approval) to transfer a specific one of your NFTs from this collection.
Proceed with caution. Only approve addresses you trust.
// Approve the wallet address
await contract.erc721.setApprovalForToken(
"{{wallet_address}}", // The wallet address to approve
"{{token_id}}", // The token ID of the NFT to allow them to transfer
);
Configuration
setDefaultRoyaltyInfo
Set the royalty recipient and fee for the smart contract.
await contract.royalties.setDefaultRoyaltyInfo({
seller_fee_basis_points: 100, // 1% royalty fee
fee_recipient: "0x...", // the fee recipient
});
Configuration
setTokenRoyaltyInfo
Set the royalty recipient and fee for a particular token in the contract.
await contract.royalties.setTokenRoyaltyInfo("{{token_id}}", {
seller_fee_basis_points: 100, // 1% royalty fee
fee_recipient: "0x...", // the fee recipient
});
Configuration
verify - Permissions
Check to see if a wallet has a set of roles.
Throws an error if the wallet does not have any of the given roles.
const verifyRole = await contract.roles.verify(
["admin", "minter"],
"{{wallet_address}}",
);
Configuration
totalCirculatingSupply
Get the total number of NFTs that are currently in circulation.
i.e. the number of NFTs that have been minted and not burned.
const totalSupply = await contract.erc721.totalCirculatingSupply();
Configuration
totalCount
Get the total number of NFTs minted in this contract.
Unlike totalCirculatingSupply
, this includes NFTs that have been burned.
const totalSupply = await contract.erc721.totalCount();
Configuration
transfer
Transfer an NFT from the connected wallet to another wallet.
const walletAddress = "{{wallet_address}}";
const tokenId = 0;
await contract.erc721.transfer(walletAddress, tokenId);
Configuration
update - Contract Metadata
Update the metadata of your smart contract.
const txResult = await contract.metadata.update({
name: "My Contract",
description: "My contract description",
});
Configuration
metadata
Provide an object containing the metadata of your smart contract following the contract level metadata standards.
New properties will be added, and existing properties will be overwritten. If you do not provide a new value for a previously set property, it will remain unchanged.
Below are the properties you can define on your smart contract.
{
name: string; // Name of your smart contract
description?: string; // Short description of your smart contract
image?: string; // Image of your smart contract (any URL, or IPFS URI)
symbol?: string; // Symbol of your smart contract (ticker, e.g. "ETH")
external_link?: string; // Link to view this smart contract on your website
seller_fee_basis_points?: number // The fee you charge on secondary sales, e.g. 100 = 1% seller fee.
fee_recipient?: string; // Wallet address that receives the seller fee
}
wrap
Wrap a set of tokens into a new multiwrap NFT.
Note: you need to provide the multiwrap smart contract allowance
(for ERC20 tokens), or approval
(for ERC721 and ERC1155 NFTs)
before calling the wrap
function.
- ERC721 tokens:
setApprovalForToken
. - ERC1155 tokens:
setApprovalForAll
. - ERC20 tokens:
setAllowance
.
// Grant approval - ERC721 tokens
await erc721Contract.setApprovalForToken(multiwrapAddress, "{{token_id}}";
// Grant approval - ERC1155 tokens
await erc1155Contract.setApprovalForAll(multiwrapAddress, true);
// Grant approval - ERC20 tokens
await erc20Contract.setAllowance(multiwrapAddress, "{{quantity}}");
// Finally, wrap the tokens in to a new multiwrap NFT
const txResult = await contract.wrap(
{
erc20Tokens: [
{
contractAddress: "0x...", // Contract address of the token contract
quantity: "0.8", // Quantity of this token to wrap
},
],
erc721Tokens: [
{
contractAddress: "0x...", // Contract address of the NFT smart contract
tokenId: "0", // Token ID of the NFT to wrap
},
],
erc1155Tokens: [
{
contractAddress: "0x...", // Contract address of the NFT smart contract
tokenId: "1", // Token ID of the NFT to wrap
quantity: "2", // Quantity of this NFT to wrap
},
],
},
// Metadata of the new multiwrap NFT to create
{
name: "Wrapped bundle",
description: "This is a wrapped bundle of tokens and NFTs",
image: "ipfs://...", // Can be any IPFS URI, or URL, or File object.
}
);
Configuration
erc20Tokens
An array of objects containing a contractAddress
and quantity
of the ERC20 token to wrap.
erc721Tokens
An array of objects containing a contractAddress
and tokenId
of the ERC721 token to wrap.
erc1155Tokens
An array of objects containing a contractAddress
, tokenId
, and quantity
of the ERC1155 token to wrap.
metadata
An object containing the metadata of the new multiwrap NFT to create.
Metadata can be a string
, containing a URL that points to,
or an object containing valid metadata properties.