Development Environment and Tools

Necessary tools to start writing EVM contracts

circle-info

Before getting started, you can apply for testnet ONG tokens that will be used for invoking any contracts you deploy over at the faucet herearrow-up-right.

circle-exclamation

Development Environment and Tools

EVM smart contracts are written using Solidityarrow-up-right. You can reuse existing Ethereum contract frameworks to develop and deploy EVM contracts.

Remix

Remix IDEarrow-up-right is an open source development environment for EVM contracts. Remix IDE documentation is herearrow-up-right.

We will now go through an example of a Hello World contract development using Remix.

Initialize Remix

First, locate and activate "Solidity Compiler" and "Deploy and Run Transactions" in PLUGIN MANAGER.

image-20210526142630046arrow-up-right

Then, select Solidity environment. Create a new file and name it HelloWorld.sol. Then copy the code of Hello World contractarrow-up-right and paste it in the file just created.

image-20210526143301031arrow-up-right

Compile Contract

Click on the Solidity Compiler button, select compiler version to 0.5.10 and start compiling HelloWorld.sol

Deploy Contract

The contract is ready to deploy on Ontology after compiling. Here we deploy it on Ontology TestNet.

circle-info

Note: MetaMask must be configured for Ontology before you deploy the contract.

Select "Custom RPC" in MetaMask networks settings. Fill in and save the info below.

  • Network name: Ontology TestNet

  • Node URL: https://polaris1.ont.io:10339 or https://polaris2.ont.io:10339 or https://polaris3.ont.io:10339 or https://polaris4.ont.io:10339

  • Chain ID: 5851

RemixIDE_Step1arrow-up-right

Finally, select "Injected Web3" in Remix. Click "Deploy" to finish.

deploy contractarrow-up-right

Invoke Contract

Now you can call the method in this contract. The string hello is saved in the contract when you deploy it, you can call the method message to query this string:

invoke contractarrow-up-right

Truffle

Truffle offers tools and frameworks for EVM contract development, testing and management. You can find more details herearrow-up-right.

Now we will demonstrate how to use Truffle with this test codearrow-up-right.

Install Truffle

First, initialize and install dependencies.

Then run this command to install Truffle.

Configure truffle-config

  • Create a new .secret to store the mnemonic phrase or private key (which can be found in MetaMask).

  • Edit the code of truffle-config as below.

Deploy Contract

Run this command to deploy the contract on the Ontology network.

If successful, you will see the result below.

circle-exclamation

Hardhat

Hardhat is an Ethereum development environment. We will use this test codearrow-up-right as an example and demonstrate how to use Hardhat.

Install Hardhat

Please refer to Hardhat docarrow-up-right for details on this step.

Configure hardhat-config

  • Create a new .secret file to save your private key.

  • Update the code of hardhat.config.js as shown below:

Deploy Contract

Run this command in root of the project directory to deploy the contract on Ontology Chain:

The result looks like this:

Network Info

Network Types

MainNet

Item

Description

NetworkName

Ontology MainNet

chainId

58

Gas Token

ONG Token

RPC

https://dappnode1.ont.io:10339,

https://dappnode2.ont.io:10339,

https://dappnode3.ont.io:10339,

https://dappnode4.ont.io:10339,

http://dappnode1.ont.io:20339, http://dappnode2.ont.io:20339, http://dappnode3.ont.io:20339, http://dappnode4.ont.io:20339

TestNet

Item

Description

NetworkName

Ontology TestNet

chainId

5851

Gas Token

ONG Token

RPC

https://polaris1.ont.io:10339 , https://polaris2.ont.io:10339,

https://polaris3.ont.io:10339,

https://polaris4.ont.io:10339

circle-info

Ontology EVM contracts consume ONG as gas fee for execution. You can apply for TestNet ONG herearrow-up-right.

EVM Assets on Ontology

Name

Address

ONG

0x00000000000000000000000000000000000000000

OEP-4 Assets

Please refer to this linkarrow-up-right.

Last updated