NodeReal Tutorials  / Embrace the Future of NFTs with BNB Greenfield
7 min read

Embrace the Future of NFTs with BNB Greenfield

Embrace the Future of NFTs with BNB Greenfield

TL;DR

💠BNB Greenfield is here to make it easy for you! Effortlessly upload your NFT resources and metadata.

💠To ensure your NFTs remain stored, make sure your payment account has a sufficient balance to pay the storage provider.

💠As an open marketplace, BNB Greenfield offers competitive storage pricing as compared to other storage solutions, like S3, Arweave, and Filecoin.

💠Generate your NFT using BSC, and store its metadata on the BNB Greenfield without the need for any additional tokens.

Get Started with tBNB on BNB Greenfield

Ready to get started with tBNB on BNB Greenfield? Great! If you already have the token in your wallet, you're good to go. Otherwise, simply head over to BNB-Chain discord and find <testnet-faucet> channel to get the tBNB you need. Redeem the BNB from the faucet and bridge over for tBNB through DCellar.

Bridging BNB for tBNB

Create a NFT smart contract on the BNB Smart Chain

Looking for a user-friendly and high-performance decentralized storage network to store your NFTs? Look no further than BNB Greenfield! It's accessible through dApp DCellar, blockchain explorer GreenfieldScan, Greenfield CLI, and SDKs, making it easy for you to use.

To create your NFT collection, we recommend using the secure and reusable smart contracts provided by the OpenZeppelin library. In this guide, we'll demonstrate how to create a "CrazyCodingGirl'' NFT collection using OpenZeppelin's popular ERC721 standard.

ERC721 is a widely-adopted standard for unique digital assets on the blockchain. Each token has a distinct identifier and can include metadata such as names, descriptions, and images. These tokens can be transferred, traded, and sold across various supporting platforms.

Using OpenZeppelin's ERC721PresetMinterPauserAutoId contract, the "CrazyCodingGirl" collection will follow the ERC721 standard and include extra features:

- Minter: a role permitting new token minting

- Pauser: a role enabling token transfer pausing

- AutoId: a feature assigning sequential token IDs automatically

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;


import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/utils/Counters.sol";


contract CrazyCodingGril is ERC721 {
   using Counters for Counters.Counter;
   Counters.Counter private _tokenIds;


   mapping(uint256 => string) private _tokenURIs;


   constructor() ERC721("CrazyCodingGril", "NFT721") {}


   function mintNFT(address recipient, string memory tokenURI) public returns (uint256) {
      
       _tokenIds.increment();
       uint256 newItemId = _tokenIds.current();
       _mint(recipient, newItemId);
       _tokenURIs[newItemId] = tokenURI;


       return newItemId;
   }


   function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
       require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
       return _tokenURIs[tokenId];
   }
}

Using Remix IDE, compile the smart contract and deploy it to a local environment for testing purposes.

ERC721 Token URI with Greenfield

Once deployed, prepare the TokenURI for your upcoming NFT token. TokenURI is a property of ERC721 non-fungible tokens (NFTs) that stores a unique Uniform Resource Identifier (URI). This URI points to the token's metadata, typically a JSON file containing information such as the token's name, description, image URL, and other attributes. The tokenURI serves as a standardized way to access and display information about a specific NFT, making it easier for various platforms and applications to interact with and present NFTs consistently.

Token metadata

Example:

{
  "name": "Your Token Name",
  "description": "A brief description of your token.",
  "image": "URL_OF_NFT_CONTENTS"
}

Uploading "Cool Girl" to BNB Greenfield

Let's get started - our next token is named "Cool Girl"! Here's how to upload the "Cool Girl" JPEG file to the BNB Greenfield network using either DCellar or the Greenfield CLI:

1️⃣
Open either DCellar or the Greenfield CLI and log in to your BNB Greenfield account.
2️⃣
Upload the "Cool Girl" JPEG file to your account, ensuring that the file is set to public-read.
3️⃣
Once uploaded, copy the view URL for the file from BNB Greenfield for later use.
🥳
That's it! 

By following these simple steps, you can easily upload your digital assets and store them securely on BNB Greenfield. Start exploring the world of NFTs today!

DCellar is a user-friendly option, allowing you to simply navigate to the webpage, connect your wallet, and upload your files. In this explanation, we will focus on the CLI (Command Line Interface) approach, which is more developer friendly.

CLI configuration

Before you begin interacting with Greenfield, you must first configure your CLI through the config file. This will ensure that your settings are properly set up for communication with the Greenfield network.

Clone the Greenfield Github repo and installation of cmd

git clone https://github.com/bnb-chain/greenfield-cmd.git
cd greenfield-cmd
make build
cd build

// Get help for supporting commands and basic command format
./gnfd-cmd -h

Example of config.toml on your Greenfield LI:

rpcAddr = "https://gnfd-testnet-fullnode-tendermint-us.bnbchain.org:443"
chainId = "greenfield_5600-1"
passwordFile = "password.txt"

