Multiwrap
When using the Multiwrap smart contract, additional top-level functionality is available to use.
To access the top-level functionality, use the get_multiwrap
method when creating the contract instance:
contract = python.get_multiwrap(
"{{contract_address}}",
)
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:
get_wrapped_contents
Get the contents of a wrapped token bundle.
token_id = 0
contents = contract.get_wrapped_contents(token_id)
print(contents.erc20_tokens)
print(contents.erc721_tokens)
print(contents.erc1155_tokens)
Configuration
token_id
The ID of the wrapped token to get the contents of. Must be of type int
.
token_id = 0
contents = contract.get_wrapped_contents(token_id)
Return Value
The contents of the wrapped token bundle, of type WrappedTokens
class WrappedTokens:
erc20_tokens: List[ERC20Wrappable] = dataclasses.field(default_factory=list)
erc721_tokens: List[ERC721Wrappable] = dataclasses.field(default_factory=list)
erc1155_tokens: List[ERC1155Wrappable] = dataclasses.field(default_factory=list)
class ERC20Wrappable:
contract_address: str
quantity: Price
class ERC721Wrappable:
contract_address: str
token_id: int
class ERC1155Wrappable:
contract_address: str
token_id: int
quantity: int
wrap
Wrap any number of ERC20, ERC721, or ERC1155 tokens into a single wrapped token.
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)
Configuration
contents
The tokens to wrap into a single wrapped token. Must be a TokensToWrap
object.
class TokensToWrap:
erc20_tokens: List[ERC20Wrappable] = dataclasses.field(default_factory=list)
erc721_tokens: List[ERC721Wrappable] = dataclasses.field(default_factory=list)
erc1155_tokens: List[ERC1155Wrappable] = dataclasses.field(default_factory=list)
from thirdweb.types import (
TokensToWrap,
ERC20Wrappable,
ERC721Wrappable,
ERC1155Wrappable,
NFTMetadataInput,
)
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)
wrapped_token_metadata
The metadata to use for the wrapped token. Must a NFTMetadataInput
object.
class NFTMetadataInput:
name: str
description: Optional[str] = None
image: Optional[str] = None
external_url: Optional[str] = None
animation_url: Optional[str] = None
background_color: Optional[str] = None
properties: Optional[Dict[str, Any]] = None
attributes: Optional[Dict[str, Any]] = None
from thirdweb.types import (
TokensToWrap,
ERC20Wrappable,
ERC721Wrappable,
ERC1155Wrappable,
NFTMetadataInput,
)
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)
recipient_address (optional)
The optional address to send the wrapped token to. Must be of type str
.
from thirdweb.types import (
TokensToWrap,
ERC20Wrappable,
ERC721Wrappable,
ERC1155Wrappable,
NFTMetadataInput,
)
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://...",
),
recipient_address="0x..."
)
print(tx.receipt, tx.id)
unwrap
Unwrap a wrapped token bundle
wrapped_token_id = 0
recipient_address = "0x..."
tx = contract.unwrap(wrapped_token_id, recipient_address)
Configuration
wrapped_token_id
The ID of the wrapped token to unwrap. Must be of type int
.
wrapped_token_id = 0
recipient_address = "0x..."
tx = contract.unwrap(wrapped_token_id, recipient_address)
recipient_address (optional)
The optional address to send the unwrapped tokens to. Must be of type str
.
wrapped_token_id = 0
recipient_address = "0x..."
tx = contract.unwrap(wrapped_token_id, recipient_address)