NAV Navbar

Introduction

The Ontology dAPI standard, proposed in OEP-6, details a general API for interacting with the Ontology blockchain, to be made available to dApp developers by wallet providers, such as O3.

Improved user security

In the cryptocurrency space, the main focal point for securing ones funds is the protection of a users private key(s). All transactions signed with a users private key can be broadcast to the blockchain, and alter the state of their assets. In order to keep this information save, many users opt to keep their private keys secured offline, in a trusted wallet, or through the use of hardware wallets. On the other hand, dApp developers required access to a users private key to have them sign transactions related to the use of their application, which in turn leads to requesting users to provide the dApp with their private key. This is very dangerous, as the dApp developer now has full control over all over a users funds, and if the dApp is malicious, can simply empty a users account without their permission. This is where the dAPI steps in.

Users can minimize their security exposure footprint by reducing the number of apps that have access to their private keys. In many cases these users already have found a trusted wallet provider where they can securely manage their funds. Via the dAPI, users can continue to interact with dApps in the Ontology ecosystem without having to provide their private keys to every dApp. dApps that integrate with the dAPI can simply request users to sign a transaction by sending a message to the wallet provider with the transaction details. The wallet provider will prompt the user to sign the transaction from within the wallet application, and broadcast on their behalf. This is a simple, yet powerful tool, that allows users to safely interact with dApps with the confidence that the dApp will not be able to execute tranactions unknowingly on their behalf.

Accelerated dApp development experience

When starting any new cryptocurrency related project, one of the first big tasks that many promising projects commit to is to provide users with a secure and robust wallet to interact with. Creating a quality wallet is no quick task, and it can distract projects from the original goal that they set out to accomplish. This becomes increasingly more true with the complexity of implementing different SDKs for different platforms or integrating with hardware wallets such as Ledger devices.

There are already a lot of great and trusted wallet providers in the cryptocurrency space, and the dAPI allows new projects to absolve themselves of the responsibility of creating yet another wallet. It is the hope of many that this will allow projects to focus them development attention to the real problem that the space is facing today, providing a myriad of robust and useful applications of blockchain technology.

How does it work?

Web based projects can integrate the o3-dapi-core and o3-dapi-ont Javascript packages into their project via CDN or NPM. The packages will take care of all communications with the Ontology blockchain and the O3 wallet. All functions called by the dApp are asynchronously processed, and users will be prompted via their O3 wallet to identify themselves to the dApp, and sign transactions.

Base Methods

getProvider

o3dapi.ONT.getProvider()
.then((provider: Provider) => {
  const {
    name,
    website,
    version,
    compatibility,
    extra,
  } = provider;

  const {
    theme,
    currency,
  } = extra;

  console.log('Provider name: ' + name);
  console.log('Provider website: ' + website);
  console.log('Provider dAPI version: ' + version);
  console.log('Provider dAPI compatibility: ' + JSON.stringify(compatibility));
  console.log('Provider UI theme: ' + theme);
  console.log('Provider Base currency: ' + currency);
})
.catch(({type: string, description: string, data: any}) => {
  switch(type) {
    case NO_PROVIDER:
      console.log('No provider available.');
      break;
    case CONNECTION_DENIED:
      console.log('The user rejected the request to connect with your dApp.');
      break;
  }
});

Example Response

{
  name: 'Awesome Wallet',
  website: 'https://www.awesome.com',
  version: 'v0.0.1',
  compatibility: [
    'OEP-6',
  ],
  extra: {
    theme: 'Dark Mode',
    currency: 'USD',
  }
}

Returns information about the dAPI provider, including who this provider is, the version of their dAPI, and the NEP that the interface is compatible with.

Input Arguments

None

Success Response

Parameter Type Description
name String The name of the wallet provider
website String The website of the wallet provider
version String The version of the dAPI that the the wallet supports
compatibility String[] A list of all applicable NEPs which the wallet provider supports
extra Object Provider specific attributes
extra
Parameter Type Description
theme string UI theme of the provider
currency string Base currency set by user

