Ontology Developer Center
DISCOVERCOMMUNITYSUPPORT
  • Introduction
  • Discover Ontology
  • Getting Started
  • Glossary
  • Decentralized Identity and Data
    • ONT ID
      • Decentralized Identifiers
        • Method Specification for Ontology
        • Method Specification for Ethereum
        • Method Specification for BSC
      • Verifiable Credentials
        • Anonymous Credentials
      • ONT Login
        • Scenarios
        • Protocol Specification
        • Front-end JavaScript SDK
          • Integration and Usage
          • API Reference
        • Front-end UI SDK
          • Integration and Usage
          • API Reference
        • Back-end Go SDK
          • Integration and Usage
          • API Reference
        • Back-end Java SDK
          • Integration and Usage
          • API Reference
      • ONT TAG
        • Workflow
        • API Reference
      • Mercury
      • OScore
    • DDXF
      • Components and Interfaces
      • GREP
      • Overall Scheme
      • Solutions
        • Marketplace
          • Deployment
          • Scenarios
          • SaaS Tenant
          • Java SDK
        • Data Storage
          • Deployment
          • Java SDK
        • Resource Auditor
        • Offline Judge
      • Use Cases
        • E-Shops
  • ONTOLOGY ELEMENTS
    • Smart Contracts
      • Types of smart contracts
    • Token Protocols
    • Consensus Mechanism
    • Ontology Oracle
      • Oracle Process Flow
  • GUIDES & TUTORIALS
    • Development Guides
      • dApp Development
        • Using the dAPI
        • Data Synchronization
      • Smart Contract Development
        • EVM Contract
          • Development Environment and Tools
          • Wallet Setup
          • Contract Development
          • How to Deploy a Smart Contract with GetBlock
        • NeoVM Contract
          • Development tools and environment
          • Launching the IDE
          • Writing and editing program logic
          • Deploying and testing on private net
        • WASM Contract
          • Development Environment
          • Project Initiation - Hello World
          • Creating your own project
          • Development using SmartX
          • Runtime API
          • Contract Fundamentals
          • Inter-contract Interaction
          • Developing Contracts in C++
        • Publish Contract Source Code
    • Integration Guides
      • dApp Integration
        • dAPI Integration
          • Chrome Plugin
          • Mobile wallet dApp
          • QR code mechanism
          • Wake call mechanism
        • Cocos 2D-x
        • Unity 3D applications
      • Mobile Wallet Integration
        • SDK integration
        • dAPI Integration
          • In-wallet applications
          • QR code mechanism
          • Wake call mechanism
        • Stake
      • Using ONT ID
      • Exchange Integration
        • Exchange Docking Guide
        • Exchange API
      • Ontology for dApp Stores
    • EVM & Token Decimals Upgrade
  • ONTOLOGY NODE
    • Abstract
    • Node Deployment
      • Standard Node
      • Rosetta Node
    • Interacting with a Public Node
  • DEVELOPER TOOLS
    • dApp Development Framework
      • Punica CLI
      • Punica boxes
      • Solo Chain
    • IDE
    • APIs
      • HTTP API
        • Restful
        • WebSocket
        • Remote Procedure Call (RPC)
      • Explorer v2 API
        • Block
        • Address
        • Contract
        • Token
        • Transactions
        • ONT ID
        • Summary
        • Node
      • Native Token API
        • ONT Contract API
        • ONG Contract API
      • ONT ID Contract API
      • Web3 API
      • OScore Open API
      • Rosetta Node API
        • Data API
        • Construction API
      • DToken Contract API
      • DDXF
        • Marketplace Contract API
        • Storage API
      • Governance API
    • Digital Wallet
      • Chrome Plugin provider
      • Chrome Plugin dAPI
      • Mobile version provider
      • Mobile version dAPI
    • SDKs
    • Signing Server
      • Installation
      • API reference
  • COMMUNITY
    • Ecosystem Programs
    • Community Libraries
    • Community Events
    • Community Channels
    • Core Contributors
  • SUPPORT
    • FAQ
      • Basic blockchain concepts
      • Ontology Nodes
      • Ontology token protocols
      • Smart contracts
      • SDKs and APIs
    • Contact Us
Powered by GitBook
On this page
  • Development Environment and Tools
  • Remix
  • Truffle
  • Hardhat
  • Network Info
  • Network Types
  • EVM Assets on Ontology
  • OEP-4 Assets

Was this helpful?

  1. GUIDES & TUTORIALS
  2. Development Guides
  3. Smart Contract Development
  4. EVM Contract

Development Environment and Tools

Necessary tools to start writing EVM contracts

PreviousEVM ContractNextWallet Setup

Last updated 1 year ago

Was this helpful?

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

The value of gas price for a transaction must be in multiples of 10^9. The minimum value is 2500*10^9.

Development Environment and Tools

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

Remix

is an open source development environment for EVM contracts. Remix IDE documentation is .

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.

Then, select Solidity environment. Create a new file and name it HelloWorld.sol. Then copy the code of and paste it in the file just created.

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.

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

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

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:

