NAV Navbar
python

Introduction

Codacy Badge Codacy Badge Build Status pypi-w pypi-pyversions pypi-v Downloads

The ontology-python-sdk is the official Python implementation of the Ontology SDK which contain specific functionality for the Ontology ecosystem.

Getting Started

pip3 install ontology-python-sdk

Installation requires a Python 3.6 or later environment.

Network

This module contains functions help you to interact with an Ontology nodes by RPC, RESTful or WebSocket.

RPC

from ontology.sdk import Ontology

sdk = Ontology()
sdk.rpc.connect_to_test_net()
sdk.rpc.connect_to_main_net()
sdk.rpc.connect_to_localhost()
sdk.rpc.set_address('http://localhost:20336')

You can interact with Ontology network by JSON-RPC in synchronously.

get version

from ontology.sdk import Ontology

sdk = Ontology()
sdk.rpc.connect_to_test_net()
version = sdk.rpc.get_version()

Gets the current node version synchronously.

get networkid

from ontology.sdk import Ontology

sdk = Ontology()
sdk.rpc.connect_to_test_net()
version = sdk.rpc.get_network_id()

Gets the current network ID synchronously.

get merkle proof

from ontology.sdk import Ontology

sdk = Ontology()
sdk.rpc.connect_to_test_net()
tx_hash = '12943957b10643f04d89938925306fa342cec9d32925f5bd8e9ea7ce912d16d3'
merkle_proof = sdk.rpc.get_merkle_proof(tx_hash)

Gets merkle proof of specific transaction synchronously.

Merkle tree

RESTful

from ontology.sdk import Ontology

sdk = Ontology()
sdk.restful.connect_to_test_net()
sdk.restful.connect_to_main_net()
sdk.restful.connect_to_localhost()
sdk.restful.set_address('http://localhost:20334')

You can interact with Ontology network by JSON-RPC in synchronously.

get version

from ontology.sdk import Ontology

sdk = Ontology()
sdk.restful.connect_to_test_net()
version = sdk.restful.get_version()

Gets the current node version synchronously.

get networkid

from ontology.sdk import Ontology

sdk = Ontology()
sdk.rpc.connect_to_test_net()
version = sdk.restful.get_network_id()

Gets the current network ID synchronously.

get merkle proof

from ontology.sdk import Ontology

sdk = Ontology()
sdk.restful.connect_to_test_net()
tx_hash = '12943957b10643f04d89938925306fa342cec9d32925f5bd8e9ea7ce912d16d3'
merkle_proof = sdk.restful.get_merkle_proof(tx_hash)

Gets merkle proof of specific transaction synchronously.

Merkle tree

WebSocket

from ontology.sdk import Ontology

sdk = Ontology()
sdk.websocket.connect_to_test_net()
sdk.websocket.connect_to_main_net()
sdk.websocket.connect_to_localhost()
sdk.rpc.set_address('http://localhost:20335')

You can interact with Ontology network by WebSocket.

get version

from ontology.sdk import Ontology

sdk = Ontology()
sdk.websocket.connect_to_test_net()
version = await sdk.websocket.get_version()

Gets the current node version asynchronously.

get networkid

from ontology.sdk import Ontology

sdk = Ontology()
sdk.rpc.connect_to_test_net()
version = await sdk.websocket.get_network_id()

Gets the current network ID asynchronously.

get merkle proof

from ontology.sdk import Ontology

sdk = Ontology()
sdk.websocket.connect_to_test_net()
tx_hash = '12943957b10643f04d89938925306fa342cec9d32925f5bd8e9ea7ce912d16d3'
merkle_proof = await sdk.websocket.get_merkle_proof(tx_hash)

Gets merkle proof of specific transaction asynchronously.

Merkle tree

Async RPC

from ontology.sdk import Ontology

sdk = Ontology()
sdk.aio_rpc.connect_to_test_net()
sdk.aio_rpc.connect_to_main_net()
sdk.aio_rpc.connect_to_localhost()

You can interact with Ontology network by JSON-RPC in asynchronously.