Error Response

Parameter Type Description
type String The type of error which has occured
description String A description of the error which has occured
data String? Any raw data associated with the error

getNetworks

o3dapi.ONT.getNetworks()
.then(response => {
  const {
    networks,
    defaultNetwork,
  } = response.networks;

  console.log('Networks: ' + networks);
  // eg. ["MainNet", "TestNet", "PrivateNet"]

  console.log('Default network: ' + defaultNetwork);
  // eg. "MainNet"
})
.catch(({type: string, description: string, data: any}) => {
  switch(type) {
    case NO_PROVIDER:
      console.log('No provider available.');
      break;
    case CONNECTION_DENIED:
      console.log('The user rejected the request to connect with your dApp');
      break;
  }
});

Example Response

{
  networks: ["MainNet", "TestNet", "PrivateNet"],
  defaultNetwork: "TestNet",
}

Returns the networks the wallet provider has available to connect to, along with the default network the wallet is currently set to.

Input Arguments

None

Success Response

Parameter Type Description
networks String[] A list of all networks which this wallet provider allows access to
defaultNetwork String Network the wallet is currently set to

Error Response

Parameter Type Description
type String The type of error which has occured
description String A description of the error which has occured
data String? Any raw data associated with the error

getAccount

o3dapi.ONT.getAccount()
.then((account: Account) => {
  const {
    address,
    label,
  } = account;

  console.log('Provider address: ' + address);
  console.log('Account label: ' + label);
})
.catch(({type: string, description: string, data: any}) => {
  switch(type) {
    case NO_PROVIDER:
      console.log('No provider available.');
      break;
    case CONNECTION_DENIED:
      console.log('The user rejected the request to connect with your dApp');
      break;
  }
});

Example Response

{
  address: 'AeysVbKWiLSuSDhg7DTzUdDyYYKfgjojru',
  label: 'My Spending Wallet'
}

Return the Account that is currently connected to the dApp.

Success Response

Parameter Type Description
address String The address of the account that is currently connected to the dapp
label String A label the users has set to identify their wallet

Error Response

Parameter Type Description
type String The type of error which has occured
description String A description of the error which has occured
data String? Any raw data associated with the error

getPublicKey

o3dapi.ONT.getPublicKey()
.then((account: AccountPublicKey) => {
  const {
    address,
    publicKey,
  } = account;

  console.log('Provider address: ' + address);
  console.log('Provider public key: ' + publicKey);
})
.catch(({type: string, description: string, data: any}) => {
  switch(type) {
    case NO_PROVIDER:
      console.log('No provider available.');
      break;
    case CONNECTION_DENIED:
      console.log('The user rejected the request to connect with your dApp');
      break;
  }
});

Example Response

{
  address: 'AeysVbKWiLSuSDhg7DTzUdDyYYKfgjojru',
  publicKey: '03d43468721ef8936548878071b534d8228c313e02e6d90cef8c65fd3c2d4eaeed'
}

Return the AccountPublicKey that is currently connected to the dApp.

Success Response

Parameter Type Description
address String The address of the account that is currently connected to the dapp
publicKey String The public key of the account that is currently connected to the dapp

Error Response

Parameter Type Description
type String The type of error which has occured
description String A description of the error which has occured
data String? Any raw data associated with the error

disconnect

o3dapi.ONT.disconnect()
.then(() => {
  console.log('Account sucessfully disconnected!');
})
.catch(() => {
  console.log('There was a proider error while disconnecting');
});

Disconnects the user account from the dapp. This method can be used to log a user out, or to change to a different user, by chaining the getAccount methods call after disconnect successfully returns.

Asset Methods

getBalance

Fetch the ONT and ONG balance of a given account.

