From Ethereum to Aurora With Infura

johnjvester

John Vester

Posted on July 12, 2022

From Ethereum to Aurora With Infura

Article Image

The promise of Web3 is enticing.

Freedom from tech giants and giving power back to creators are lofty but worthy goals. Ethereum is the world’s largest and most-used public blockchain and has supported the growth of Web3 since it was launched in 2015. Being the first and most popular doesn’t come without challenges, especially when network demand is high. Slow and expensive transactions don’t exactly make for the best developer experience and the rise of L2s to ensure Ethereum scalability continues to be surprising. For developers that want to try other layer one chains, there are alternatives.

The NEAR protocol is an innovative blockchain ecosystem. Their network is lightning fast with low transaction costs, while its bridges are helping create the multi-chain future we’ve all been hoping for. But most Web3 developers get their start on Ethereum and Solidity. Since NEAR primarily uses Rust for its smart contracts, this could be a tough transition for most.

Thankfully, NEAR recognizes this challenge and has since released Aurora, their own version of Ethereum compatibility on top of their network. This allows Ethereum devs to easily start building on NEAR or transfer existing projects without changing their Solidity code. And even better, the node provider, Infura, offers Aurora compatibility through their RPC URLs.

In this article, we will explore the NEAR protocol, its Aurora environment, and why an Ethereum dev would want to make the switch. Then we’ll look at deploying a simple smart contract onto Aurora using an Infura RPC URL to see just how easy it is to get started.

What Is NEAR?

NEAR is a layer-one blockchain network and one of the most exciting new protocols to enter the Web3 space. They deliver an excellent user and developer experience by offering extremely fast and cheap transactions. Instead of using complex, hard-to-read wallet addresses, NEAR utilizes human-readable addresses, making interaction with the network much more user-friendly. Additionally, their innovative Nightshade Sharding mechanisms enable scalability on levels that no other blockchain can currently compete with.

With its Rainbow Bridge and Octopus Network, NEAR is interoperable with other blockchain environments, including Bitcoin, Ethereum, Polkadot, and Cosmos. Meanwhile, things like a Proof-of-Stake consensus mechanism, focus on green projects, and contributions to CO2 compensation projects in developing countries have led to the NEAR protocol being awarded the Climate Neutral Product Label from South Pole. In addition, their free education platform ensures that anyone seeking to build on NEAR has the available resources. Overall, NEAR is a very forward-thinking, Earth-conscious ecosystem attracting many participants of like mind.

What Is Aurora?

Aurora is a protocol similar in nature to an Ethereum rollup but for the NEAR ecosystem. It is an Ethereum Virtual Machine (EVM) deployed as a smart contract, which provides an Ethereum-like developer experience on top of the NEAR protocol. The EVM compatibility ensures that any project built on Ethereum ports easily to Aurora without having to change a single line of code.

Since the Aurora implementation is a smart contract, it receives the same benefits as working with the NEAR L1 protocol. Those perks include significantly higher transaction throughput, up to 1000x lower transaction fees, faster transaction finality, and horizontal EVM scaling through NEAR’s Nightshade Sharding mechanisms, among other upsides. Aurora also maintains NEAR’s interoperable nature through the Rainbow Bridge, which facilitates the permissionless transfer of tokens and data between Aurora, NEAR, and Ethereum. At its core, Aurora addresses the challenges that the Ethereum mainnet faces while providing Ethereum developers and users a more effortless onboarding experience to the NEAR ecosystem.

Why Should an Ethereum Dev Start Building on Aurora?

As the introduction mentions, Rust is the primary coding language for NEAR smart contracts. Rust is a notoriously difficult language to learn, and most developers get their start in Web3 by coding Ethereum smart contracts in either the Solidity or Vyper languages. Aurora makes it easier for devs to build on NEAR by providing an EVM environment compatible with both Solidity and Vyper. But why should developers leave Ethereum?

The beautiful thing about Aurora is that devs don’t actually have to leave the Ethereum network to build on NEAR. Anything that runs on Ethereum transfers effortlessly to NEAR through the Rainbow Bridge. So devs can deploy to both networks simultaneously. Also, the base currency on Aurora is ETH, so acquiring an additional network’s tokens to deploy and interact with smart contracts is unnecessary.

Additionally, all the tools an Ethereum developer already knows work out of the box on Aurora. For example, Truffle is still compatible for making smart contract projects, while MetaMask can handle all transactions. Now that Infura offers compatibility with Aurora, devs can build projects with more observability and better security using custom RPC URLs.

Let’s Build!

For the project portion of this article, we will create a simple ERC-20 contract with Truffle, add the Aurora Testnet to MetaMask using our own Infura RPC URL, deploy to the Aurora Testnet with the Truffle Dashboard, verify deployment on the Aurora Testnet block explorer, and then transfer some of our ERC-20 tokens to another wallet.

...

