Multiwrap
Learn how to interact with your Multiwrap contract in the SDK.
Create a Multiwrap Contract
- React
- Javascript
- Python
- Go
const sdk = useSDK();
const contractAddress = await sdk.deployer.deployMultiwrap({
name: "My Multiwrap",
});
const contractAddress = await sdk.deployer.deployMultiwrap({
name: "My Multiwrap",
});
Python SDK support for deployMultiwrap is coming soon.
Want this feature sooner? Let us know in Discord!
Go SDK support for deployMultiwrap is coming soon.
Want this feature sooner? Let us know in Discord!
Getting the contract in your application
To start using your Multiwrap contract inside your application, you need to use its contract address. You can get the contract address from the dashboard.
- React
- Javascript
- Python
- Go
import { useMultiwrap } from '@thirdweb-dev/react'
export default function Component() {
const multiwrap = useMultiwrap("<YOUR-CONTRACT-ADDRESS>")
// Now you can use the multiwrap contract in the rest of the component
}
import { ThirdwebSDK } from "@thirdweb-dev/sdk";
const sdk = new ThirdwebSDK("{{chainName}}");
const contract = sdk.getMultiwrap("{{contract_address}}");
from thirdweb import ThirdwebSDK
# You can customize this to a supported network or your own RPC URL
network = "mumbai"
# Now we can create a new instance of the SDK
sdk = ThirdwebSDK(network)
# If you want to send transactions, you can instantiate the SDK with a private key instead:
# sdk = ThirdwebSDK.from_private_key(PRIVATE_KEY, network)
contract = sdk.get_multiwrap("{{contract_address}}")
import (
"github.com/thirdweb-dev/go-sdk/thirdweb"
)
privateKey = "..."
sdk, err := thirdweb.NewThirdwebSDK("mumbai", &thirdweb.SDKOptions{
PrivateKey: privateKey,
})
contract, err := sdk.GetMultiwrap("{{contract_address}}")
Setting Royalty Fees
- React
- Javascript
- Python
- Go
// royalties on the whole contract
contract.royalties.setDefaultRoyaltyInfo({
seller_fee_basis_points: 100, // 1%
fee_recipient: "0x..."
});
// override royalty for a particular token
contract.royalties.setTokenRoyaltyInfo(tokenId, {
seller_fee_basis_points: 500, // 5%
fee_recipient: "0x..."
});
// royalties on the whole contract
contract.royalties.setDefaultRoyaltyInfo({
seller_fee_basis_points: 100, // 1%
fee_recipient: "0x..."
});
// override royalty for a particular token
contract.royalties.setTokenRoyaltyInfo(tokenId, {
seller_fee_basis_points: 500, // 5%
fee_recipient: "0x..."
});
Python SDK support for royalties is coming soon.
Want this feature sooner? Let us know in Discord!
Go SDK support for royalties is coming soon.
Want this feature sooner? Let us know in Discord!
Wrapping Tokens
You can wrap any number of ERC20, ERC721, or ERC1155 tokens into a single wrapped ERC721 NFT.
When you wrap NFTs, you mint a new NFT into the Multiwrap contract.
- React
- Javascript
- Python
- Go
const tx = await contract.wrap({
erc20Tokens: [{
contractAddress: "0x...",
quantity: "0.8"
}],
erc721Tokens: [{
contractAddress: "0x...",
tokenId: "0"
}],
erc1155Tokens: [{
contractAddress: "0x...",
tokenId: "1",
quantity: "2"
}]
}, {
name: "Wrapped bundle",
description: "This is a wrapped bundle of tokens and NFTs",
image: "ipfs://...",
});
const receipt = tx.receipt(); // the transaction receipt
const wrappedTokenId = tx.id; // the id of the wrapped token bundle
const tx = await contract.wrap({
erc20Tokens: [{
contractAddress: "0x...",
quantity: "0.8"
}],
erc721Tokens: [{
contractAddress: "0x...",
tokenId: "0"
}],
erc1155Tokens: [{
contractAddress: "0x...",
tokenId: "1",
quantity: "2"
}]
}, {
name: "Wrapped bundle",
description: "This is a wrapped bundle of tokens and NFTs",
image: "ipfs://...",
});
const receipt = tx.receipt(); // the transaction receipt
const wrappedTokenId = tx.id; // the id of the wrapped token bundle
from thirdweb.types import (
TokensToWrap,
ERC20Wrappable,
ERC721Wrappable,
ERC1155Wrappable,
NFTMetadataInput,
)
# Contract setup goes here...
tx = contract.wrap(
TokensToWrap(
erc20_tokens=[
ERC20Wrappable(contract_address="0x...", quantity=0.8),
],
erc721_tokens=[
ERC721Wrappable(contract_address="0x...", token_id=0),
],
erc1155_tokens=[
ERC1155Wrappable(contract_address="0x...", token_id=0, quantity=1),
]
),
NFTMetadataInput(
name="Wrapped NFT",
description="This is a wrapped bundle of tokens and NFTs",
image="ipfs://...",
)
)
print(tx.receipt, tx.id)
contents := &thirdweb.MultiwrapBundle{
ERC20Tokens: []*thirdweb.MultiwrapERC20{
&thirdweb.MultiwrapERC20{
ContractAddress: "0x...",
Quantity: 1,
},
},
ERC721Tokens: []*thirdweb.MultiwrapERC721{
&thirdweb.MultiwrapERC721{
ContractAddress: "0x...",
TokenId: 1,
},
},
ERC1155Tokens: []*thirdweb.MultiwrapERC1155{
&thirdweb.MultiwrapERC1155{
ContractAddress: "0x...",
TokenId: 1,
Quantity: 1,
},
},
}
wrappedTokenMetadata := &thirdweb.NFTMetadataInput{
Name: "Wrapped Token"
}
// This will mint the wrapped token to the connected wallet
tx, err := contract.Wrap(contents, wrappedTokenMetadata, "")
Viewing Wrapped NFTs
One wrapped NFT
- React
- Javascript
- Python
- Go
const { contract } = useContract(<ContractAddress>);
const { data: nft, isLoading, error } = useNFT(contract?.nft, <tokenId>);
const tokenId = 0;
const nft = await contract.nft.get(tokenId);
nft = contract.get(0)
print(nft)
nft, err := contract.Get(0)
All wrapped NFTs
- React
- Javascript
- Python
- Go
const { contract } = useContract(<ContractAddress>);
const { data: nfts, isLoading, error } = useNFTs(contract?.nft, { start: 0, count: 100 });
const wrappedBundles = await contract.getAll();
console.log(wrappedBundles);
nfts = contract.get_all()
print(nfts)
nfts, err := contract.GetAll()
ownerOne := nfts[0].Owner
nameOne := nfts[0].Metadata.Name
Amount of tokens owned by a specific wallet
- React
- Javascript
- Python
- Go
const { contract } = useContract(<ContractAddress>);
const { data: ownerBalance, isLoading, error } = useNFTBalance(contract?.nft, <OwnerWalletAddress>);
const walletAddress = "{{wallet_address}}";
const balance = await contract.nft.balanceOf(walletAddress);
console.log(balance);
balance = contract.balance_of("{{wallet_address}}")
print(balance)
address := "{{wallet_address}}"
balance, err := contract.BalanceOf(address)
View Wrapped NFT Contents
- React
- Javascript
- Python
- Go
const contents = await contract.getWrappedContents(wrappedTokenId);
console.log(contents.erc20Tokens);
console.log(contents.erc721Tokens);
console.log(contents.erc1155Tokens);
const contents = await contract.getWrappedContents(wrappedTokenId);
console.log(contents.erc20Tokens);
console.log(contents.erc721Tokens);
console.log(contents.erc1155Tokens);
token_id = 0
contents = contract.get_wrapped_contents(token_id)
print(contents.erc20_tokens)
print(contents.erc721_tokens)
print(contents.erc1155_tokens)
tokenId := 0
contents, err := contract.GetWrappedContents(tokenId)
erc20Tokens := contents.Erc20Tokens
erc721Tokens := contents.Erc721Tokens
erc1155Tokens := contents.Erc1155Tokens
Unwrapping Tokens
When you unwrap a wrapped NFT, you can get the underlying tokens back and burn the wrapped NFT.
- React
- Javascript
- Python
- Go
await contract.unwrap(wrappedTokenId);
await contract.unwrap(wrappedTokenId);
tx = contract.unwrap(wrapped_token_id, receipientAddress)
tokenId := 0
tx, err := contract.Unwrap(tokenId, "")
Transferring NFTs
- React
- Javascript
- Python
- Go
const walletAddress = "{{wallet_address}}";
const tokenId = 0;
await contract.nft.transfer(walletAddress, tokenId);
const walletAddress = "{{wallet_address}}";
const tokenId = 0;
await contract.nft.transfer(walletAddress, tokenId);
to = "{{wallet_address}}"
token_id = 0
receipt = contract.transfer(to, token_id)
to := "0x..."
tokenId := 0
tx, err := contract.Transfer(to, tokenId)