o3dapi.ONT.asset.getBalance({
  network: 'MainNet',
  address: 'AeysVbKWiLSuSDhg7DTzUdDyYYKfgjojru',
})
.then((balance: Balance) => {
  const {
    ont,
    ong,
  } = balance;

  console.log('ONT balance: ' + ont);
  console.log('ONG balance: ' + ong);
})
.catch(({type: string, description: string, data: any}) => {
  switch(type) {
    case NO_PROVIDER:
      console.log('No provider available.');
      break;
    case RPC_ERROR:
      console.log('There was an error when broadcasting this transaction to the network.');
      break;
  }
});

Example Response

{
  ong: '100.04985783',
  ont: '999'
}

Return the ONT

Success Response

Parameter Type Description
ont String The ONT balance of the account
ong String The ONG balance of the account

Error Response

Parameter Type Description
type String The type of error which has occured
description String A description of the error which has occured
data String? Any raw data associated with the error

getUnboundOng

Fetch the claimable ONG amount for a given account.

o3dapi.ONT.asset.getUnboundOng({
  network: 'MainNet',
  address: 'AeysVbKWiLSuSDhg7DTzUdDyYYKfgjojru',
})
.then(({amount: string}) => {
  console.log('Claimable ONG balance: ' + amount);
})
.catch(({type: string, description: string, data: any}) => {
  switch(type) {
    case NO_PROVIDER:
      console.log('No provider available.');
      break;
    case RPC_ERROR:
      console.log('There was an error when broadcasting this transaction to the network.');
      break;
  }
});

Example Response

{
  amount: '1.04985783'
}

Success Response

Parameter Type Description
amount String The claimable ONG amount

Error Response

Parameter Type Description
type String The type of error which has occured
description String A description of the error which has occured
data String? Any raw data associated with the error

getGrantOng

Fetch the ONG amount granted to a given account.

o3dapi.ONT.asset.getGrantOng({
  network: 'MainNet',
  address: 'AeysVbKWiLSuSDhg7DTzUdDyYYKfgjojru',
})
.then(({amount: string}) => {
  console.log('Claimable ONG balance: ' + amount);
})
.catch(({type: string, description: string, data: any}) => {
  switch(type) {
    case NO_PROVIDER:
      console.log('No provider available.');
      break;
    case RPC_ERROR:
      console.log('There was an error when broadcasting this transaction to the network.');
      break;
  }
});

Example Response

{
  amount: '1.04985783'
}

Success Response

Parameter Type Description
amount String The claimable ONG amount

Error Response

Parameter Type Description
type String The type of error which has occured
description String A description of the error which has occured
data String? Any raw data associated with the error

getAllowance

Fetch the amount of a given asset that was pre-allocation from one account to another.

o3dapi.ONT.asset.getAllowance({
  network: 'MainNet',
  fromAddress: 'AeysVbKWiLSuSDhg7DTzUdDyYYKfgjojru',
  toAddress: 'AGchtbL3ibh9qG1n9KXJusEuAjjSWTsLyk',
  asset: 'ONT',
})
.then(({amount: string}) => {
  console.log('Allocated amount: ' + amount);
})
.catch(({type: string, description: string, data: any}) => {
  switch(type) {
    case NO_PROVIDER:
      console.log('No provider available.');
      break;
    case RPC_ERROR:
      console.log('There was an error when broadcasting this transaction to the network.');
      break;
  }
});

Example Response

{
  amount: '1.04985783'
}

Success Response

Parameter Type Description
amount String Allocation amount of a given asset from one account to another

Error Response

Parameter Type Description
type String The type of error which has occured
description String A description of the error which has occured
data String? Any raw data associated with the error

send

Fetch the amount of a given asset that was pre-allocation from one account to another.

