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. Development environment set-up and installation
  • 2. Creating a dAPI instance
  • 3. Deploying dAPI methods
  • Fetching account or identity information
  • Smart contract methods
  • Communication methods that assist interaction with the chain
  • Account transfer method
  • Data signature methods
  • 4. dAPI demonstration
  • How to set the gaslimit and gasprice
  • How to handle addresses

Was this helpful?

  1. GUIDES & TUTORIALS
  2. Integration Guides
  3. dApp Integration
  4. dAPI Integration

Chrome Plugin

Integrating the Google Chrome Cyano wallet plugin

PreviousdAPI IntegrationNextMobile wallet dApp

Last updated 3 years ago

Was this helpful?

Before using the , it is necessary to first install and implement a wallet that has the dAPI provider functionality built into it, for e.g., .

The dAPI can be implemented using TypeScript, and can also be used in JavaScript programs.

Some of the more popular usage channels of dApps, apart from opening the dApp in the Chrome browser, also consist of launching the dApp from withing the mobile wallet. The access scheme for opening a dApp in the wallet is illustrated .

Here is a step by step guide to assist developers with the integration process:

1. Development environment set-up and installation

Before starting with the actual development process, do ensure that the following tools are installed and set-up on your local machine.

  • Node.js v6+ (LTS with npm) -

  • Google Chrome -

  • Cyano Wallet Chrome Plugin -

  • Git -

Next, we can install Ontology's dAPI. While building dApps, this dAPI serves as one of the core APIs that allow us to communicate with the chain. The source code can be downloaded . To carry out the installation using npm, use the following shell command:

npm install ontology-dapi

2. Creating a dAPI instance

Creating a dAPI instance involves importing and registering the client-side, as such:

import { client } from 'ontology-dapi';
client.registerClient({});

3. Deploying dAPI methods

Once a dAPI instance is created successfully, dAPI methods can be used in a given dApp.

Fetching account or identity information

account = await client.api.asset.getAccount()
res = await client.api.identity.getIdentity();

Smart contract methods

const result = await client.api.smartContract.invoke({contract,method,parameters,gasPrice,gasLimit,requireIdentity});
const result = await client.api.smartContract.invokeRead({ contract, method, parameters });
const result = await client.api.smartContract.deploy({code,name,version,author,email,description,needStorage,gasPrice,gasLimit});

Communication methods that assist interaction with the chain

const network = await client.api.network.getNetwork();
const height = await client.api.network.getBlockHeight();
const block = await client.api.network.getBlock({ block: 1 });
const transaction = await client.api.network.getTransaction({txHash: '314e24e5bb0bd88852b2f13e673e5dcdfd53bdab909de8b9812644d6871bc05f'});
const balance = await client.api.network.getBalance({ address: 'AcyLq3tokVpkMBMLALVMWRdVJ83TTgBUwU' });

Account transfer method

const result = await client.api.asset.makeTransfer({ recipient, asset, amount });

Data signature methods

const message: string = values.message;
const signature: Signature = {
  data,
  publicKey
};
const result = await client.api.message.signMessage({ message });
const result = await client.api.message.verifyMessage({ message, signature });

4. dAPI demonstration

Follow the link below to refer to a demo dApp that utilizes the dAPI methods mentioned above.

How to set the gaslimit and gasprice

Every transaction that takes place on the chain includes a gaslimit and gasprice.

gasprice has a correlation with the amount of standby time while the given transaction is packaged. Currently, the lowest value of gasprice is 500 units on the TestNet and MainNet.

The gaslimit of deployment contracts is set based on the complexity of smart contract's execution process. The minimum gaslimit value of a contract can be determined before deploying it by carrying out a pre-execution. The default gaslimit value of native contracts is 20000, while that of deployment contracts is usually higher than 20000000 units, generally speaking.

How to handle addresses

The Chrome plugin Cyano wallet only accepts addresses in ByteArray format when importing addresses. While testing smart contracts in SmartX, the IDE automatically converts addresses to ByteArray format. So, there will be no address related issues during the deployment phase. However, in the developer's local environment, if the conversion is not carried out manually, the system will return an error.

The following method can be used to convert addresses to ByteArray format in JavaScript:

import {Crypto} from 'ontology-ts-sdk';
var address = new Crypto.Address(account).serialize() //The "address" assigned here is in ByteArray format

For a comprehensive list of all the available dAPI methods, please refer to the .

dAPI for Chrome
Cyano Wallet for Chrome
here
Download link
Download link
Download link
Download link
here
dAPI Specification
Using the dAPI