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
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
get - Contract Metadata
Get the metadata of a smart contract.
const metadata = await contract.metadata.get();
Configuration
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
getAll - Permissions
Retrieve all of the roles and associated wallets.
const allRoles = await contract.roles.getAll();
Configuration
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
getDefaultRoyaltyInfo
Gets the royalty recipient and BPS (basis points) of the smart contract.
const royaltyInfo = await contract.royalties.getDefaultRoyaltyInfo();
Configuration
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
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
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
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
set - Owner
Set the owner address of the contract.
const txResult = await contract.owner.set("{{wallet_address}}");
Configuration
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
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
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.
}
);