get version

from ontology.sdk import Ontology

sdk = Ontology()
sdk.aio_rpc.connect_to_test_net()
version = await sdk.aio_rpc.get_version()

Gets the current node version asynchronously.

get networkid

from ontology.sdk import Ontology

sdk = Ontology()
sdk.rpc.connect_to_test_net()
version = await sdk.aio_rpc.get_network_id()

Gets the current network ID asynchronously.

get merkle proof

from ontology.sdk import Ontology

sdk = Ontology()
sdk.aio_rpc.connect_to_test_net()
tx_hash = '12943957b10643f04d89938925306fa342cec9d32925f5bd8e9ea7ce912d16d3'
merkle_proof = await sdk.aio_rpc.get_merkle_proof(tx_hash)

Gets merkle proof of specific transaction asynchronously.

Merkle tree

Async RESTful

from ontology.sdk import Ontology

sdk = Ontology()
sdk.aio_restful.connect_to_test_net()
sdk.aio_restful.connect_to_main_net()
sdk.aio_restful.connect_to_localhost()

You can interact with Ontology network by RESTful in asynchronously.

get version

from ontology.sdk import Ontology

sdk = Ontology()
sdk.aio_restful.connect_to_test_net()
version = await sdk.aio_restful.get_version()

get networkid

from ontology.sdk import Ontology

sdk = Ontology()
sdk.rpc.connect_to_test_net()
version = await sdk.aio_restful.get_network_id()

Gets the current network ID asynchronously.

get merkle proof

from ontology.sdk import Ontology

sdk = Ontology()
sdk.aio_restful.connect_to_test_net()
tx_hash = '12943957b10643f04d89938925306fa342cec9d32925f5bd8e9ea7ce912d16d3'
merkle_proof = await sdk.aio_restful.get_merkle_proof(tx_hash)

Gets merkle proof of specific transaction asynchronously.

Merkle tree

Account

get address

from ontology.utils import utils
from ontology.account.account import Account

private_key = utils.get_random_bytes(32).hex()
account = Account(private_key)
address = account.get_addres()

export wif

from ontology.utils import utils
from ontology.account.account import Account

private_key = utils.get_random_bytes(32).hex()
account = Account(private_key)
wif = account.export_wif()

Identity

Wallet Manager

from ontology.sdk import Ontology

sdk = Ontology()
wm = sdk.wallet_manager

This module contains functions to manage Ontology digital accounts and digital identity (named ONT ID) which based on W3c DID protocol specification.

create wallet

from os import path
from ontology.sdk import Ontology

sdk = Ontology()
wallet_path = path.join(path.curdir, 'wallet.json')
sdk.wallet_manager.create_wallet_file(wallet_path)

This interface helps us to create a wallet's KeyStore file in specify path.

open wallet

from os import path
from ontology.sdk import Ontology

sdk = Ontology()
wallet_path = path.join(path.curdir, 'wallet.json')
wallet = sdk.wallet_manager.open_wallet(wallet_path)

We can read wallet's KeyStore by using open_wallet interface, which will help us load KeyStore file in JSON format from disk into memory.

create account

from ontology.sdk import Ontology

sdk = Ontology()
acct = sdk.wallet_manager.create_account('password')

create identity

from ontology.sdk import Ontology

sdk = Ontology()
identity = sdk.wallet_manager.create_identity('password')

get account

from os import path
from ontology.sdk import Ontology

sdk = Ontology()
wallet_path = path.join(path.curdir, 'wallet.json')
wallet = sdk.wallet_manager(wallet_path)
acct = wallet.get_account_by_b58_address('ANDfjwrUroaVtvBguDtrWKRMyxFwvVwnZD', 'password')

get identity

from os import path
from ontology.sdk import Ontology

sdk = Ontology()
wallet_path = path.join(path.curdir, 'wallet.json')
wallet = sdk.wallet_manager(wallet_path)
identity = wallet_manager.get_identity_by_ont_id('did:ont:ANDfjwrUroaVtvBguDtrWKRMyxFwvVwnZD')