What You’ll Learn

  • How to set up Aurora on MetaMask with an Infura RPC URL
  • How to use Truffle Dashboard to deploy an ERC-20 contract to the Aurora Testnet
  • How to view a transaction on the Aurora Testnet block explorer

What You’ll Need

Additional Resources

...

Step 1 - Set Up MetaMask

Before we can deploy anything, we need to set up the channels to do so. For that, we will need a MetaMask wallet extension on our browser and an Infura project ID. So let’s start with Infura.

1.A - Infura Project ID

Head to infura.io and either sign up for an account or log in. Next, create a new project using the button in the top-right corner of the screen. For the Product, choose Ethereum, and then give your project a name:

New Infura Project

With our new project created, all we need from Infura now is our RPC URL. This is in the General Settings for our project under the Keys section. Switch the Endpoints dropdown to Aurora Testnet and copy the URL.

Project Settings

Now that we have our RPC URL, we need someplace to use it! Here is where MetaMask comes in.

1.B - Configure MetaMask

Head over to metamask.io and download the extension for your particular browser. Once installed, open the extension, and we’ll add the Aurora Testnet.

First, select the Network dropdown menu and press the Add Network button. This will open a window where we can input the correct information to add the Aurora Network to our MetaMask wallet. Fill in the form with the following information:

