Brownie: Create and Mint an NFT Using Brownie

Learn how to create and mint an NFT using Brownie.

What is Brownie?

Brownie is a smart contract web3 development framework built from the Python library web3.py. Brownie has a variety of template projects for users to get started with and develop their own projects. These templates are referred to as ‘Brownie mixes’. In this tutorial, we’ll use a Brownie mix for creating an ERC721 NFT token. This mix comes with some sample assets and metadata files, but we’ll upload our own assets to Filebase and create personalized metadata files to create our NFTs.

Read below to learn how to create and mint an NFT using Brownie.

Prerequisites:

1. We’ll start by uploading an image to Filebase for us to use as an NFT.

To do this, navigate to console.filebase.com. If you don’t have an account already, sign up, then log in.

2. Select ‘Buckets’ from the left side bar menu, or navigate to console.filebase.com/buckets.

Select ‘Create Bucket’ in the top right corner to create a new bucket for your NFTs.

3. Enter a bucket name and choose the IPFS storage network to create the bucket.

Bucket names must be unique across all Filebase users, be between 3 and 63 characters long, and can contain only lowercase characters, numbers, and dashes.

4. Next, select the bucket from your list of buckets, then select ‘Upload’ in the top right corner to upload your image file.

5. Select your image to be uploaded.

Once uploaded, it will be listed in the bucket.

6. You can view the object’s IPFS CID in the CID column, or you can click on your uploaded object to display the metadata for the object, which includes the IPFS CID.

Choose the method you prefer, and take note of the IPFS CID for your image. We will reference this later.

7. Next, create a new .json file that correlates with your NFT image.

This can be named anything you’d like, but ideally should correlate to whichever NFT it belongs with. For example, if you name your NFTs according to their number in the collection, the .json file for NFT #1 should be 1.json.

This file will hold the metadata for your NFT, such as its name, description, and any attributes. The format of this file is as follows:

{
    "name": "name",
    "description": "description",
    "image": "https://ipfs.io/ipfs/FILEBASE_IPFS_CID",
    "attributes": [
        {
            "trait_type": "trait",
            "value": 100
        }
    ]
}

Replace the name, description, and attributes with any values you want. Then replace the FILEBASE_IPFS_CID value with the IPFS CID you took note of in Step 6.

8. Then, upload this .json file to your Filebase IPFS bucket using the same workflow we used to upload our image files.

Take note of the IPFS CID for your .json file.

9. Next, open a command prompt window.

Use the following commands to download the Brownie Mix for creating NFTs:

git clone https://github.com/PatrickAlphaC/nft-mix

cd nft-mix

10. Then install the eth-brownie package and ganache-cli:

pip install eth-brownie

npm install -g ganache-cli

11. Next, login to the Infura.io console. Create a new project.

12. Select the Ethereum network, and give your project a name.

13. In the Project settings, select "Rinkeby” from the endpoint dropdown menu.

14. Then, take down the Project ID. You will need this in the next step.

15. Next, get your cryptowallet’s private key.

If you are using Metamask, follow the instructions found here.

16. Open the .env file in your project directory.

Replace the existing content with the following:

export PRIVATE_KEY=WALLET_PRIVATE_KEY

export WEB3_INFURA_PROJECT_ID=INFURA_PROJECT_ID

Replace the values WALLET_PRIVATE_KEY with your cryptowallet’s private key, and INFURA_PROJECT_ID with your Infura Project ID.

Save the file.

17. Now it’s time to deploy our smart contract.

This Brownie Mix uses the OpenZepplin package for the ERC721 token. Use the following command to deploy the contract:

brownie run scripts/simple_collectible/deploy_simple.py --network rinkeby

18. Then, open the file located at scripts/simple_collectible/create_collectible.py.

This is the script that creates our NFT. We’ll need to edit this file to use the IPFS image we uploaded to Filebase. Replace the following line in this script:

sample_token_uri = "ipfs://FILEBASE_IPFS_CID”

Replace FILEBASE_IPFS_CID with the IPFS CID of your NFT image from the beginning of this tutorial.

19. Now we’re ready to run this script to mint our NFT.

Run the script with the following command:

brownie run scripts/simple_collectible/create_collectible.py --network rinkeby

You’ve now minted your first NFT on the Ethereum testnet! From here, you can upload more image files and json files, then change your script to reflect the IPFS CID for each one to upload as many NFTs as you’d like!

If you have any questions, please join our Discord server, or send us an email at hello@filebase.com

Last updated