HD Wallet

get master keys

from ontology.crypto.hd_private_key import HDPrivateKey

mnemonic = 'obscure worry home pass museum toss else accuse limb hover denial alpha'
master_keys = HDPrivateKey.master_key_from_mnemonic(mnemonic, 'password')

get root keys

from ontology.crypto.hd_private_key import HDPrivateKey

mnemonic = 'obscure worry home pass museum toss else accuse limb hover denial alpha'
master_keys = HDPrivateKey.master_key_from_mnemonic(mnemonic, 'password')
root_keys = HDPrivateKey.from_path(self.master_keys[0])

get private child key

from ontology.crypto.hd_private_key import HDPrivateKey

mnemonic = 'obscure worry home pass museum toss else accuse limb hover denial alpha'
master_keys = HDPrivateKey.master_key_from_mnemonic(mnemonic, 'password')

root_keys = HDPrivateKey.from_path(master_keys[0])
for i in range(10):
  child_sks = HDPrivateKey.from_path(root_keys[-1], '{change}/{index}'.format(change=0, index=i))

get public child key

from ontology.crypto.hd_public_key import HDPublicKey

mnemonic = 'obscure worry home pass museum toss else accuse limb hover denial alpha'
master_keys = HDPrivateKey.master_key_from_mnemonic(mnemonic, 'password')
root_keys = HDPrivateKey.from_path(master_keys[0])

root_pk = root_keys[-1].public_key
for i in range(10):
  child_pks = HDPublicKey.from_path(root_pk, '{change}/{index}'.format(change=0, index=i))

Native Contract

ONT

from os import path

from ontology.sdk import Ontology

sdk = Ontology()
ont = sdk.native_vm.ont()

This module contains functions to manage Ontology digital asset Ontology Token which based on Native Contract.

name

from ontology.sdk import Ontology

sdk = Ontology()
token_name = sdk.native_vm.ont().name()

Returns the name of the token synchronously.

symbol

from ontology.sdk import Ontology

sdk = Ontology()
token_symbol = sdk.native_vm.ont().symbol()

Returns the symbol of the token synchronously.

decimals

from ontology.sdk import Ontology

sdk = Ontology()
decimals = sdk.native_vm.ont().decimals()

Returns the number of decimals the token uses synchronously.

balance of

from ontology.sdk import Ontology

sdk = Ontology()
balance = sdk.native_vm.ont().balance_of('ANDfjwrUroaVtvBguDtrWKRMyxFwvVwnZD')

Returns the account balance of another account with owner address synchronously.

transfer

from ontology.sdk import Ontology

sdk = Ontology()
from_acct = sdk.wallet_manager.create_account('password')
to_address = 'ANDfjwrUroaVtvBguDtrWKRMyxFwvVwnZD'
tx_hash = sdk.native_vm.ont().transfer(from_acct, to_address, 10, from_acct, 500, 20000)

Transfers amount of tokens to to_address synchronously.

approve

from ontology.sdk import Ontology

sdk = Ontology()
owner = sdk.wallet_manager.create_account('password')
spender = 'ANDfjwrUroaVtvBguDtrWKRMyxFwvVwnZD'
tx_hash = sdk.native_vm.ont().approve(owner, spender, 10, owner, 500, 20000)

Allows spender to withdraw from owner account multiple times, up to the value amount.

allowance

from ontology.sdk import Ontology

sdk = Ontology()
owner = 'Af1n2cZHhMZumNqKgw9sfCNoTWu9de4NDn'
spender = 'ANDfjwrUroaVtvBguDtrWKRMyxFwvVwnZD'
tx_hash = sdk.native_vm.ont().allowance(owner, spender)

Returns the amount which spender is still allowed to withdraw from owner.

transfer from

from ontology.sdk import Ontology

sdk = Ontology()
spender = sdk.wallet_manager.create_account('password')
owner = 'ANDfjwrUroaVtvBguDtrWKRMyxFwvVwnZD'
to_address = spender.get_address_base58()
tx_hash = sdk.native_vm.ont().transfer_from(spender, owner, to_address, 1, acct1, 500, 20000)