Let’s take a second to break that down. First, for the network name, we added Infura to the end to signify that we are using an Infura RPC URL instead of the publicly available Aurora Testnet URL (https://testnet.aurora.dev/). This is apparent in the next bullet point where we pasted our RPC URL. This URL will give us a few more options to deploy and secure access to our projects.. Next, the Chain ID is necessary for signing transactions, and this number specifies the Aurora Testnet. For the currency symbol, the base currency for Aurora is Ether, rather than NEAR’s native token. And finally, we input the Aurora Testnet block explorer URL so we can easily view our transactions as they occur.

The last step to configure MetaMask is to ensure we can use the advanced gas controls. Navigate to Settings -> Advanced and toggle the Advanced gas controls to “ON” if it’s not already. This will allow us to set the necessary gas limit when deploying our smart contract.

1.C - Aurora Testnet ETH

The final task in this step is to get some Aurora Testnet ETH so we can deploy our contract. So, head to the Aurora Testnet Faucet, press the Testnet button under the title to switch networks, connect your wallet, and request some Testnet ETH.

Auroro Testnet ETH

Switch to the Aurora Testnet in MetaMask to view your newly acquired ETH:

MetaMask View

Now that we’ve got everything set up to get our contract onto the Aurora Testnet, let’s build the project!

Step 2 - Build The Project

2.A - Install Truffle

To build and deploy our project, we will use Truffle, as the new version comes with a super handy tool called the Truffle Dashboard. This tool allows us to deploy smart contracts without exposing our wallet private keys or mnemonic phrases. With NPM installed, run the following command in your terminal:

npm install -g truffle 
Enter fullscreen mode Exit fullscreen mode

Next, we’ll create and initialize a new Truffle project:

mkdir AuroraTest && cd AuroraTest
truffle init
Enter fullscreen mode Exit fullscreen mode

This creates a basic starter project with a proper file structure we can build on to suit our needs.

Since we will be using OpenZeppelin’s ERC-20 contract to create our token, we need to install one last dependency:

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

Next, open up your favorite code editor, and let’s start building!

2.B - Configure the Truffle Dashboard

To connect Truffle to the dashboard for deployment, we need to add it as a network option. Open up the truffle-config.js file and add the Truffle Dashboard inside the networks object. Aside from all the commented out boilerplate, our object should now look like this:

networks: {
  dashboard: {
    port: 24012,
  }
}
Enter fullscreen mode Exit fullscreen mode

The Truffle Dashboard runs on port 24012 by default, but we can change this if we wish. We would just need to specify the port when we run the dashboard.

While we are still in the truffle-config.js file, scroll down to compilers and double-check which version Truffle is using. This is the version number we will specify in our smart contract. Mine is 0.8.13.

2.C - The Smart Contract

Next up is the smart contract. In the contracts folder, we can delete the migrations contract that’s already in there and create a new file called AuroraToken.sol. Our ERC-20 token code will look like this:

// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.13;

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

contract AuroraToken is ERC20 {
    constructor (string memory name, string memory symbol) ERC20(name, symbol){
        // Mint 1000 tokens to msg.sender
        _mint(msg.sender, 1000 * 10 ** uint(decimals()));
    }
}
Enter fullscreen mode Exit fullscreen mode

2.D - The Deployment Code

The next step is to create the JavaScript code we will use to deploy our file to the Aurora Testnet. Under the migrations folder, we will alter the contents of 1_initial_migration.js so it looks like this:

const AuroraToken = artifacts.require("AuroraToken");

module.exports = function (deployer) {
  deployer.deploy(AuroraToken, 'AToken', 'ATKN');
};
Enter fullscreen mode Exit fullscreen mode

Note: AToken and ATKN are the token name and symbol, respectively. You can set these to whatever you wish.

Now we are all set to deploy!

Step 3 - Deploying the Smart Contract

We now have everything we need to deploy our smart contract to the Aurora Testnet. The first thing we need to do is start up the Truffle Dashboard.

3.A - Set Up the Truffle Dashboard

In a new terminal window, run the following command:

truffle dashboard
Enter fullscreen mode Exit fullscreen mode

This should cause a new window to pop up, but in case it doesn’t, navigate to localhost:24012 in your browser.

Connect Wallet

Click on the Connect Wallet button to connect your MetaMask wallet to the Truffle Dashboard. Once connected, it will ask us if we wish to connect to our wallet’s currently assigned network. Here, we’ll switch to the Aurora Testnet if not connected to it already.

Connect Wallet Testnet

Now that we have connected our MetaMask wallet to the Aurora Testnet via the Truffle Dashboard, all incoming requests will get routed from Truffle to the dashboard. So let’s put it to work!

3.B - Deploy the Smart Contract

Back in our original terminal window, navigate to the root folder of the project and run the command to deploy our smart contract:

truffle migrate --network dashboard
Enter fullscreen mode Exit fullscreen mode

Truffle Migrate

This will send an “Incoming Request” to the Truffle Dashboard.

Incoming Request

After pressing the Process button, MetaMask should pop up with the transaction we need to sign. First, however, we need to adjust the gas limit. Click on the Edit link, and select Edit suggested gas fee to input a Gas Limit and Gas Price. We’ll set these to 672190 and 0.00001, respectively.

Note: The Gas Limit value comes from running the migrate command and checking the Gas sent value in the terminal response. If your deployment fails because it ran out of gas, check this value and adjust MetaMask accordingly. As for the Gas Price, this number is arbitrary since you are deploying to a testnet. Your transaction will get processed regardless of the price, so you can set this to any number you can afford. If deploying to Aurora mainnet, you will need to set this price to something competitive for your transaction to be processed.

Edit Request

Request

After saving these new values, click the Confirm button to continue with the transaction. After a few seconds, we should see a successful response in our terminal, and MetaMask should display a “transaction approved” message. Our contract now exists on the Aurora Testnet!

Take note of the contract address printed in the terminal. We will use this to verify our contract on the block explorer and import our tokens to our wallet.

Contract Address

Step 4 - Verify Successful Deployment

Now let’s just make sure everything worked properly. We’ll first check our transaction on the Aurora Testnet block explorer and then import our new tokens to our MetaMask.

4.A - Aurora Testnet Block Explorer

For this step, we can either follow the “transaction approved” message from MetaMask (since we configured the block explorer URL when setting up the network connection) or head to https://testnet.aurorascan.dev/ and enter the contract address from our console.

Transaction Report

Excellent! We have confirmation that our smart contract exists on the Aurora Testnet. Now let’s import our new tokens to MetaMask.

4.B - Importing Tokens to MetaMask

MetaMask doesn’t automatically detect our new tokens, so we have to import them ourselves. Open up the wallet, select Assets, and then Import tokens.

Don't See Tokens?

Paste the contract address we received in our terminal response, and the other fields should auto-populate.

Contract Address

ATKN Value

Awesome! Now that our tokens are visible in our MetaMask wallet, we can send them to another address.

Step 5 - Sending the Tokens

So all we need to do to send tokens to another address is input the address we wish to send them to! If we don’t have a specific address, we can easily create a new account in our MetaMask wallet and send them there. Just go to My Accounts and create a new one.

On the MetaMask dashboard, click on the Send button and either paste in an address or choose Transfer between my accounts.

Next, select our ATKN asset and input an amount to send.

Send 1

After a few seconds, we should receive another successful transaction message. Again, we can follow this message or check our contract page on the block explorer to prove the transfer was successful.

Transaction Report #2

If the ATKNs were sent to an address we control, we could check the new balance in our wallet. Then, we just need to import the tokens again using the same method as before. After pasting in the contract address and importing the asset, we now have a visible balance in our wallet. Nice!

Validation

Additionally, we can check our Infura project and view the request activity.

Infura Project Activity

Conclusion

The Aurora Protocol is a network deployed as a smart contract that exists on the NEAR blockchain. It is an EVM equivalent experience that inherits all of the benefits of NEAR while providing an easy onboarding experience for devs and users alike. Transactions are faster and cheaper, and projects are significantly more scalable.

In this article, you learned how to deploy and interact with a smart contract on the Aurora Testnet. You created a custom RPC URL connection in MetaMask using Infura to include additional observability and security options to your project, launched your own ERC-20 token using the Truffle Dashboard, and transferred some tokens to another address.

Hopefully, this experience has shown you how easy it is to transfer your existing Solidity and Ethereum skills to the NEAR network with Aurora. Check out the NEAR Education Platform and the Aurora Documentation to learn more about this protocol.

Have a really great day!

💖 💪 🙅 🚩
johnjvester
John Vester

Posted on July 12, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related