Home Tutorials How To Create And Deploy An NFT Smart Contract

How To Create And Deploy An NFT Smart Contract

This article will show you how to accomplish it in the most straightforward manner imaginable, so you’ll be up and running in no time. We’ll use OpenZeppelin ERC721 smart contracts, which are the gold standard in the smart contract world.

There are other tools for deploying smart contracts, but for the sake of this tutorial, we’ll utilize the web3 CLI tool because it’s the quickest and most straightforward.

How To Create And Deploy An NFT Smart Contract

Set Up Your Environment

The next steps must only be once, after which you can deploy and interact as much as you like without having to repeat them.

  • Install the CLI application
  • This one-liner will install the utility and allow you to use it immediately. If you’re concerned about what install. sh is doing, you can read the source.
  •  curl -LSs Here

Configure the network

We’ll simply need to spend a couple of pennies for GoChain, and it’ll be fully compatible with Ethereum.

So we can use it just like Ethereum. If you’d like, you can edit the line below to point to Ethereum and pay the extra amount.

  • export WEB3_NETWORK=gochain
  • # for ethereum: export WEB3_NETWORK=ethereum

Obtain / Add Gas For these transactions, you’ll need to utilize an account that has some gas, or establish a new one and send gas to it. On GoChain, this will be $GO, while on Ethereum, it will be $ETH.

Run the following command to establish a new account:

web3 account creates this is what will print.

  • Private key: 0xABC123
  • Public address: 0xXYZ456

To the “Public address,” send some $GO. If you need some $GO to get started, click here to see where to get some.

  • Copy the “Private key” (or use an existing one if you choose) and run the following command:

WEB3 PRIVATE KEY=0xABC123 export

  • Keep a copy of this private key in a secure place so you can use it again. Let’s get this party started!
  • Now that we’ve got our network up and running, as well as our private key filled with gas, we can start having some fun.

Putting Together the Contract

  • Code generators for standard contracts like ERC20 and ERC721  into the web3 CLI.

Just run:

  • This will create a file called KATS.sol, which is your new NFT contract’s solidity program.
  • When someone queries the NFT information, the base-uri argument should point to a server that you control.
  • Below, we’ll go over metadata and image/video files.

Activate the Contract

It’s only a matter of compiling and deploying it from here. This is also made simple using the web3 CLI:

  • web3 contract build KATS.sol
  • web3 contract deploy KATS.bin

Your new contract address will print as a result of this action. You’ve completed the deployment of an NFT contract! You may have the 10 best NFT collectors Discord server that will help further.

NFTs in mint condition

Now that the contract has, all we have to do is create new ones. Let’s start by setting the contract address as an environment variable so that the rest of the commands can use it:

export WEB3 ADDRESS=0xCONTRACT ADDRESS

  • When minting, you’ll need to supply the address of the person who will be the owner of this new NFT:

—wait —abi web3 contract call —gas-limit KATS.abi —function mint 0xABC 2000000

  • This function creates a completely new NFT and assigns it to 0xABC. The new OpenZeppelin ERC721 presets feature an auto-incrementing ID, so you’ll see the updated token ID in the output.

LEAVE A REPLY

Please enter your comment!
Please enter your name here