thirdweb

Mint an NFT Collection with Python

Mint an NFT Collection with Python

Published on:

November 18, 2021

Mint your own NFT using the thirdweb Python SDK

Pratham Prasoon & Raza Zaidi

Intro

This guide explains in 5 easy steps how to mint an NFT. Minting an NFT requires a couple of steps. We need to create a project in the dashboard and create an NFT Collection module inside our project. We also need to connect a wallet. So if you don't have a wallet, make sure to sign up with MetaMask or CoinWallet. We are gonna use Metamask, if you don't have one, you can follow this guide.

Alright without further ado, let's mint an NFT.

Dashboard setup

The first thing we need to do is head over to the dashboard and create a project and an NFT Collection module. if you don't know how to do this, check out this guide.

Once you've set everything up, it's time to mint our first NFT, but we don't need the dashboard for that! I mean we could, but why use GUI if we can use Python!?

The code

1. Create a Python file and fire up a virtual environment

Go ahead and create a new Python file. Let's call it python_nft.py and open it in your favorite code editor. We'll use Visual Studio.

Next up use the following code in your terminal to create a virtual environment and install the ThirdWeb SDK!

virtual-env
#create a virtual environment python3 -m venv ./myenv #activate virtual environment source ./myenv/bin/activate #install the thirdweb sdk pip install thirdweb-sdk
virtual-env
#create a virtual environment conda create -n "thirdweb" python=3.9 #activate virtual environment conda activate thirdweb #install the thirdweb sdk pip install thirdweb-sdk

2. Import the SDK

In order to make use of our SDK, you need to establish a connection to a blockchain. Click here to learn how to connect to the blockchain and instantiate our SDK.

For this guide, you will need to instantiate the SDK following these steps, using your own signer with thirdweb.

3. Define which module to use

Now we need to define which module we want to use. This is the module we just created inside our project PythonNFT. We called the module 'Python1'. This module has an address. We need to pass the address here. You can find the address here, under Python1:

In our python_nft.py we include the following code. First we define a variable nft_smart_contract_address and store our module address in here.

Then we create an object that uses the NFT Collection module inside the sdk with our address.

python_nft.py
#pick your module and enter the smart contract address nft_smart_contract_address = "0xdd25FAEE772FbB1bcB7ba0b2cEE6387A8F82f032" nft_module = sdk.get_nft_module(nft_smart_contract_address)

4. Time to mint the NFT!

The arguments passed over here are the same as minting an NFT inside the dashboard. If you want to familiarize yourself with the process, check out the dashboard!

python_nft.py
#Mint an NFT on your smartcontract name_nft = "new nft!" description_nft = "NFT EXAMPLE" image_nft = "ipfs://QmdFeKxt6FJUNvaGgzYuYNRbpNWyHxP2PFzjsgPf1eD2Jf" prop = {} nft_module.mint(MintArg(name=name_nft, description=description_nft, image_uri=image_nft, properties=prop))

5. Results

Get the balance to check it out or head over to the dashboard.

python_nft.py
#check your balance to check if you minted an nft! print(nft_module.balance())

So the only thing left is to run our code! Open a terminal and paste the following:

# Runs the python file python python_nft.py

That's it!

You have minted your own NFT using thirdweb and the Python SDK, you should be proud!


Ready to build your first web3 app? Get early access & add web3 features to your project today.

Pratham Prasoon & Raza Zaidi

Contents

Intro

Dashboard setup

The code

1. Create a Python file and fire up a virtual environment

2. Import the SDK

3. Define which module to use

4. Time to mint the NFT!

5. Results

That's it!