Advanced guide to CENNZnet.io

Advanced guide to CENNZnet.io

Translations of this article can be found here:

CENNZnet.io is a web portal and wallet where you can interact with CENNZnet’s blockchain network. In this guide, we will look specifically at the tools within the Advanced section of the web portal. These tools are most useful for DApp developers building on CENNZnet.

We recommend before exploring this section, you familiarise yourself with the basics of CENNZnet.io, you can do this using the intro guide to CENNZnet.io here.

This article will guide you through the functions available in the Advanced section of the cennznet.io. We will look at:

  • Development notes: explaining gas fees and connecting to the development node.
  • Chain state: reading data from the chain, including storage items, constants and raw storage.
  • Extrinsics: submitting transactions to modify data on the chain.
  • Sudo: submitting transactions that require super user access. (Available for development nodes only)
  • Settings: cennznet.io settings
  • Tool box: additional helper functionalities for developers
  • JavaScript: trying the CENNZnet JavaScript API with code examples.
  • Wiki: a link to CENNZnet’s technical docs hosted on Github.

 

Before you start: Development notes

Before we go through each page in the Advanced area of cennznet.io, there are two things to note for developers: gas fees and connecting to a development node.

 

1. Gas fees

When you request an operation on the blockchain, there may be a fee for the computation required. This fee is called the gas fee.

In CENNZnet, reading data from the storage is free, whereas writing to the storage costs. In CENNZnet, the gas fee is paid in the currency CPAY, as part of our dual token economy. You can understand more about how this system works in detail here.

To avoid paying gas fees during development, you can use a development node. The instructions for setting up a development node can be found in the next section of this article under ‘Connecting to a development node’.

 

2. Connecting to a development node

A development node comes with test accounts that own billions of CENNZ and CPAY. This allows you to test your DApps without paying real money.

By default, cennznet.io will connect to the MainNet, which is the CENNZnet production blockchain called Azalea. To use a development node, you will need to connect to it using these steps:

1.Start a development node

  • Install Docker
  • Run a development node using a docker command:
docker run -p 9944:9944 -it --rm  cennznet/cennznet:1.2.2 --dev --ws-external

2. Connect cennznet.io to the local development node

  • Navigate to Advanced -> Settings
  • Select “Local Node” from the first drop-down menu
  • Click “Save & Reload”

 

Chain state

The Chain state page allows you to read data from the chain using RPC (Remote Procedure Call). Operations in the chain state page are free of gas fees.

There are 3 types of chain states that you may query, which can be seen in the tabs at the top of the screen:

  1. Storage: Query runtime storage items defined in the runtime modules.
  2. Constants: Query constant variables defined in the runtime modules.
  3. Raw storage: Query directly from the persistent key-value data store of the blockchain.

 

Storage

In the Storage tab you can subscribe to updates on a storage by selecting the query and the parameters if required from the drop down menus and then clicking on the blue “+” button on the right hand side of your screen.

Once you have clicked the “+” button, an entry will appear below the dropdown menus. This item shows the value that you queried and updates in real-time.

You can subscribe to as many items as you like. To unsubscribe, or remove the item, click the orange “x” button next to the desired query.

 

An example use case

An example of a likely use case of the storage query function is checking Charlie’s CENNZ balance:

  • Select genericAsset and freeBalance
  • In AssetId, type “16000”, which is the AssetID for CENNZ in the dev chain
  • Choose FERDIE for the AccountId
  • Press the plus button.

Note: to get the AssetID of a type of token, you can use the RPC method genericAsset.registeredAssets(). Instructions for using RPC methods are in the RPC calls section of this article.

 

Reference for Storage methods

To learn more about available storage methods, please reference the linked GitHub page here.

 

Constants

This tab works in exactly the same way as Storage. The only difference is that the values queried in the Storage tab update as things change on the chain, whereas the values queried in the constants page will always be the same no matter what happens on the chain.

 

Raw storage

CENNZnet has a key-value data store, which is the persistent storage of the blockchain implemented as a database-backed modified Merkle tree. This provides fast data insertion and retrieval to the blockchain. The Raw storage tab allows you to query the data store directly.

