Create a token with Open Zeppelin Contract Wizard and deploy it on a Testnet

Salah I.
Block Magnates
Published in
5 min readNov 11, 2022

--

Open Zeppelin is a very renown company in the smart-contract industry that provides an open-source framework to build secure smart contract.

This is part of a complete suite of tools helping developers, from building to managing and securing a smart-contract development and deployment.

In this article, I will focus on the contract library, and more esp ecially on one of their tools called the Contract Wizard helping developer to bo otstrap a contract with multiple components and features coming from their own solidity library. We will leverage this tool to create and deploy a simple ERC20 contract on a testnet.

Fig1. Open Zeppelin Contract Wizard

Within this tool, we can create different kind of contract, as ERC20 ERC721, ERC1155 or Governance token.

You just have to select which features you want to enable, and once it is done, you can either :

  • copy it
  • download it and integrate it in a Truffle/Hardhat project
  • open it in Remix to explore the result, maybe add some changes and test it.

In this example, we will open it in Remix by clicking the Open in Remix button.

Fig2. Explore the contract with Remix to get more insight on what is happening and what each features works

What I find really interesting with Remix is that I am able to easily check each of the implemented function to understand what they do. Great stuff when you’re learning !

You can then test it by deploying it first on the Remix VM.
Remix VM is a sandbox blockchain running inside the browser. On each reload, the old blockchain is reseted, and not everything is functionnal in it (for example, block.timestamp is not working)

This completed, you will have access to all the methods your token inherited from the different libraries you added by selecting the features :

Fig3. Deployed token on VM

Then, the next move is to deploy it to a Testnet. This is what we usually do if we want to challenge our contract it in a more realistic environment. Testnets are real network based on the actual blockchain they inherit from, but working with different rules that make mining blocks easier than on a real network. Using a testnet is free and Ether on it does not hold any real value.

To do so, go to the Deploy & Run Transactions tab, select the Injected Provider environment and configure your wallet (depends on you, in my case it is Metamask) to the testnet you want to deploy it (in my case it is on Goerli) :

Fig4. Setting the network environment Injected Provider

To be able to deploy the contract to Goerli you need to do two things :

1. Add the network to your wallet if its not already done (tutorial here)

Fig5. Setting the network to Goerli testnet

2. You will need some fake Ether to pay for the transaction too. You can get them from faucets :

There are many different faucets, and it is possible that at the time I’ll post this article, one of these will become unavailable.

When its done, you will be able to get the contract address either in Remix output, or within Metamask :

Fig6. click on the contract deployment transaction to find the txn hash and then the contract
Fig7. Or do it from the Remix output console

You will land on Etherscan, a block explorer that make Ethereum data accessible to everyone through a very powerful interface.

From this page, you will be able to find your contract address.
Click on it :

Fig8. The page you see if you click on a transaction hash in Etherscan

This will send you to your token contract address.

If you already explored the DeFi space, there’s chances that you already know that some contract can be interacted directly through Etherscan website.
As an example you can check the Uniswap Token contract here, and by going to “Read Contract” or “Write Contract”, you can interact directly with the contract without the need to go to the Uniswap website interface :

Fig9. Uniswap Router contract, different from the one linked above
Fig10. Uniswap web DApp

But let’s go back to our contract now :

Fig11. Unverified contract on Etherscan

As you can see, our contract isn’t really interactable, and it is explained why : the contract must be verified and published.

This doesn’t mean that nobody can interact with the contract. Once the contract is deployed to the Ethereum blockhain, anyone can interact with it as far as he has the right information. And as the data is publicly available, anyone with a good knowledge can access to it.

Verifying a contract is important though, it is a mark of confidence for the users of your contract, as they can easily verify it and see if there is bugs, or worse, if it is a scam.

To verify the contract, just click on Verify and Publish (visible on fig11) :

Fig12. Verify & Publish form

Go back to your Remix page and verify the information to complete the required fields : Compiler version, chosen License, but for the compiler type select Solidity (Single file)

You will land here :

Fig13. Contract Source Code verification form

You may have noticed that your contract is importing other contracts from OpenZeppelin. That means you don’t have a single file contract... So why did you chose Single File option ?

Thanks to Remix plugins, that you will find here :

Fig14. Plugin Manager from Remix interface where you can download useful modules

Click on the icon, search for the “Flattener” plugin and activate it.

When its done, go to the new Icon and click on Flatten contract XXXXXX

Fig15. Flattener Plugin from Remix

This will copy the flattened contract to your clipboard. Then, copy it on Etherscan Contract Source Code Verification form (fig12) , and start the verification process.

If you’ve done everything correctly, the verification will change the contract page of your contract to this !

Fig15. your first verified ERC20 contract
Fig16. Your first verified ERC20 contract on Goerli !

Well done, you’ve just created and deployed your first ERC20 token on Ethereum (testnet) !

--

--