o3dapi.ONT.asset.send({
  network: 'MainNet',
  from: 'AeysVbKWiLSuSDhg7DTzUdDyYYKfgjojru',
  to: 'AGchtbL3ibh9qG1n9KXJusEuAjjSWTsLyk',
  asset: 'ONG',
  amount: '0.00000001'
})
.then(({txid, nodeUrl}: SendOutput) => {
  console.log('Send transaction success!');
  console.log('Transaction ID: ' + txid);
  console.log('RPC node URL: ' + nodeUrl);
})
.catch(({type: string, description: string, data: any}) => {
  switch(type) {
    case NO_PROVIDER:
      console.log('No provider available.');
      break;
    case SEND_ERROR:
      console.log('There was an error when broadcasting this transaction to the network.');
      break;
    case MALFORMED_INPUT:
      console.log('The receiver address provided is not valid.');
      break;
    case CANCELED:
      console.log('The user has canceled this transaction.');
      break;
    case INSUFFICIENT_FUNDS:
      console.log('The user has insufficient funds to execute this transaction.');
      break;
  }
});

Example Response

{
  txid: 'ed54fb38dff371be6e3f96e4880405758c07fe6dd1295eb136fe15f311e9ff77',
  nodeUrl: 'http://polaris1.ont.io:20334',
}

The send API can be used for accepting payments from the user in a cryptocurrency that is located on the Ontology blockchain. It requires user authentication in order for the transaction to be relayed. The transaction will be relayed by the wallet.

Input Arguments

Parameter Type Description
from String The address from where the transaction is being sent. This will be the same value as the one received from the getAccount API
to String The address to where the user should send their funds
asset String The asset which is being requested for payment (e.g ONT or ONG)
amount String The amount which is being requested for payment
network String Network alias to submit this request to.

Success Response

Parameter Type Description
txid String The transaction id of the send request which can be queried on the blockchain
nodeURL String The node to which the transaction was submitted to.

Error Response

Parameter Type Description
type String The type of error which has occured
description String A description of the error which has occured
data String? Any raw data associated with the error

Network Methods

getBlockHeight

getBlock

getBlockHash

getNodeCount

getVersion

getMerkleProof

Transaction Methods

getTransaction

getGasPrice

getBlockHeightByTxHash

getBlockTxsByHeight

getMempoolTxCount

getMempoolTxState

getSmartCodeEvent

Smart Contract Methods

getContract

getStorage

invokeRead

invoke

deploy

Message Methods

signMessage

o3dapi.ONT.message.signMessage({
  message: 'Hello World!',
})
.then((signedMessage: SignedMessage) => {
  const {
    publicKey,
    message,
    salt,
    data,
  } = signedMessage;

  console.log('Public key used to sign:', publicKey);
  console.log('Original message:', message);
  console.log('Salt added to message:', salt);
  console.log('Signed data:', data);
})
.catch(({type: string, description: string, data: any}) => {
  switch(type) {
    case UNKNOWN_ERROR:
      console.log(description);
      break;
  }
});

Example Response

{
  publicKey: '0241392007396d6ef96159f047967c5a61f1af0871ecf9dc82afbedb68afbb949a',
  data: '0147fb89d0999e9d8a90edacfa26152fe695ec8b3770dcad522048297ab903822e12472364e254ff2e088fc3ebb641cc24722c563ff679bb1d1623d08bd5863d0d',
  salt: '058b9e03e7154e4db1e489c99256b7fa',
  message: 'Hello World!',
}

Signs a provided messaged with an account selected by user. A salt prefix is added to the input string, and provided as a part of the data while signing. In the example, the signed value would be 058b9e03e7154e4db1e489c99256b7faHello World!.

Input Arguments

Parameter Type Description
message String The message to sign

Success Response

Parameter Type Description
publicKey String The public key used to sign message
data String The signed data
salt String The salt prefix added to the original message before signing
message String The original message

Error Response

Parameter Type Description
type String The type of error which has occurred
description String A description of the error which has occurred
data String? Any raw data associated with the error

verifyMessage

