Deploy an ERC-20 on Aurora using Hardhat
Tags: aurora, hardhat, tutorial, solidity
Published: 2022-11-08 16:38:52

[Aurora](https://aurora.dev/) is an EVM-based network that benefits from the security and scalability of NEAR. Technically, Aurora is a shard of NEAR that supports [Solidity](https://soliditylang.org/). There's nothing as simple as deploying an ERC-20 token on Aurora Testnet. 

## Aurora Testnet setup

Go to [https://aurora.dev/start](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](https://aurora.dev/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](https://testnet.rainbowbridge.app/) to transfer some Goerli ETH to Aurora Testnet.

## Hardhat config

1. Clone this repository: [https://github.com/julienbrg/dune-erc20](https://github.com/julienbrg/dune-erc20)
2. Copy the `.env.example` file
3. Rename it `.env`
4. In MetaMask, export the private key of the wallet holding the Aurora Testnet ETH, copy-paste it after the equal sign (line 3)
5. In your terminal (in your root directory):

```bash
npm i
```

## The ERC-20 contract

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

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

You can test this contract with: 

```
npx hardhat test 
```

Then just deploy it to Aurora Testnet:

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

You should get something like this: 

```
ERC-20 deployed at 0x51723295B6E50d94D887Bbc70c1AE0ab1Fa3a469 ✅
```

On [Aurorascan](https://testnet.aurorascan.dev/tx/0x375eaf92f4b4629968e5e3c622a96c00da0d610edf380e5e87d5ea8f98a94e52), your deployment transaction will look like this: 

![Aurorascan tx](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/er6hpx7cknok1sj6lpa6.png)

Congrats, you just deployed a Solidity contract to Aurora Testnet! 🎉

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

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

For info, there's even a frontend available if you want to mint some Dune tokens: [https://dune-aurora.netlify.app/](https://dune-aurora.netlify.app/). It was made using React, [Web3Auth](https://web3auth.io/) and a builder called [Plasmic](https://www.plasmic.app/). The Github repo is [here](https://github.com/julienbrg/my-little-central-bank/tree/dune) (there's a `dune` branch) if you want to have a look.

Now let's deploy to Mainnet... 

## Deploy to Aurora Mainnet

We're going to use a tool called Aurora+. Please head to [https://aurora.plus](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):

![personalized endpoint](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k0ztre8yxynm0l1yv2gm.png)

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.

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, you can use Aurorascan API: 

[https://aurorascan.dev/myapikey](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. 

In the `deploy.ts` file uncomment the lines 15, 16 and 17, and: 

```
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](https://aurorascan.dev/address/0x1692787eF1044d9De9c1b60886891C5b7e33a7C4#code). 

![aurorascan](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7igbuygk5s5o0n45nvkx.png)

And you can also use the [`transfer.ts`](https://github.com/julienbrg/dune-erc20/blob/main/scripts/transfer.ts) script to mint some DUNE:

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

Thanks for your read!

Photo by <a href="https://unsplash.com/@heitmannj?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Henrik Heitmann</a>

---

Feel free to contact me via [Element](https://matrix.to/#/@julienbrg:matrix.org), [Telegram](https://t.me/julienbrg), [Twitter](https://twitter.com/julienbrg), [Discord](https://discord.gg/pfkJpEb4xn), or [LinkedIn](https://www.linkedin.com/in/julienberanger/).