NFT Collection
When using the NFT Collection smart contract, additional top-level functionality is available to use.
To access the top-level functionality, use the get_nft_collection
method when creating the contract instance:
contract = python.get_nft_collection(
"{{contract_address}}",
)
The extensions that the NFT collection contract supports are listed below.
- ERC721
- ERC721Burnable
- ERC721Supply
- ERC721Enumerable
- ERC721Mintable
- ERC721BatchMintable
- ERC721SignatureMint
- Royalty
- PlatformFee
- PrimarySale
- Permissions
- ContractMetadata
- Ownable
- Gasless
get_owned
Get the token IDs owned by a specific address.
address = "0x..."
owned_nfts = contract.get_owned(address)
Configuration
get_owned_token_ids
Get the token IDs owned by a specific address
address = "0x..."
owned_token_ids = contract.get_owned_token_ids(address)
Configuration
mint
Mint a new NFT to the connected wallet
from thirdweb.types.nft import NFTMetadataInput
# You can customize the metadata to your needs
metadata = NFTMetadataInput.from_json({
"name": "Cool NFT",
"description": "This is a cool NFT",
"image": open("path/to/file.jpg", "rb")
})
tx = contract.mint(metadata)
receipt = tx.receipt
token_id = tx.id
nft = tx.data()
Configuration
metadata
Either provide a string
that points to valid metadata object
or an NFTMetadataInput
object containing the metadata.
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
The image
property can be an IPFS URI, a URL, or a File
object.
If a file is provided for the image, it will also be uploaded and pinned to IPFS before minting.
Using a string:
# Option 1: Provide a string that points to valid metadata object
metadata = "https://example.com/metadata.json"
Using an object:
from thirdweb.types.nft import NFTMetadataInput
# Option 2: Provide a metadata object, which will be uploaded and pinned to IPFS for you.
metadata = NFTMetadataInput.from_json(
"name": "Cool NFT #1",
"description": "This is a cool NFT",
"image": "https://example.com/image.png", # URL, IPFS URI, or File object
# ... Any other metadata you want to include
)
Provide the metadata to the mint
function:
# Either the string or the object can be provided to the mint function
tx = contract.mint(metadata)
mint_to
The same as mint
, but allows you to specify the address of the wallet that will receive the NFT rather than using
the connected wallet address.
from thirdweb.types.nft import NFTMetadataInput
# Note that you can customize this metadata however you like
metadata = NFTMetadataInput.from_json({
"name": "Cool NFT",
"description": "This is a cool NFT",
"image": open("path/to/file.jpg", "rb"),
})
# You can pass in any address here to mint the NFT to
tx = contract..mint_to("0x7fDae677aA6f94Edff9872C4b91D26407709c790", metadata)
receipt = tx.receipt
token_id = tx.id
nft = tx.data()
Configuration
mint_batch
Mint multiple NFTs in a single transaction to the connected wallet.
from thirdweb.types.nft import NFTMetadataInput
tx = contract.mint_batch([
NFTMetadataInput.from_json(
"name": "Cool NFT #1",
"description": "This is a cool NFT",
"image": "https://example.com/image.png", // URL, IPFS URI, or File object
),
NFTMetadataInput.from_json(
"name": "Cool NFT #2",
"description": "This is a cool NFT",
"image": "https://example.com/image.png", // URL, IPFS URI, or File object
),
])
Configuration
metadatas
A list of strings that point to, or NFTMetadataInput
objects containing
valid metadata properties.
List[Union(NFTMetadataInput, str)]
See mint
for more details on the properties available.
mint_batch_to
The same as mint_batch
, but allows you to specify the address
of the wallet that will receive the NFTs rather than using the connected wallet address.
from thirdweb.types.nft import NFTMetadataInput
tx = contract.mint_batch_to("{{wallet_address}}", [
NFTMetadataInput.from_json(
"name": "Cool NFT #1",
"description": "This is a cool NFT",
"image": "https://example.com/image.png", // URL, IPFS URI, or File object
),
NFTMetadataInput.from_json(
"name": "Cool NFT #2",
"description": "This is a cool NFT",
"image": "https://example.com/image.png", // URL, IPFS URI, or File object
),
])
Configuration
wallet_address
The address of the wallet you want to mint the NFTs to.
Must be a string
.
metadatas
A list of strings that point to, or NFTMetadataInput
objects containing
valid metadata properties.
See mint
for more details on the properties available.