Transfers value amount of tokens from address owner to address to_address.

ONG

from ontology.sdk import Ontology

sdk = Ontology()
ong = sdk.native_vm.ong()

This module contains functions to manage Ontology digital asset Ontology Gas which based on Native Contract.

name

from ontology.sdk import Ontology

sdk = Ontology()
token_name = sdk.native_vm.ong().name()

Returns the name of the token synchronously.

symbol

from ontology.sdk import Ontology

sdk = Ontology()
token_symbol = sdk.native_vm.ong().symbol()

Returns the symbol of the token synchronously.

decimals

from ontology.sdk import Ontology

sdk = Ontology()
decimals = sdk.native_vm.ong().decimals()

Returns the number of decimals the token uses synchronously.

balance of

from ontology.sdk import Ontology

sdk = Ontology()
balance = sdk.native_vm.ong().balance_of('ANDfjwrUroaVtvBguDtrWKRMyxFwvVwnZD')

Returns the account balance of another account with owner address synchronously.

unbound

from ontology.sdk import Ontology

sdk = Ontology()
sdk.rpc.connect_to_test_net()
address = 'ANDfjwrUroaVtvBguDtrWKRMyxFwvVwnZD'
unbound_ong = sdk.native_vm.ong().unbound(address)

Unbound ONG is an amount of ONG which has not been added to your claimable ONG balance yet (since it only updates each time you make an ONT transaction in your wallet address). When an ONT transaction is made in your address, the claimable ONG balance will update (adding your unbound ONG amount to your claimable ONG amount).

transfer

from ontology.sdk import Ontology

sdk = Ontology()
from_acct = sdk.wallet_manager.create_account('password')
to_address = 'ANDfjwrUroaVtvBguDtrWKRMyxFwvVwnZD'
tx_hash = sdk.native_vm.ong().transfer(from_acct, to_address, 10, from_acct, 500, 20000)

Transfers amount of tokens to to_address synchronously.

approve

from ontology.sdk import Ontology

sdk = Ontology()
owner = sdk.wallet_manager.create_account('password')
spender = 'ANDfjwrUroaVtvBguDtrWKRMyxFwvVwnZD'
tx_hash = sdk.native_vm.ong().approve(owner, spender, 10, owner, 500, 20000)

Allows spender to withdraw from owner account multiple times, up to the value amount.

allowance

from ontology.sdk import Ontology

sdk = Ontology()
owner = 'Af1n2cZHhMZumNqKgw9sfCNoTWu9de4NDn'
spender = 'ANDfjwrUroaVtvBguDtrWKRMyxFwvVwnZD'
tx_hash = sdk.native_vm.ong().allowance(owner, spender)

Returns the amount which spender is still allowed to withdraw from owner.

transfer from

from ontology.sdk import Ontology

sdk = Ontology()
spender = sdk.wallet_manager.create_account('password')
owner = 'ANDfjwrUroaVtvBguDtrWKRMyxFwvVwnZD'
to_address = spender.get_address_base58()
tx_hash = sdk.native_vm.ong().transfer_from(spender, owner, to_address, 1, acct1, 500, 20000)

Transfers value amount of tokens from address owner to address to_address.

ONT ID

from ontology.sdk import Ontology

sdk = Ontology()
ont_id = sdk.native_vm.ont_id()

get public keys

from ontology.sdk import Ontology

sdk = Ontology()
ont_id = 'did:ont:APywVQ2UKBtitqqJQ9JrpNeY8VFAnrZXiR'
pub_keys = sdk.native_vm.ont_id().get_public_keys(ont_id)

Async ONT

from ontology.sdk import Ontology

sdk = Ontology()
ont = sdk.native_vm.aio_ont()

Async ONG

from ontology.sdk import Ontology

sdk = Ontology()
ong = sdk.native_vm.aio_ong()

Async ONT ID

from os import path

from ontology.sdk import Ontology

sdk = Ontology()
sdk.native_vm.aio_ont_id()

