DEV Community

Cover image for How to Create and Deploy Your Own Token on Base Goerli Testnet πŸͺ™
Vedant Chainani
Vedant Chainani

Posted on • Updated on

How to Create and Deploy Your Own Token on Base Goerli Testnet πŸͺ™

What is this article about?

In this article, we will explore the technical process of deploying an ERC-721 token on the Base Blockchain using thirdweb. With this process, you can mint tokens and transfer them to other users. We will also cover the technical aspects of thirdweb and provide detailed instructions on deploying your tokens on more than 700 EVM-compatible blockchains πŸš€

Let's start building


What is an ERC-721 Token

ERC-721 tokens, also known as non-fungible tokens (NFTs), are a unique type of token standard on the Ethereum blockchain that allows for the creation and ownership of completely unique digital assets.

Today, the most common use case for ERC-721 NFTs is for digital art. Users buy these NFTs for a number of reasons, including supporting artists, investing long-term in hopes that the price will go up, quickly flipping/trading NFTs for a profit, or simply because they like the artwork.


What is Base Blockchain

Base Blockchain

Base Blockchain is a new Ethereum-based blockchain developed by Coinbase. As a Layer 2 (L2) network, it provides a secure, low-cost, and developer-friendly platform for building decentralized applications (dApps).

One of the primary goals of Base is to address the scalability issues that plague the Ethereum mainnet. With high gas fees and slow transaction speeds, the mainnet can be a challenging environment for dApp developers to work with. Base is designed to alleviate these problems and offer a more efficient and effective solution.


What is thirdweb

Thirdweb is a powerful development framework designed to help you incorporate web3 functionality into your applications. With Thirdweb, you can easily build and deploy decentralized applications (DApps) that interact with the blockchain, enabling you to leverage the benefits of a decentralized network.

At its core, Thirdweb provides developers with a variety of tools and workflows to streamline the development process. These include contracts that serve as the foundation for your web3 functionality, software development kits (SDKs) that let you build blockchain applications and dashboards that enable you to manage your contract.


Prerequisites

Before you start with the tutorial make sure you haveΒ Node.jsΒ v14 or greater, and theΒ MetamaskΒ browser extension installed on your machine.


Setting up the project

Open up your terminal and navigate to the location where you want to create your project directory. Next, we will use the thirdweb Contract Kit to create a new Smart Contract Project. To get started, create a new Solidity project with the following command:

npx thirdweb@latest create contract
Enter fullscreen mode Exit fullscreen mode

After creating just fill in the basic things like the name of the project and the contract. In the Starter contract just start with an Empty Contract. We will be using OpenZeppelin Smart Contracts to build our NFT Contract. To install simply run the following command:-

npm install @openzeppelin/contracts
Enter fullscreen mode Exit fullscreen mode

Creating Token

Firstly Navigate to contracts/Token.sol file and remove any existing code, we will be building our contract from scratch.

At the top of the file, add the following SPDX license identifier and Solidity version declaration:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
Enter fullscreen mode Exit fullscreen mode

The SPDX license identifier specifies the license under which your code is distributed, while the Solidity version declaration specifies which version of Solidity you're using.

Next, import the necessary contracts from the OpenZeppelin library:

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Burnable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
Enter fullscreen mode Exit fullscreen mode

Here is the Overview of all the Files:

  • ERC721.sol - Core Implementation on ERC721 Base Contract

  • ERC721URIStorage.sol - A more Complex and expensive way of storing metadata.

  • ERC721Burnable.sol - A way in which token holders can burn their tokens(transfer to Zero Address)

  • Ownable.sol - Method in which an Owner can be assigned to an address, which ensures checks.

  • Counters.sol - A simple way to get a counter that can only be incremented, decremented or reset.

Define the contract itself, called Token, and have it inherit from the imported contracts:

contract Token is ERC721, ERC721URIStorage, ERC721Burnable, Ownable {
    ...
}
Enter fullscreen mode Exit fullscreen mode

This line of code specifies that the Token contract is inherited from the ERC721, ERC721URIStorage, ERC721Burnable, and Ownable contracts.

Define a variable using Counters from the OpenZeppelin library:

using Counters for Counters.Counter;
Counters.Counter private _tokenIdCounter;
Enter fullscreen mode Exit fullscreen mode

This will allow us to keep track of the token IDs for each new token we mint.

In the constructor, specify the name and symbol for your token:

constructor() ERC721("Token", "TKN") {}
Enter fullscreen mode Exit fullscreen mode

This line of code sets the name of your token to "Token" and the symbol to "TKN". You can customize these to fit your specific needs.

Now lets define a function called safeMint that allows the owner of the contract to mint new tokens:

function safeMint(address to, string memory uri) public {
    uint256 tokenId = _tokenIdCounter.current();
    _tokenIdCounter.increment();
    _safeMint(to, tokenId);
    _setTokenURI(tokenId, uri);
}
Enter fullscreen mode Exit fullscreen mode

This function takes two arguments: the address that the token will be minted to (to) and the URI for the token's metadata (URI). The function then increments the current token ID counter, mints a new token to the specified address, and sets the token's metadata URI.

Override two functions required by Solidity:

  1. burn - This function allows to burn the tokens, i.e., send to Zero Address
function _burn(uint256 tokenId) internal override(ERC721, ERC721URIStorage) {
    super._burn(tokenId);
}
Enter fullscreen mode Exit fullscreen mode
  1. tokenURI - It returns the Token URI for the token
function tokenURI(uint256 tokenId)
    public
    view
    override(ERC721, ERC721URIStorage)
    returns (string memory)
{
    return super.tokenURI(tokenId);
}
Enter fullscreen mode Exit fullscreen mode

These functions ensure that the Token contract adheres to the ERC721 and ERC721URIStorage standards.

And that's it! We have completed our smart contract.

Full Code:

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

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Burnable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Counters.sol";

contract Token is ERC721, ERC721URIStorage, ERC721Burnable, Ownable {
    using Counters for Counters.Counter;

    Counters.Counter private _tokenIdCounter;

    constructor() ERC721("Token", "TKN") {}

    function safeMint(address to, string memory uri) public {
        uint256 tokenId = _tokenIdCounter.current();
        _tokenIdCounter.increment();
        _safeMint(to, tokenId);
        _setTokenURI(tokenId, uri);
    }

    // The following functions are overrides required by Solidity.

    function _burn(
        uint256 tokenId
    ) internal override(ERC721, ERC721URIStorage) {
        super._burn(tokenId);
    }

    function tokenURI(
        uint256 tokenId
    ) public view override(ERC721, ERC721URIStorage) returns (string memory) {
        return super.tokenURI(tokenId);
    }
}
Enter fullscreen mode Exit fullscreen mode

Deploying the Smart Contract

Now that the contract is done, let's deploy it and mint some NFTs! πŸš€

Run the following command to deploy your smart contract using the dashboard:

npx thirdweb@latest deploy
Enter fullscreen mode Exit fullscreen mode

Now, what thirdweb does is firstly compiles your contract and upload your contract to IPFS. After successful compilation and Upload you will be given a link at last from which you can deploy your contract.

Before Deploying Our Contract, we need to add Base Blockchain Testnet to our Networks. to do that go to thirdweb dashboard and on the top right side of the screen click the Configure Networks gear icon

then in the add network section search for 'Base Goerli Testnet', select that network and then click on 'Add Network'

Now go back to the dashboard and click on the profile icon on the top right of the screen and switch your network. Under the Testnet Section, select the Base Goerli Testnet and click on that. you will be prompted with a Metamask popup where you will be asked to add Base Goerli Testnet to your networks. click on approve.

Now we have added Base Testnet to our networks, we need to get some Testnet ETH to deploy our contract. Quicknode is a multichain faucet that we will use to get some test net eth, go to the Quicknode website and connect your Metamask wallet. now select Base Blockchain with Testnet Config and then click on continue.

Now complete the remaining steps and you will receive 0.05 Testnet Ether in your account.

Now we are ready to deploy our NFT Contract. Go to the link that you got after deploying the contract, and select the 'Base Goerli Testnet (ETH)' under the networks section.

After that click on the blue deploy button. you will be needed to approve two transactions, the first will be for deploying your contract and the second for adding your contract to the thirdweb's dashboard.