o3dapi.ONT.message.verifyMessage({
  message: '058b9e03e7154e4db1e489c99256b7faHello World!',
  data: '0147fb89d0999e9d8a90edacfa26152fe695ec8b3770dcad522048297ab903822e12472364e254ff2e088fc3ebb641cc24722c563ff679bb1d1623d08bd5863d0d',
  publicKey: '0241392007396d6ef96159f047967c5a61f1af0871ecf9dc82afbedb68afbb949a',
})
.then(({response: bool}) => {
  console.log('Signature data matches provided message and public key: ' + response);
})
.catch(({type: string, description: string, data: any}) => {
  switch(type) {
    case NO_PROVIDER:
      console.log('No provider available.');
      break;
    case CONNECTION_DENIED:
      console.log('The user rejected the request to connect with your dApp');
      break;
  }
});

Example Response

{
  result: true,
}

Returns whether the provided signature data matches the provided message and was signed by the account of the provided public key.

Input Arguments

Parameter Type Description
message String The original signed message
data String The signature data
publicKey String The public key of the account used to sign the message

Success Response

Parameter Type Description
result Boolean Whether the provided signature matches the provided message and public key

Error Response

Parameter Type Description
type String The type of error which has occurred
description String A description of the error which has occurred
data String? Any raw data associated with the error

Staking Methods

getNodeList

getStakeInfo

getStakedClaimableOng

getStakedClaimableOngRewards

getStakeRoundInfo

getTotalStake

addStake

claimStakedOng

claimStakedOngRewards

requestStakeWithdraw

withdrawStake

OEP4 Token Methods

getTokenDetails

getDecimals

getName

getSymbol

getTokenSupply

getBalanceOf

getAllowance

init

transfer

transferMulti

approve

transferFrom

Events

Events are a way for the wallet to asynchronously with the DAPP when certain changes occur to the state of the wallet that might be relevant for the

READY

On a READY event, the callback will fire with a single argument with information about the wallet provider. At any time a READY event listener is added, it will immidiately be called if the provider is already in a ready state. This provides a single flow for dapp developers since this listener should start any and all interactions with the dapi protocol.

Parameter Type Description
name String The name of the wallet provider
website String The website of the wallet provider
version String The version of the dAPI that the the wallet supports
compatibility String[] A list of all applicable NEPs which the wallet provider supports
extra Object Provider specific attributes
extra
Parameter Type Description
theme string UI theme of the provider

ACCOUNT_CHANGED

On a ACCOUNT_CHANGED event, the callback will fire with a single argument of the new account. This occurs when an account is already connected to the dapp, and the user has changed the connected account from the dapi provider side.

Parameter Type Description
address String Address of the new account
label String A label the users has set to identify their wallet

CONNECTED

On a CONNECTED event, the user has approved the connection of the dapp with one of their accounts. This will fire the first time any of one of the following methods are called from the dapp: getAccount, invoke, send.

Parameter Type Description
address String Address of the new account
label String A label the users has set to identify their wallet

DISCONNECTED

On a DISCONNECTED event, the account connected to the dapp via the dapi provider has been disconnected (logged out).

NETWORK_CHANGED

On a NETWORK_CHANGED event, the user has changed the network their provider wallet is connected to. The event will return the updated network details.

Parameter Type Description
networks String[] A list of all networks which this wallet provider allows access to
defaultNetwork String Network the wallet is currently set to

Errors

The NEO dAPI will provide these basic errors. It is up to the wallet provider to provide additional information if they choose:

Error Type Meaning
NO_PROVIDER Could not find an instance of the dAPI in the webpage
CONNECTION_DENIED The dAPI provider refused to process this request
RPC_ERROR An RPC error occured when submitting the request
MALFORMED_INPUT An input such as the address is not a valid NEO address
CANCELED The user cancels, or refuses the dapps request
INSUFFICIENT_FUNDS The user does not have a sufficient balance to perform the requested action

Utils

These are a collection of commonly used utilities for parsing responses from smart contracts.

hex2str

Converts a hex string to a string.

example:

const hex2strInput = '68656c6c6f';
const hex2strExpected = 'hello';

const hex2strResult = o3dapi.utils.hex2str(hex2strInput);

console.log('hex2str', hex2strExpected === hex2strResult);

str2hex

Converts a string to a hex string.

example:

const str2hexInput = 'hello';
const str2hexExpected = '68656c6c6f';