Async ONT

from os import path

from ontology.sdk import Ontology

sdk = Ontology()
ont = sdk.native_vm.aio_ont()

This module contains functions to manage Ontology digital asset Ontology Token which based on Native Contract.

name

from ontology.sdk import Ontology

sdk = Ontology()
token_name = await sdk.native_vm.aio_ont().name()

Returns the name of the token asynchronously.

symbol

from ontology.sdk import Ontology

sdk = Ontology()
token_symbol = await sdk.native_vm.aio_ont().symbol()

Returns the symbol of the token asynchronously.

decimals

from ontology.sdk import Ontology

sdk = Ontology()
decimals = await sdk.native_vm.aio_ont().decimals()

Returns the number of decimals the token uses asynchronously.

balance of

from ontology.sdk import Ontology

sdk = Ontology()
balance = await sdk.native_vm.aio_ont().balance_of('ANDfjwrUroaVtvBguDtrWKRMyxFwvVwnZD')

Returns the account balance of another account with owner address asynchronously.

transfer

from ontology.sdk import Ontology

sdk = Ontology()
from_acct = sdk.wallet_manager.create_account('password')
to_address = 'ANDfjwrUroaVtvBguDtrWKRMyxFwvVwnZD'
tx_hash = await sdk.native_vm.aio_ont().transfer(from_acct, to_address, 10, from_acct, 500, 20000)

Transfers amount of tokens to to_address asynchronously.

approve

from ontology.sdk import Ontology

sdk = Ontology()
owner = sdk.wallet_manager.create_account('password')
spender = 'ANDfjwrUroaVtvBguDtrWKRMyxFwvVwnZD'
tx_hash = await sdk.native_vm.aio_ont().approve(owner, spender, 10, owner, 500, 20000)

Allows spender to withdraw from owner account multiple times, up to the value amount.

allowance

from ontology.sdk import Ontology

sdk = Ontology()
owner = 'Af1n2cZHhMZumNqKgw9sfCNoTWu9de4NDn'
spender = 'ANDfjwrUroaVtvBguDtrWKRMyxFwvVwnZD'
tx_hash = await sdk.native_vm.aio_ont().allowance(owner, spender)

Returns the amount which spender is still allowed to withdraw from owner.

transfer from

from ontology.sdk import Ontology

sdk = Ontology()
spender = sdk.wallet_manager.create_account('password')
owner = 'ANDfjwrUroaVtvBguDtrWKRMyxFwvVwnZD'
to_address = spender.get_address_base58()
tx_hash = await sdk.native_vm.aio_ont().transfer_from(spender, owner, to_address, 1, acct1, 500, 20000)

Transfers value amount of tokens from address owner to address to_address.

Async ONG

from ontology.sdk import Ontology

sdk = Ontology()
ong = sdk.native_vm.aio_ong()

This module contains functions to manage Ontology digital asset Ontology Gas which based on Native Contract.

name

from ontology.sdk import Ontology

sdk = Ontology()
token_name = await sdk.native_vm.aio_ong().name()

Returns the name of the token asynchronously.

symbol

from ontology.sdk import Ontology

sdk = Ontology()
token_symbol = await sdk.native_vm.aio_ong().symbol()

Returns the symbol of the token asynchronously.

decimals

from ontology.sdk import Ontology

sdk = Ontology()
decimals = await sdk.native_vm.aio_ong().decimals()

Returns the number of decimals the token uses asynchronously.

balance of

from ontology.sdk import Ontology

sdk = Ontology()
balance = await sdk.native_vm.aio_ong().balance_of('ANDfjwrUroaVtvBguDtrWKRMyxFwvVwnZD')

Returns the account balance of another account with owner address asynchronously.

unbound

from ontology.sdk import Ontology

sdk = Ontology()
sdk.rpc.connect_to_test_net()
address = 'ANDfjwrUroaVtvBguDtrWKRMyxFwvVwnZD'
unbound_ong = await sdk.native_vm.aio_ong().unbound(address)