Runtime storage, which is exposed by the Storage tab, is a layer of abstraction on top of this key-value data store. Typically, the Storage and Constants tabs should suffice your daily needs as a DApp developer.

The Raw storage tab may become useful in some edge cases, where you know the key for an item that went missing from the API, for example, when a runtime module was removed, but it still has data stored on the chain.

Learn more about raw storage here.

 

Extrinsics (only visible once you have set up an account on CENNZnet)

Extrinsic data refers to data carried inside blocks that are external to the blockchain; this means it is not used to support the blockchain’s functioning. Extrinsic methods are the runtime’s callable methods which modify extrinsic data.

The Extrinsics page exposes all extrinsic methods of the runtime modules in CENNZnet. This allows you to submit transactions in order to modify data on the chain. Submitting transactions incurs gas fees.

To call an extrinsic method, you first select the account that will be used to call it, the module and method you want to call, and specify the parameters if required.

Note: some of the methods available on this page have permission restrictions on the calling account. For example, rewards -> setInflationRate can only be called successfully if you have sudo access.

 

Reference for Extrinsic methods

To learn more about potential extrinsic methods, please reference the linked GitHub page here.

 

Sudo (only available on dev nodes)

The Sudo page exposes the same methods as extrinsics. However, by calling the methods from this page you do so as a superuser, which means you have more permissions.

Note: this is an advanced tool and is only required when you are developing a custom chain. It can let you perform actions on the chain, such as runtime upgrades.

 

Settings

The Settings page has 2 tabs,

  • General: Provides access to the settings for cennznet.io.
  • Developer: An advanced tool for working with a custom chain. This allows you to expose additional types to cennznet.io, so that cennznet.io can encode and decode these types.

Detailed descriptions are available in the help menu, which can be opened if you click on the “?” button.

 

Toolbox

The Toolbox page provides the following helper functionalities:

  • RPC calls: Access all RPC calls exposed by the CENNZnet API.
  • Hash data: Get the Blake2 hash of a given piece of text.
  • Sign message: Get the signature of supplied data signed by one of your accounts.
  • Verify signature: Verify if a signature for a given piece of data and account.

 

RPC calls

RPC calls allow you to interact with a node to query and to submit or retrieve chain information. Some RPC calls also allow node operators to do simple admin tasks.

You can also read node specific info for example. pending transactions, client version. You can also retrieve values that require calculation by the node, e.g. CENNZX buy and sell prices.

 

Example usage

Getting Asset IDs:

  • Select genericAsset and registeredAssets()
  • Press Submit RPC call
  • The AssetIDs are shown as the key in the returned key-value pairs.

 

Reference for RPC methods

To learn more about potential RPC methods, please reference the linked GitHub page here.

 

Hash data

Hash data is a crypto utility that gives you the Blake2b hash of a given piece of text. Blake2b is a very fast cryptographic hash function that’s used in CENNZnet.

 

Sign message

This tab lets you generate a signature for a given set of data using an account that you own.

 

Verify signature

This tab allows you to verify if a message has been signed by an account. For example, you can check to see if the signature of a transaction was signed by an account.

You can select an account from your address book, or paste the address into the first dropdown menu.

 

Javascript

The Javascript page is a great place to try the CENNZnet API.

Here you can select a code example from the drop down menu, make changes if you wish, and then execute the code by pressing the play button on the top right corner of the text editor. The console logs will be shown on the right hand side.

There are 4 types of code examples:

  • RPC: Demonstrates how to use the RPC methods through the API. They use the ‘api.rpc’ methods.
  • Storage: Demonstrates how to query runtime module storage without performing calculations. They use the `api.query` methods, e.g. api.query.genericAsset.freeBalance().
  • Consts: Demonstrates how to access the constant variables through the API.
  • Extrinsics: Demonstrates how to use the extrinsic methods through the API.

Technical references of the API methods are available in the Wiki.

 

Github

The Github button takes you to the Github repo of our Javascript API.

 

Wiki

The Wiki button takes you to CENNZnet’s wiki, which is hosted on Github. Here you can find technical documentation and guides.