How to Create and Deploy Your Own Token on Base Goerli Testnet 🪙
Tags: web3, blockchain, tutorial, solidity
Published: 2023-03-30 21:18:10

## 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](https://thirdweb.com/). 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](https://media.tenor.com/Hvb4UTQESkUAAAAC/lets-start-building-building.gif)

---

## 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.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gx0k6l1qs8wjptjfi0qt.jpg)

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](https://blog.thirdweb.com/content/images/size/w1000/2023/02/What-is-Base-Blockchain---Layer-2-Network-by-Coinbase.jpg)

**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

![](https://mirror-media.imgix.net/nft/3IibBGTsx411sG_YsEqD4.png)

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](https://nodejs.org/en/) v14 or greater, and the [Metamask](https://metamask.io/download/) 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:

```bash
npx thirdweb@latest create contract
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1680209587961/a1318376-7b3a-4c25-abcd-4d21bd041542.png)

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:-

```bash
npm install @openzeppelin/contracts
```

---

## 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:

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

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:

```solidity
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";
```

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:

```solidity
contract Token is ERC721, ERC721URIStorage, ERC721Burnable, Ownable {
	...
}
```

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:

```solidity
using Counters for Counters.Counter;
Counters.Counter private _tokenIdCounter;
```

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:

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

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:

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

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`
    

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

2.  **tokenURI** - It returns the Token URI for the token
    

```solidity
function tokenURI(uint256 tokenId)
    public
    view
    override(ERC721, ERC721URIStorage)
    returns (string memory)
{
    return super.tokenURI(tokenId);
}
```

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:

```solidity
 // 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);
    }
}
```

---

## 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:

```bash
npx thirdweb@latest deploy
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1680209679328/5b5b8286-d785-42d8-9304-85be2743712f.png)

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](https://thirdweb.com/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'

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1680209721903/94a84424-98e0-4620-bc5b-2c467e18c582.png)

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.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1680209740441/80426183-c4d9-41ab-8cc7-d971ab713742.png)

Now we have added Base Testnet to our networks, we need to get some Testnet ETH to deploy our contract. [Quicknode](https://faucet.quicknode.com/drip) 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.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1680209767841/30866bc7-04a9-477e-a266-8796490aefe1.png)

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.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1680209852896/6c7baa60-4c14-4806-acb3-42fa8c87bfcd.png)

and that's it you have successfully deployed your contract to **Base Goerli Testnet**. 🎉

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1680209897439/50b84640-9204-4827-b7ca-18bba1ce1913.png)

You can see the Deployed Contract on the thirdweb Dashboard: [https://thirdweb.com/base-goerli/0xb4Ee5e8ab99425F48bdf2458249F0B81Be3FFFbF](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:

```json
{
   "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
      }
   ]
}
```

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`](https://ipfs.io/ipfs/bafybeicb6ytxdp3jbedqejdd3ckbuzjv57tb33bk2ldyd7jw5pg3e52yky/metadata.json)


![Unicorn NFT](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qcxouwshowq0puy7k7aj.png)


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

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1680209909425/77d6cefe-8b48-4dc7-a32c-89d1a46da36d.png)

🎉 Congratulations! You've successfully minted your NFT on the Base Goerli Testnet!

🚀 You can also view your transactions on the [Basescan Goerli Explorer](https://goerli.basescan.org/).

---

## 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](https://twitter.com/Envoy_1084). 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](https://www.linkedin.com/in/vedant-chainani/) and [Twitter](https://twitter.com/Envoy_1084) to share our experiences and insights into the ever-evolving world of blockchain technology. 🔗

Thanks for reading, and keep on creating! 🚀