Unbound ONG is an amount of ONG which has not been added to your claimable ONG balance yet (since it only updates each time you make an ONT transaction in your wallet address). When an ONT transaction is made in your address, the claimable ONG balance will update (adding your unbound ONG amount to your claimable ONG amount).

transfer

from ontology.sdk import Ontology

sdk = Ontology()
from_acct = sdk.wallet_manager.create_account('password')
to_address = 'ANDfjwrUroaVtvBguDtrWKRMyxFwvVwnZD'
tx_hash = await sdk.native_vm.aio_ong().transfer(from_acct, to_address, 10, from_acct, 500, 20000)

Transfers amount of tokens to to_address asynchronously.

approve

from ontology.sdk import Ontology

sdk = Ontology()
owner = sdk.wallet_manager.create_account('password')
spender = 'ANDfjwrUroaVtvBguDtrWKRMyxFwvVwnZD'
tx_hash = await sdk.native_vm.aio_ong().approve(owner, spender, 10, owner, 500, 20000)

Allows spender to withdraw from owner account multiple times, up to the value amount.

allowance

from ontology.sdk import Ontology

sdk = Ontology()
owner = 'Af1n2cZHhMZumNqKgw9sfCNoTWu9de4NDn'
spender = 'ANDfjwrUroaVtvBguDtrWKRMyxFwvVwnZD'
tx_hash = await sdk.native_vm.aio_ong().allowance(owner, spender)

Returns the amount which spender is still allowed to withdraw from owner.

transfer from

from ontology.sdk import Ontology

sdk = Ontology()
spender = sdk.wallet_manager.create_account('password')
owner = 'ANDfjwrUroaVtvBguDtrWKRMyxFwvVwnZD'
to_address = spender.get_address_base58()
tx_hash = await sdk.native_vm.aio_ong().transfer_from(spender, owner, to_address, 1, acct1, 500, 20000)

Transfers value amount of tokens from address owner to address to_address.

NEO Contract

OEP-4

name

from ontology.sdk import Ontology

sdk = Ontology()
contract_address = '1ddbb682743e9d9e2b71ff419e97a9358c5c4ee9'
oep4 = sdk.neo_vm.oep4(contract_address)
token_name = oep4.name()

Returns the name of the token synchronously.

symbol

from ontology.sdk import Ontology

sdk = Ontology()
contract_address = '1ddbb682743e9d9e2b71ff419e97a9358c5c4ee9'
oep4 = sdk.neo_vm.oep4(contract_address)
token_symbol = oep4.symbol()

Returns the symbol of the token synchronously.

decimals

from ontology.sdk import Ontology

sdk = Ontology()
contract_address = '1ddbb682743e9d9e2b71ff419e97a9358c5c4ee9'
oep4 = sdk.neo_vm.oep4(contract_address)
decimals = oep4.decimals()

Returns the number of decimals the token uses synchronously.

total supply

from ontology.sdk import Ontology

sdk = Ontology()
contract_address = '1ddbb682743e9d9e2b71ff419e97a9358c5c4ee9'
oep4 = sdk.neo_vm.oep4(contract_address)
supply = oep4.total_supply()

Returns the total token supply synchronously.

balance of

from ontology.sdk import Ontology

sdk = Ontology()
contract_address = '1ddbb682743e9d9e2b71ff419e97a9358c5c4ee9'
oep4 = sdk.neo_vm.oep4(contract_address)
balance = oep4.balance_of('ANDfjwrUroaVtvBguDtrWKRMyxFwvVwnZD')

Returns the account balance of another account with owner address synchronously.

init

from ontology.sdk import Ontology

sdk = Ontology()
contract_address = '1ddbb682743e9d9e2b71ff419e97a9358c5c4ee9'
oep4 = sdk.neo_vm.oep4(contract_address)
founder = sdk.wallet_manager.create_account('password')
payer = sdk.wallet_manager.create_account('password')
tx_hash = oep4.init(founder, payer, 500, 20000)

Contract owner uses this interface to activate oep-4 token.

transfer

