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
  • 1. Get Ready
  • 2. Create Your Smart Contract (Example)
  • 3. Compile Your Smart Contract
  • 4. Connect to Ontology's RPC Node with Web3.js
  • 5. Deploy Your Smart Contract with Web3.js
  • 6. Test Your Smart Contract
  • 7. Celebrate Your Success! 🎉

Was this helpful?

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

How to Deploy a Smart Contract with GetBlock

Dive straight into our freshly brewed guide from the devs' desk. Your dream of deploying a smart contract on Ontology is about to become a reality with these easy, step-by-step instructions.

PreviousContract DevelopmentNextNeoVM Contract

Last updated 1 year ago

Was this helpful?

1. Get Ready

Set up a Development Environment:

  • .

  • Development tools like [] or [].

  • on your computer.

  • library.

  • The Ontology RPC URL endpoint by .

2. Create Your Smart Contract (Example)

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.2 <0.9.0;

contract FunctionalityContract {
    string message;
    function setMessage(string memory newMessage) public {
        message = newMessage;
    }
    function getMessage() public view returns (string memory) {
        return message;
    }
}

Save this as Test.sol or a name of your choice with .sol extension.

3. Compile Your Smart Contract

truffle compile Test.sol

You'll receive an output similar to:

Compiling your contracts...

> Compiling ./Test.sol
> Artifacts written to /Users/hannask/explorer/ontologi/build/contracts
> Compiled successfully using:
— solc: 0.8.19+commit.7dd6d4e4.Emscripten.clang

This generates two crucial files: the bytecode (.bin) and ABI (.abi). The bytecode is the version ready for the Ontology blockchain, while the ABI describes how you can interact with the contract.

4. Connect to Ontology's RPC Node with Web3.js

You can achieve this connection by using the following script. Remember to replace <Ontology RPC URL> with the URL you got from GetBlock.

const Web3 = require('web3');
const web3 = new Web3('https://ont.getblock.io/<API-KEY>/testnet/web3/');

5. Deploy Your Smart Contract with Web3.js

The following script assists in deploying the smart contract:

const fs = require('fs');

// Read ABI and bytecode files
const abi = JSON.parse(fs.readFileSync('<path-to-abi-file>', 'utf8'));
const bytecode = fs.readFileSync('<path-to-bytecode-file>', 'utf8');

// Create a new Contract object using ABI
const myContract = new web3.eth.Contract(abi);

// Create a transaction object using the bytecode
const deployTransaction = myContract.deploy({
    data: '0x' + bytecode,
    arguments: [arg1, arg2, ...]
});

// Send the transaction to Ontology
deployTransaction.send({
    from: '<sender-address>',
    gas: <gas-limit>,
    gasPrice: <gas-price>
})
.on('receipt', (receipt) => {
    console.log('Contract deployed at address:', receipt.contractAddress);
});

Don't forget to fill in the placeholders (<path-to-abi-file>, <path-to-bytecode-file>, <sender-address>, <gas-limit>, and <gas-price>) with the corresponding details.

6. Test Your Smart Contract

Once your smart contract is deployed, it's crucial to test its functionality to ensure it behaves as expected.

// Set a message
myContract.methods.setMessage("Hello, Ontology!").send({ from: '<sender-address>' }).then(receipt => {
    console.log('Transaction receipt:', receipt);
});

// Get the message
myContract.methods.getMessage().call().then(result => {
    console.log('Stored message is:', result);
});

This test involves setting a new message in the contract and retrieving it. You should see "Hello, Ontology!" printed in your console.

7. Celebrate Your Success! 🎉

You've now written, deployed, and tested a smart contract on the Ontology network using the GetBlock RPC node provider. Cheers to your contribution to the decentralized world!

In order to get one, register on , choose Ontology in the protocols, testnet as a network and create your endpoint, then copy it to use for your purposes. If you want to deploy contract on mainnet, then choose mainnet as a network.

Solidity programming language
Truffle
Remix IDE
Node.js
Web3.js
GetBlock
GetBlock.io