const str2hexResult = o3dapi.utils.str2hex(str2hexInput);

console.log('str2hex', str2hexExpected === str2hexResult);

hex2int

Converts a hex string to an integer.

example:

const hex2intInput = '00e1f505';
const hex2intExpected = 100000000;

const hex2intResult = o3dapi.utils.hex2int(hex2intInput);

console.log('hex2int', hex2intExpected === hex2intResult);

int2hex

Converts an integer to a hex string.

example:

const int2hexInput = 100000000;
const int2hexExpected = '00e1f505';

const int2hexResult = o3dapi.utils.int2hex(int2hexInput);

console.log('int2hex', int2hexExpected === int2hexResult);

reverseHex

Converts the endian of a hex string, big to little, or little to big.

example:

const reverseHexInput = 'bc99b2a477e28581b2fd04249ba27599ebd736d3';
const reverseHexExpected = 'd336d7eb9975a29b2404fdb28185e277a4b299bc';
const reverseHexResult = o3dapi.utils.reverseHex(reverseHexInput);

console.log('reverseHex', reverseHexExpected === reverseHexResult);

address2scriptHash

Converts an address to a script hash.

example:

const address2scriptHashInput = 'Ab2fvZdmnM4HwDgVbdBrbTLz1wK5TcEyhU';
const address2scriptHashExpected = 'd336d7eb9975a29b2404fdb28185e277a4b299bc';

const address2scriptHashResult = o3dapi.utils.address2scriptHash(address2scriptHashInput);

console.log('address2scriptHash', address2scriptHashExpected === address2scriptHashResult);

scriptHash2address

Converts a script hash to an address.

example:

const scriptHash2addressInput = 'd336d7eb9975a29b2404fdb28185e277a4b299bc';
const scriptHash2addressExpected = 'Ab2fvZdmnM4HwDgVbdBrbTLz1wK5TcEyhU';

const scriptHash2addressResult = o3dapi.utils.scriptHash2address(scriptHash2addressInput);

console.log('scriptHash2address', scriptHash2addressExpected === scriptHash2addressResult);

Development Environment

This is a walkthrough of how to get setup in order to start creating, deploying, and interacting with smart contracts on the Ontology Blockchain.

We will be using 3 separate tools during development:

Solo Chain

A self contained Ontology private network. No additional dependencies required.

O3

dAPI wallet provider which supports the Ontology interface

SmartX

Write and compile smart contract code. Available as an O3 dapp.

Installation

Download and install the latest version of the latest versions of the Solo Chain and O3 apps.

Solo Chain Installer

O3 Desktop Installer Be sure to install the desktop version of the O3 application for development. Mobile support coming soon.

Solo Chain setup

Open the Solo Chain app, and click start if not already started.

soloStart

Claim your ONG for the master account.

soloONG

Get the private key of the master account by clicking on the key, and copying the value.

soloPk

Note that this account is for the private network only. Please do not use this account for any main net transaction, or ever share or display your real private key with anyone but yourself.

soloPk2

O3 Setup

Open up the O3 app, and click the "Import existing wallet" button.

o3import

Paste the Solo Chain master account private key into the provided field.

o3import2

Give the account a name, and a password to login to this account in the future.

o3import3

You should now be logged into the Solo Chain master account in O3. Please navigate to the apps screen by clicking on the apps icon in the toolbar on the left hand side.

o3apps

Once on the apps screen, click on the title "Apps" rapidly 10 times to put the O3 app into developer mode.

o3apptitle

You should notice that in dev mode you will now have access to the "Dev Settings" menu on the top right, and the addition of several developer apps to the app list.

o3devMode

In the "Dev Settings" menu, you can set the location of your private Ontology network. By default, it should already be set up to work with your Solo Chain private network.

o3devset

Creating your Smart Contract

Open up the SmartX app from the list in the O3 application. Please be sure to open from within the O3 app, and NOT directly from your browser. The version provided in the O3 app list is customized to streamline your development experience using the O3 and Solo Chain apps.

