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
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
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
),
])