Establish another folder is a recommended practice. Therefore, we will designate an additional folder and label it as "testnet".

Copy over "config.toml" & "gnfd-cmd" from build to testnet folder. Also create the following text file 1) key.txt and 2) password.txt.


Create the keystore file

In order to utilize the advanced functionalities of the command tool, the following steps must be taken to generate a keystore file:

1️⃣
Export your private key from MetaMask and save it in "key.txt" as plain text.
2️⃣
Set your password, which should be specified in the "passwordFile" field in the configuration file named "password.txt".
3️⃣
Use the "gen-key" command to create a keystore. The "-privKeyFile" flag is used to designate the file path for the private key file created in step 1. The ensuing command can be leveraged to generate a keystore file named key.json:
// create keystore file
gnfd-cmd create-keystore --privKeyFile key.txt key.json
4️⃣
The private key file (key.txt) generated in step 1 can be deleted as it serves no further purpose after the keystore has been created.


Once the keystore file has been generated, subsequent commands will require the addition of "-k keystore-path". Please note that "key.json" is the default keystore file. When running commands with "-k keystore-file", the private key information will be securely retrieved from the keystore.

Create Payment Account and Transfer tBNB(test token) to the payment account

1️⃣
First, create your payment account after your configuration file is ready.
// create a payment account
./gnfd-cmd payment create-account

And then transfer tBNB to your wallet.


// transfer to an account in Greenfield
gnfd-cmd -c config.toml transfer --toAddress 0xF678C3734F0EcDCC56cDE2df2604AC1f8477D55d --amount 12345

You can query your payment account balance by owner address.


// query payments account under owner or a address with optional flag --user
gnfd-cmd -c config.toml ls-payment-account --owner 0x5a64aCD8DC6Ce41d824638419319409246A9b41A

Deposit tBNB to your payment account.


// deposit from owner's account to the payment account
gnfd-cmd -c config.toml payment-deposit --toAddress 0xF678C3734F0EcDCC56cDE2df2604AC1f8477D55d --amount 12345

Create bucket and upload tokenURI metadata file

Now we can create bucket.

// create bucket
./gnfd-cmd bucket create gnfd://jimmy-bucket

// change buckett visibility to public-read
./gnfd-cmd bucket update --visibility=public-read gnfd://jimmy-bucket

// check bucket information
./gnfd-cmd bucket head gnfd://jimmy-bucket

Put your file to the bucket.


./gnfd-cmd object put cool-girl.jpeg gnfd://jimmy-bucket

After you upload your file, it is time to assemble the metadata json file. Here we need to use the view URL of the file you just uploaded.

😁
The view URL format is https://${SP-URL}/view/${bucket-name}/${ObjectName}/

{
   "name": "CoolGirl",
   "description": "A cool girl sitting on a platform and thinking about future .",
   "image": "https://gnfd-testnet-sp-1.nodereal.io/view/jimmy-bucket/cool-girl.jpeg"
}

Upload the metadata json file to the greenfield as well.


./gnfd-cmd -c config.toml  put --visibility public-read ./cool-girl.json  gnfd://bucketname/jimmy-bucket

Then the token URI will be the link of the json file.

Of course you can view all this information through DCellar, and select the bucket and view the details.

👉
Enter the bucket and select the object you want to view, and click the “View Details”.

All the details of the selected object will be displayed.

Mint your NFT with the TokenURI

After you compile your smart contract and deploy to the testnet, you can call the mint function with two parameters to mint the token.

{
"address recipient": "0xf37ef72904d77F17Ca4DEbD1Bb9330e713bE3Df7",
"string tokenURI": "https://gnfd-testnet-sp-1.nodereal.io/view/jimmy-bucket/cool-girl.json"
}

On the BscScan you can view the token tracker to view the NFT you just minted.

Summary

BNB Greenfield is the ideal platform to store and manage your NFT assets and metadata. It's designed specifically for NFT use cases, making it effortless to upload your NFT assets and metadata securely. With a competitive storage pricing structure compared to alternatives like S3, Arweave, and Filecoin, BNB Greenfield is an attractive option for long-term storage. Just ensure your payment account has a sufficient balance to cover storage fees. Experience the convenience, affordability, and security of NFT creation and storage with BNB Greenfield. Sign up today and join the world of NFTs!

About NodeReal

NodeReal is a one-stop blockchain infrastructure and service provider that embraces the high-speed blockchain era and empowers developers by “Make your Web3 Real”. We provide scalable, reliable, and efficient blockchain solutions for everyone, aiming to support the adoption, growth, and long-term success of the Web3 ecosystem.

Join Our Community

Join our community to learn more about NodeReal and stay up to date!

Discord | Twitter| Youtube | LinkedIn


Reference

https://github.com/bnb-chain/greenfield-cmd

https://greenfield.bnbchain.org/docs/guide/getting-started/interact-with-greenfield.html

https://greenfield.bnbchain.org/docs/guide/getting-started/get-test-bnb.html