o3smartx

Upon opening the app, you will be presented with the default hello world contract. Click on the "File" button on the top left to open up the menu, where you can open a contract file on your local machine, save the current smart contract to your local machine, or load a template, such as OEP4. For this example, go ahead and load up the OEP4 template.

smartxfile

Once loaded, you can review the code in the IDE, and make changes to properties such as the token name or supply. Once you are satisfied, click on "Compile" on the right hand side to compile the contract to into the format required for deployment.

smartxoep4

Deploying your Smart Contract

Once compiled, you should see your compiled contract code on the right hand side. To proceed to deployment, click on either the "Deploy" tab on the top, or the "Next" button on the bottom.

smartxcompiled

Fill in some information about your contract, and click "Deploy".

smartxdeploy

The O3 app will be brought to the foreground, and will prompt you to authorize the deployment transaction. First select your Solo Chain master account, and accept the connection from the SmartX dapp.

smartxconnect

You can then review the transaction confirmation dialog for the deployment transaction you are about to sign. Click on "Show transaction details" to review the details of the transaction.

smartxtxconfirm

Here, you want to ensure that the transaction is being sent to the correct network (PrivateNet in this case), and all the deployment information. Once ready, click the "Approve" button to sign and broadcast the transaction.

smartxtxconfirm2

Once approving, the transaction will be broadcast to your private net, and you will be returned to the SmartX window. From here, you can see the transaction id for your deploy, and can look for this value in Solo Chain.

smartxtxid

In the Solo Chain app, under the "Transaction" tab, you should see your transaction id at the top of the list with the type "Deploy".

soloChainTxid

In the "Smart Contracts" tab, you should also now see your newly deployed contract in the list of contract.

soloChainSc

Please take note of the "Contract Hash" value of your contract, and make sure that it matches the value provided in SmartX after compiling.

smartxContractHash

Calling your Smart Contract (O3 dapi Testbed)

Now that your contract is deployed to your private net, we want to call it. When calling your contract in your dapp, you can use the O3 dapi with the Ontology plugin. To guide you in doing so, the O3 app in dev mode provides a app called "ONT dapi Testbed".

o3ontdapi

Once open, use the network selector to change the network to private net. This testbed allows you to use all of the methods provided by the O3 Ontology plugin in a simple GUI. So you can experiment with calling the different functions on the different networks.

ontdapinet

For example, you scroll down to the "getContract" methods, paste in your contract hash for your newly deployed smart contract, and it will pull the details for your contract. You can experiment calling the details for different contracts on test net or main net.

ontdapigc

To make a test call to your contract, scroll down to "invokeRead", paste in your contract hash into the "Script Hash" field. We will be calling the "decimals" operation, and clear out the "Arguments" field since this method takes no input arguments. Upon submitting, the ouput on the right hand side will show you the JSON response back from the private net, where the "Result" is "08". Which correctly indicates the 8 decimal places out new token has.

ontdapiir

From here, you can play around with the different methods available in the testbed, and when you are ready to start integrating calls to your contract from your dapp, head on over to the O3 Ontology dapi plugin repo. There you can learn more about how to integrate the JS packages into your app, and look at the source code for this testbed as a reference.

o3-dapi-ont

ONT dapi Testbed Reference dapp

Calling your Smart Contract (O3 dapi - OEP4 Testbed)

The O3 dapi protocol also supports convinience methods for OEP4 tokens, which can be found in the dev apps list under "ONT OEP4 Testbed".

o3appoep4

Upon opening the OEP4 testbed app, you should first paste in the script hash of the contract which you would like to interface with, and select the network on which your contract is currently deployed to.

o3oep4hash

The getTokenDetails method will give you an overview of your token, but each method can also be called individually.

o3oep4token

You can also invoke all the methods on the token to test our your logic.

o3oep4invoke

All of these methods are available on the o3-dapi-ont plugin at o3dapi.ONT.oep4. Examples of all calls can be found for the testbed code here.