Deploy an ERC-20 to Aurora using Hardhat

Hello world! Aurora is the EVM-based network of NEAR. The transaction fees are low, the average block confirmation time is fast, and it benefits from the security and scalability of NEAR.

Julien Béranger
Aurora Hacks

--

Aurora is an EVM-based network that benefits from the security and scalability of NEAR. Technically, Aurora is a shard of NEAR that supports Solidity. The ERC-20 token standard was first created in 2015. For better and for worse, it’s one of the most used Web3 application so far.

Watch the video tutorial

In this ‘hello world’ tutorial, you will learn how to:

  • Test a Solidity contract
  • Deploy it to Aurora Testnet
  • Deploy it Aurora Mainnet without paying any gas fees
  • Get it verified on Aurorascan

1. Setup

First of all, please make sure you have these installed on your machine:

Once you’ve installed these globally on your machine, you can:

  1. Clone this repository: https://github.com/julienbrg/dune-erc20
  2. In your terminal (in your root directory), install the node modules by typing the following command:
npm i

Aurora Testnet

Go to https://aurora.dev/start, in the Aurora Network section, select the testnet tab and click on Add Network: this will add Aurora Testnet as a new network in your MetaMask wallet.

Head to Aurora Testnet faucet and click on the testnet button. Now you can just click on the Connect to Aurora Testnet button, it will turn into a Request 0.001 ETH from faucet button: just click it to get 0.001 ETH. That will be more than enough to deploy your ERC-20 token contract.

If you need more, you can use the Testnet Rainbow Bridge to transfer some Goerli ETH to Aurora Testnet.

Back to the root directory:

  1. Copy the .env.example file
  2. Rename it .env
  3. In MetaMask, export the private key of the wallet holding the Aurora Testnet ETH, copy-paste it after the equal sign (line 3)

Aurora Mainnet

We’re going to use a tool called Aurora+. Please head to https://aurora.plus, and sign up to get your 50 free tx per months. Once you’ve done that, you have your personalized RPC endpoint URL that is waiting for you (top-right menu):

You can copy-paste that URL into your .env file (line 1).

Then you want to export your wallet’s private key into your .env file as well.

Aurorascan API

Something is missing in that .env file and it's the Aurorascan API key. You're going to need it to make it easy for everyone to read the source code of your contract:

https://aurorascan.dev/myapikey

You can sign up there, click on API-key in the left menu, then click on add to create an API key. Copy-paste it in the .env file.

2. Test

This is a very basic ERC-20 token that’s using open Zeppelin Solidity contracts library. There’s only one function: the mint() function. The visibility is set to public, meaning that anyone can call this function and mint as many units as he/she wants (we're in an 'open bar' mode, so to speak):

// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.4;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract Dune is ERC20 {
constructor() ERC20("Dune", "DUNE") {}

function mint(address to, uint256 amount) public {
_mint(to, amount);
}
}

So you will first deploy the contract and then use it by calling the mint() function and transfer a handful of DUNE token to yourself.

Before we deploy, we want to run the test file called Dune.ts. that’s in the test folder. Here’s the command you want to use:

npx hardhat test

You will see that:

  • The Solidity contract compilation worked well
  • It was properly deployed to a local network
  • People can interact with it

3. Deploy to Aurora Testnet

The deployment script is in the scriptsfolder. To run it and deploy your contract, just type this command in your terminal:

npx hardhat run scripts/deploy.ts --network aurora_testnet

You should get something like this:

ERC-20 deployed at 0x51723295B6E50d94D887Bbc70c1AE0ab1Fa3a469 ✅

If you want to see what happened onchain, you can copy the contract address and paste in the Testnet Explorer search bar. If you click on the transaction hash, you will see something like this:

That’s it, you just deployed a Solidity contract to Aurora Testnet! 🎉

To mint and transfer a handful of DUNE to yourself (or to a friend), you can use this command:

npx hardhat run scripts/transfer.ts --network aurora_testnet

If you like, you can even add this token to you MetaMask wallet so you can verify that it’s there and transfer some. In MetaMask, click on the ‘Assets’ tab, and then on ‘Import token’. There you can paste your contract address, the other fields will auto-complete, click on the ‘Add custom token’ and the DUNE token will appear with a balance of 1 unit.

4. Deploy to Aurora Mainnet

The following command will execute the deploy.ts file located in the script folder:

npx hardhat run scripts/deploy.ts --network aurora_mainnet

Congrats! 🎉

Your ERC-20 is deployed to Aurora Mainnet, you paid nothing, the source code is available for everyone to verify what's going on, and people can even trigger the mint function directly from Aurorascan.

And you can also use the transfer.ts script to mint some DUNE:

npx hardhat run scripts/transfer.ts --network aurora_mainnet

Contract verification

This very contract was already verified so any other similar contract will be verified too. A contract is ‘verified’ when the source code (in Solidity) match byte code that’s on the blockchain.

In this project, the Etherscan verification plugin is in placeIn the deploy.ts file uncomment the lines 15, 16 and 17, and:

npx hardhat run scripts/deploy.ts --network aurora_mainnet

Congrats! 🎉

For info, there’s even a frontend available if you want to mint some Dune tokens: https://dune-aurora.netlify.app/. It was made using React, Web3Auth and a builder called Plasmic. The Github repo is here (there’s a dune branch) if you want to have a look.

The DUNE token you just deployed and used benefits from the security of the Aurora network. Also, we’re using the Open Zeppelin set of contracts that have been audited many times. For info, the Open Zeppelin Wizard is a very handy tool to edit your own smart contracts.

Thanks for your read!

Photo by Henrik Heitmann

Feel free to contact me via Element, Telegram, Twitter, Discord, or LinkedIn.

--

--

Julien Béranger
Aurora Hacks

DevRel at Arthera | Member of the W3HC | Co-founder of Āto | Founder of Strat | Volunteer at Emmaüs Connect