Truffle

Install Truffle

First, initialize and install dependencies.

Then run this command to install Truffle.

npm install -g 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.

const HDWalletProvider = require('@truffle/hdwallet-provider');
const fs = require('fs');
const mnemonic = fs.readFileSync(".secret").toString().trim();
module.exports = {
  networks: {
    ontology: {
     provider: () => new HDWalletProvider(mnemonic, `http://polaris2.ont.io:20339`),
     network_id: 5851,
     port: 20339,            // Standard Ethereum port (default: none)
     timeoutBlocks: 200,
     gas:800000,
     skipDryRun: true
    }
  },
  compilers: {
    solc: {
      version: "0.5.16",    // Fetch exact version from solc-bin (default: truffle's version)
      docker: false,        // Use "0.5.1" you've installed locally with docker (default: false)
      settings: {          // See the solidity docs for advice about optimization and evmVersion
       optimizer: {
         enabled: true,
         runs: 200
       },
       evmVersion: "byzantium"
      }
    }
  }
};

Deploy Contract

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

truffle migrate --network ontology

If successful, you will see the result below.

Note: Avoid using ETH units (e.g. wei, gwei, ether, etc.) when writing test scripts.

Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.

Starting migrations...
======================
> Network name:    'ontology'
> Network id:      12345
> Block gas limit: 0 (0x0)
1_initial_migration.js
======================

   Replacing 'Migrations'
   ----------------------
   > transaction hash:    0x9019551f3d60611e1bc6b323f3cf3020d15c8aeb06833d14ff864e24622884aa
   > Blocks: 0            Seconds: 4
   > contract address:    0x53e137A51CfD1E1b088E0d921eB5dBCF9cFa955E
   > block number:        6264
   > block timestamp:     1624876467
   > account:             0x4e7946D1Ee8f8703E24C6F3fBf032AD4459c4648
   > balance:             0.00001
   > gas used:            172969 (0x2a3a9)
   > gas price:           0 gwei
   > value sent:          0 ETH
   > total cost:          0 ETH


   > Saving migration to chain.
   > Saving artifacts
   -------------------------------------
   > Total cost:                   0 ETH


2_deploy_migration.js
=====================

   Replacing 'HelloWorld'
   ----------------------
   > transaction hash:    0xf8289b96f2496a8c940ca38d736a554a90f64d927b689921781619499906721b
   > Blocks: 0            Seconds: 4
   > contract address:    0xfbff9bd546B0e0D4b40f6f758847b70050d01b37
   > block number:        6266
   > block timestamp:     1624876479
   > account:             0x4e7946D1Ee8f8703E24C6F3fBf032AD4459c4648
   > balance:             0.00001
   > gas used:            243703 (0x3b7f7)
   > gas price:           0 gwei
   > value sent:          0 ETH
   > total cost:          0 ETH

hello contract address: 0xfbff9bd546B0e0D4b40f6f758847b70050d01b37

   > Saving migration to chain.
   > Saving artifacts
   -------------------------------------
   > Total cost:                   0 ETH


Summary
=======
> Total deployments:   2
> Final cost:          0 ETH

Hardhat

Install Hardhat

Configure hardhat-config

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

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

require("@nomiclabs/hardhat-waffle");
const fs = require('fs');
const privateKey = fs.readFileSync(".secret").toString().trim();
module.exports = {
    defaultNetwork: "ontology_testnet",
        ontology_testnet: {
            url: "http://polaris2.ont.io:20339",
            chainId: 5851,
            gasPrice:2500000000000,
            gas:2000000,
            timeout:10000000,
            accounts: [privateKey]
        }
    },
    solidity: {
        version: "0.8.0",
        settings: {
            optimizer: {
                enabled: true,
                runs: 200
            }
        }
    },
};

Deploy Contract

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

$ npx hardhat run scripts/sample-script.js --network ontology_testnet

The result looks like this:

sss@sss hardhatdemo % npx hardhat run scripts/sample-script.js --network ontology_testnet
RedPacket deployed to: 0xB105388ac7F019557132eD6eA90fB4BAaFde6E81

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

Block Explorer

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

Block Explorer

EVM Assets on Ontology

Name

Address

ONG

0x00000000000000000000000000000000000000000

OEP-4 Assets

Blockchain Explorer URL: ""

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

Now we will demonstrate how to use Truffle with this .

(comes with Node)

Hardhat is an Ethereum development environment. We will use this as an example and demonstrate how to use Hardhat.

Please refer to for details on this step.

Ontology EVM contracts consume ONG as gas fee for execution. You can apply for TestNet ONG .

Please refer to this .

https://explorer.ont.io/testnet
here
test code
Node.js v8+ LTS and npm
Git
test code
Hardhat doc
here
link
https://explorer.ont.io/
https://explorer.ont.io/testnet
faucet here
Solidity
Remix IDE
here
Hello World contract
RemixIDE_Step1
invoke contract
deploy contract
image-20210526142630046
image-20210526143301031