and that's it you have successfully deployed your contract to Base Goerli Testnet. πŸŽ‰

You can see the Deployed Contract on the thirdweb Dashboard: https://thirdweb.com/base-goerli/0xb4Ee5e8ab99425F48bdf2458249F0B81Be3FFFbF


Mint an NFT

Now that we've successfully deployed our contract, it's time to mint an NFT!

To do this, let's head over to the Explorer section under the sidebar. Here, you'll find all the read-and-write methods for your contract. We'll be using the safemint function located under the write methods.

The safeMint function requires two arguments: the address to which the NFT will be minted and the metadata URI. The metadata is a JSON file containing the name, image, and attributes of your NFT. It should look something like this:

{
   "name":"Unicorn #2",
   "description":"black unicorn, a rare and mystical creature. The background should be a moonlit night, with stars twinkling in the sky and a misty forest in the distance",
   "image":"ipfs://bafybeieusozzkp2mt742urqgypwrdyv65uv2jidyspqq5j4lsuipzs2hk4/image.jpg",
   "attributes":[
      {
         "display_type":"date",
         "trait_type":"Date Created",
         "value":1679134683
      }
   ]
}
Enter fullscreen mode Exit fullscreen mode

Luckily, I've already uploaded a metadata file for a Unicorn NFT, which you can use! Simply populate the fields with your wallet address and the URI:

URI - https://ipfs.io/ipfs/bafybeicb6ytxdp3jbedqejdd3ckbuzjv57tb33bk2ldyd7jw5pg3e52yky/metadata.json

Unicorn NFT

Once you've filled in the fields, hit that execute button and approve the transaction in Metamask.

πŸŽ‰ Congratulations! You've successfully minted your NFT on the Base Goerli Testnet!

πŸš€ You can also view your transactions on the Basescan Goerli Explorer.


What’s Next?

Congratulations on creating and deploying your own token on the blockchain! πŸŽ‰

But, of course, the journey doesn't stop here. Now that you have a basic understanding of how to create and deploy a token, there are plenty of ways to take your project to the next level. Here are a few ideas:

  1. Expand your token's functionality: You can explore more advanced Solidity programming concepts and add more features to your token, such as staking, voting, or yield farming.

  2. Explore different blockchain platforms: While we focused on the Ethereum blockchain in this tutorial, there are many other blockchain platforms out there, each with its unique features and use cases. You can explore platforms like Polkadot, Binance Smart Chain, or Solana to see what they have to offer.

  3. Integrate your token into a real-world application: With your token deployed, you can integrate it into a real-world application, such as a decentralized marketplace or a gaming platform.

  4. Connect with the blockchain community: Finally, don't forget to connect with other developers and enthusiasts in the blockchain community! There are many forums, Discord servers, and social media groups where you can ask questions, share ideas, and collaborate on new projects.

The possibilities are endless, and we can't wait to see what you'll create next!


Conclusion

I hope you found this article on creating and deploying a token on the blockchain informative and helpful!

This article is about the Implementation Deep Dive contest by Alchemy University Techwriters Guild. It's an exciting opportunity for tech writers to showcase their skills by explaining complex implementation processes. By participating, writers can gain exposure to new technologies and methodologies while honing their technical writing skills. Join Alchemy University to participate in amazing contests and take your technical writing skills to the next level!

Of course, I understand that this process can be challenging at times, and you may encounter some roadblocks along the way. But don't worry! If you run into any issues or have any questions, feel free to drop a comment or send me a DM on Twitter. I'm always happy to help out a fellow blockchain enthusiast. πŸ™Œ

And if you enjoyed this article and want to see more like it, be sure to follow me for regular updates and engaging content. Let's stay connected on LinkedIn and Twitter to share our experiences and insights into the ever-evolving world of blockchain technology. πŸ”—

Thanks for reading, and keep on creating! πŸš€

Top comments (1)

Collapse
 
tarifa995 profile image
Tarifa | Areon

🚨 Attention developers worldwide! Areon Network has just launched a game-changing Hackathon! 🌐 Seize the opportunity to win big with the $500,000 prize pool. Register now at hackathon.areon.network and let the coding marathon begin! πŸπŸ’° #CodeForSuccess #AreonHackathon