NEAR Documentation
  • Concepts
  • Develop
  • Tools
  • Tutorials
  • Community
  • Tokens
  • Stake
  • Integrate
  • GitHub

›EVM

Basics

  • Getting Started
  • Create Account
  • Hackathon Guide

Front-end

  • Introduction
  • API Library
  • RPC Endpoints

Smart Contracts

  • Overview
  • AssemblyScript

    • Introduction
    • AS SDK

    Rust

    • Introduction
    • Rust SDK

Running A Node

  • Running a node
  • Running a node (Windows)

NEAR <> ETH

    EVM

    • Network Status
    • Simple EVM Script
    • Truffle
    • Web3 Provider
    • Proxy RPC Server
    • Local Setup
    • Testing Contracts

    Examples

    • Pet Shop
Edit

Testing EVM contracts

Contents:

  1. Test using the NEAR Web3 Provider.
  2. Test by pointing to an Ethereum RPC Proxy address.

NEAR Web3 Provider

At the moment, running tests via NEAR Web3 Provider requires an extra step compared to the NEAR examples developers may be familiar with at:

https://near.dev

We'll need to use our betanet account to:

  • Run tests that require only one account
  • Create new test accounts before running tests that require multiple accounts. Typically, these tests will have accounts interacting with one another, like sending fungible tokens back and forth, for instance.

The first step is to get your account to save a key pair on your local machine. So far the betanet account you created with NEAR Wallet has key pairs living in the browser. We'll want to store a key pair as an unencrypted file in your computer's home directory. (Specifically ~/.near-credentials.)

To create a local key pair, use the following NEAR CLI command and follow the instructions:

near login

The test file for NEAR Pet Shop is simple and doesn't require the creation of more accounts. Use the command below:

NEAR_MASTER_ACCOUNT=you.betanet truffle test --network near_betanet

NEAR CLI knows to look in the directory where the key pair file was saved after logging in.

An example of a test requiring multiple accounts is this test file from Balancer. Before running a test like this, we'll use the third NEAR CLI command mentioned earlier:

NEAR_ENV=betanet near evm-dev-init mike.betanet 3

This will create 3 subaccounts under mike.betanet. (It will use timestamps, for instance 1608085465606.mike.betanet, 1608085468832.mike.betanet, etc.) If the 3 part of the command was omitted, it would use the default of 5. After creating the necessary number of accounts, run the test with the same command (…truffle test…) from a moment ago.

Proxy RPC server

Testing can also be done by pointing to a local proxy RPC server. To demonstrate this, we can run the Balancer Core repository (for https://balancer.finance) and a local proxy RPC.

  1. Follow the directions in the README for the proxy RPC to get a local server running.
  2. Clone the balancer-core repository, following directions according to the README.

Then simply run:

npm run test

The above command is the same as running truffle test if your system has Truffle installed globally.

Truffle's default network points to localhost at the port 8545 which is the same as tools like Ganache and the proxy server covered here.

Last updated on 2/10/2021 by Josh
← Local SetupPet Shop →
  • Wallet
  • Explorer
  • Examples
  • Forum
  • Twitter
  • GitHub
  • Discord
  • Telegram
  • WeChat
  • YouTube

Developers

  • Overview
  • Technology
  • GitHub
  • Bounties
  • Grants

Community

  • Forum
  • Events
  • Contributor Program
  • Guild Program
  • Startup Accelerator
  • Bounties
  • Tokens

About

  • Team
  • Careers
  • Backers
  • Press Kit
  • Brand Guidelines
  • Privacy Policy

2020 NEAR Protocol|All rights reserved|hello@near.org|Privacy Policy