from ontology.sdk import Ontology

sdk = Ontology()
contract_address = '1ddbb682743e9d9e2b71ff419e97a9358c5c4ee9'
oep4 = sdk.neo_vm.oep4(contract_address)
from_acct = sdk.wallet_manager.create_account('password')
to_address = 'ANDfjwrUroaVtvBguDtrWKRMyxFwvVwnZD'
tx_hash = oep4.transfer(from_acct, to_address, 10, from_acct, 500, 20000)

Transfers amount of tokens to to_address synchronously.

transfer multi

from ontology.sdk import Ontology

sdk = Ontology()
contract_address = '1ddbb682743e9d9e2b71ff419e97a9358c5c4ee9'
oep4 = sdk.neo_vm.oep4(contract_address)
to_address = 'ANDfjwrUroaVtvBguDtrWKRMyxFwvVwnZD'
transfer_list = [[from_address1, to_address, 1], [from_address2, to_address, 1]]
signers = [from_acct1, from_acct2]
tx_hash = oep4.transfer_multi(transfer_list, signers, payer, 500, 20000)

Transfers amount of token from from-account to to-account multiple times synchronously.

approve

from ontology.sdk import Ontology

sdk = Ontology()
contract_address = '1ddbb682743e9d9e2b71ff419e97a9358c5c4ee9'
oep4 = sdk.neo_vm.oep4(contract_address)
owner = sdk.wallet_manager.create_account('password')
spender = 'ANDfjwrUroaVtvBguDtrWKRMyxFwvVwnZD'
tx_hash = oep4.approve(owner, spender, 10, owner, 500, 20000)

Allows spender to withdraw from owner account multiple times, up to the value amount.

allowance

from ontology.sdk import Ontology

sdk = Ontology()
owner = 'Af1n2cZHhMZumNqKgw9sfCNoTWu9de4NDn'
spender = 'ANDfjwrUroaVtvBguDtrWKRMyxFwvVwnZD'
tx_hash = oep4.allowance(owner, spender)

Returns the amount which spender is still allowed to withdraw from owner.

transfer from

from ontology.sdk import Ontology

sdk = Ontology()
contract_address = '1ddbb682743e9d9e2b71ff419e97a9358c5c4ee9'
oep4 = sdk.neo_vm.oep4(contract_address)
spender = sdk.wallet_manager.create_account('password')
owner = 'ANDfjwrUroaVtvBguDtrWKRMyxFwvVwnZD'
to_address = spender.get_address_base58()
tx_hash = oep4.transfer_from(spender, owner, to_address, 1, acct1, 500, 20000)

Transfers value amount of tokens from address owner to address to_address.

OEP-5

OEP-8

Async OEP-4

name

from ontology.sdk import Ontology

sdk = Ontology()
contract_address = '1ddbb682743e9d9e2b71ff419e97a9358c5c4ee9'
oep4 = sdk.neo_vm.aio_oep4(contract_address)
token_name = await oep4.name()

Returns the name of the token asynchronously.

symbol

from ontology.sdk import Ontology

sdk = Ontology()
contract_address = '1ddbb682743e9d9e2b71ff419e97a9358c5c4ee9'
oep4 = sdk.neo_vm.aio_oep4(contract_address)
token_symbol = await oep4.symbol()

Returns the symbol of the token asynchronously.

decimals

from ontology.sdk import Ontology

sdk = Ontology()
contract_address = '1ddbb682743e9d9e2b71ff419e97a9358c5c4ee9'
oep4 = sdk.neo_vm.aio_oep4(contract_address)
decimals = await oep4.decimals()

Returns the number of decimals the token uses asynchronously.

total supply

from ontology.sdk import Ontology

sdk = Ontology()
contract_address = '1ddbb682743e9d9e2b71ff419e97a9358c5c4ee9'
oep4 = sdk.neo_vm.aio_oep4(contract_address)
supply = await oep4.total_supply()

Returns the total token supply asynchronously.

balance of

from ontology.sdk import Ontology

