Using ONT ID
Integrating ONT ID to centralized and decentralized systems
ONT ID can be integrated to centralized and decentralized systems alike to implement a decentralized identity and account mechanism with a rich variety of other functions. The Ontology framework is flexible in terms of the languages that are supported. There are several public SDKs that are available for the community to work and experiment with.
ONT IDDevelopers can glance over ONT ID specifications to get a better understanding of the technical architecture.
The ONT ID protocol has been implemented on the Ontology chain using native smart contracts. API methods can be invoked to carry out ONT ID related actions such as registration, cancellation, attribute modification, etc. Follow the link below to navigate to the ONT ID contract API reference.
ONT ID Contract APIIntegrating the ONT ID framework is a simple enough process. The major steps have been illustrated below.
Use OWallet tool to create a new wallet
OWallet is a wallet tool that can be used to work with Ontology wallets and carry out staking on the Ontology network. You can download the latest version of OWallet by following this link.
Download and install OWallet, and then in the main 'wallets' window click on the '+' icon. Follow the prompts to create a new Ontology wallet. You'll need this perform any interactions with the Ontology chain.
You'll be able to see your wallet address on the top after successfully creating your wallet and exporting the .dat wallet file.
Fetch testnet ONG
Performing on-chain actions consumes ONG in the form of gas/transaction costs. Follow this link to apply for testnet ONG that will come in handy when developing on and working within the Ontology ecosystem. Use your wallet address to apply for testnet ONG tokens on the portal.
Set up SDK environment
SDKsAfter obtaining testnet ONG, you're all set to start working with the Ontology framework. The SDKs illustrated below can be used to implement ONT ID related functions. But first, we must set up the environment to use the SDK libraries in your project. Execute the commands specified to set up the SDK.
Golang SDK
1. Clone the SDK library
2. Install dependencies
Run the following command to enable Go modules in your environment in case they aren't already enabled.
And then run the following command to install the necessary dependencies.
Java SDK
1. Clone the SDK library
2. Install dependencies
TypeScript SDK
1. Clone the SDK library
2. Install the necessary dependencies
Initialize and invoke SDK
Once the environment is set up, next up would be initializing the respective SDK. The process has been briefly described individually for each SDK using the testing package that contains several useful demos for reference. Roughly speaking the sequence is as follows:
Instantiate and initialize the SDK
Create a wallet object that will be used when executing methods and making API calls
Create a new ONT ID linked to the account
Register the action on chain by storing the DID document into the contract
Add attributes if necessary
Fetch ONT ID and respective attribute related details
All the sample code used below is used for the purpose of illustration and has been taken from test or demo files that come with the SDK. The name of the file has also been specified with each code snippet.
Move the newly created wallet to the SDK main directory before proceeding to initialize the SDK
Go SDK
One way to initialize an SDK instance would be:
Next we can generate an ONT ID and start working with it. The sample code illustrates how to execute certain basic operations.
The addresses for the currently active Polaris testnet nodes can be found here.
For a more detailed and practical test case, you can refer to cred_test.go.
Java SDK
To instantiate and initialize an SDK object:
The above method is defined in the NativeOntIdTest class. You can refer to the source file and run the test respective test cases.
Sample code that illustrates basic operations:
You can refer to the NativeOntIdTxTest.java in the test directory of the SDK to find and experiment with the test class methods.
TypeScript SDK
A wide variety of functions operations can be performed with ONT ID by calling the public API exposed from the native contract deployed on the Ontology chain. The API reference for the contract and the chain itself is available here.
Last updated