sdk = Ontology()
contract_address = '1ddbb682743e9d9e2b71ff419e97a9358c5c4ee9'
oep4 = sdk.neo_vm.aio_oep4(contract_address)
balance = await oep4.balance_of('ANDfjwrUroaVtvBguDtrWKRMyxFwvVwnZD')

Returns the account balance of another account with owner address asynchronously.

init

from ontology.sdk import Ontology

sdk = Ontology()
contract_address = '1ddbb682743e9d9e2b71ff419e97a9358c5c4ee9'
oep4 = sdk.neo_vm.aio_oep4(contract_address)
founder = sdk.wallet_manager.create_account('password')
payer = sdk.wallet_manager.create_account('password')
tx_hash = await oep4.init(founder, payer, 500, 20000)

Contract owner uses this interface to activate oep-4 token asynchronously.

transfer

from ontology.sdk import Ontology

sdk = Ontology()
contract_address = '1ddbb682743e9d9e2b71ff419e97a9358c5c4ee9'
oep4 = sdk.neo_vm.aio_oep4(contract_address)
from_acct = sdk.wallet_manager.create_account('password')
to_address = 'ANDfjwrUroaVtvBguDtrWKRMyxFwvVwnZD'
tx_hash = await oep4.transfer(from_acct, to_address, 10, from_acct, 500, 20000)

Transfers amount of tokens to to_address asynchronously.

transfer multi

from ontology.sdk import Ontology

sdk = Ontology()
contract_address = '1ddbb682743e9d9e2b71ff419e97a9358c5c4ee9'
oep4 = sdk.neo_vm.aio_oep4(contract_address)
to_address = 'ANDfjwrUroaVtvBguDtrWKRMyxFwvVwnZD'
transfer_list = [[from_address1, to_address, 1], [from_address2, to_address, 1]]
signers = [from_acct1, from_acct2]
tx_hash = await oep4.transfer_multi(transfer_list, signers, payer, 500, 20000)

Transfers amount of token from from-account to to-account multiple times asynchronously.

approve

from ontology.sdk import Ontology

sdk = Ontology()
contract_address = '1ddbb682743e9d9e2b71ff419e97a9358c5c4ee9'
oep4 = sdk.neo_vm.aio_oep4(contract_address)
owner = sdk.wallet_manager.create_account('password')
spender = 'ANDfjwrUroaVtvBguDtrWKRMyxFwvVwnZD'
tx_hash = await oep4.approve(owner, spender, 10, owner, 500, 20000)

Allows spender to withdraw from owner account multiple times asynchronously, up to the value amount.

allowance

from ontology.sdk import Ontology

sdk = Ontology()
contract_address = '1ddbb682743e9d9e2b71ff419e97a9358c5c4ee9'
oep4 = sdk.neo_vm.aio_oep4(contract_address)
owner = sdk.wallet_manager.create_account('password')
spender = 'ANDfjwrUroaVtvBguDtrWKRMyxFwvVwnZD'
tx_hash = await oep4.approve(owner, spender, 10, owner, 500, 20000)

Returns the amount which spender is still allowed to withdraw from owner asynchronously.

transfer from

from ontology.sdk import Ontology

sdk = Ontology()
contract_address = '1ddbb682743e9d9e2b71ff419e97a9358c5c4ee9'
oep4 = sdk.neo_vm.aio_oep4(contract_address)
owner = 'ANDfjwrUroaVtvBguDtrWKRMyxFwvVwnZD'
to_address = spender.get_address_base58()
tx_hash = await oep4.transfer_from(spender, owner, to_address, 1, acct1, 500, 20000)

Transfers value amount of tokens from address owner to address to_address asynchronously.

Async OEP-5

Async OEP-8

Sig Server

FAQs

You can visit here to apply test tokens.

The Ontology protocol defines a way for people to interact with smart contracts and each other over a network. In order to have up-to-date information about the status of contracts, balances, and new transactions, the protocol requires a connection to nodes on the network. These nodes are constantly sharing new data with each other. The SDK is a python library for connecting to these nodes. It does not run its own node internally.