ICON – TCP / IP of Blockchain platform?

Tram Ho

1. Introduction

ICON is a Blockchain 2.0 platform (which has many similarities with Ethereum). ICON runs smart contracts with a Delegated Proof-of-Stake (BFT-DPoS) consensus protocol, a cryptocurrency on the ICON network called ICX .

The goal of the ICON development team in the future is to connect blockchain networks with each other, making them easy to exchange assets as well as data. There is an example that the ICON development team gave to compare the interconnection of blockchain networks, like the advent of the TCP / IP protocol suite that connects private networks to each other into the Internet. Global. ICON wants them to be the TCP / IP of Blockchain

About the world is an introduction video about ICON from the developer team

2. Some basic concepts

Account

Like Ethereum, ICON also has 2 types of accounts:

  • Externally Owned Accounts: Starting with hx , 20 hex bytes in length
  • Smart contract accounts: Start with cx , 20 hex bytes in length. No private key available.

Deal

Types of transactions on ICON

  • Transfer ICX
  • Save data to blockchain
  • Deploy or update SCORE
  • Change the state of SCORE

Note : Smart contract on ICON is called SCORE

The parameters when executing a transaction:

  • from : Address to create transaction
  • to : Transaction receiving address (When deploying, the receiving address is cx0000000000000000000000000000000000000000 )
  • value : The amount of ICX sent
  • stepLimit : Maximum number of steps a transaction can take (similar to gasLimit in Ethereum)
  • time stamp : The time to create a transaction
  • nonce : Transaction number of sending account (similar to nonce in Ethereum)
  • nid : Network ID (Distinguishing between mainnet, testnet)
  • data type : Helps distinguish transaction types. Includes 3 values call , deploy and message . With a normal ICX transfer, the data type is ignored.
  • data : Transaction content (can be the parameters passed to call the function in the contract)
  • signature : The digital signature of the sender of the transaction
  • transaction hash : The hash value that identifies the transaction

Transaction fee

Step is the unit of measurement for calculating transaction fees on the ICON network. The number of steps a transaction takes depends on the amount of compute resources it takes to execute the transaction. Initial Rate, 1 ICX = 100,000,000 Step . This rate can be changed if the ICX price rises too high or is dropped very low.

Formula for calculating step

Step = max (∑ βiSi + C, C)

Note : The maximum number of steps a transaction can consume is 2.5 billion steps

With:

  • Si is the number of times a particular call comes to the smart contract.
  • βi is the number of steps that will be consumed with each specific call.
  • C is the minimum number of steps a transaction needs to pay (Constant with a value of 100,000)

Below are 2 tables that describe the possible values ​​of Si and the step values ​​consumed with each corresponding call to the contract.

Policy support transaction fees for users

Normally, when making a transaction, the user will bear the full cost. With ICON, the development team designed a feature that allows contract owners to support part or all of the transaction costs when users call their contracts.

Percentage of support fees ranges from 0 – 100% (meaning fees may not be subsidized). If the contract developer wants to support fees for users, they must send an amount of ICX in advance to the contract so that when the user calls, this amount of ICX will be deducted from the user’s transaction fee depending on the rate.

Virtual Step

Virtual Step is the new fee system of the ICON network for contract owners. It is created monthly corresponding to the number of ICX sent to the contract and the period of time ICX is deposited into that contract. In addition to supporting fees for users using ICX , SCORE owners can pay fees in Virtual Step . This helps contract owners reduce part of the cost burden as well as encourage the higher percentage of support fees for users.

Some features:

  • Virtual Step and Step have a 1: 1 ratio
  • Virtual Step is created every 1,296,000 blocks (1 month). At that time, unused Virtual Steps will expire.
  • Virtual Step cannot be moved anywhere.
  • Support fee for users will spend Virtual Step first, if the Virtual Step runs out, then ICX will be spent

Calculating the Virtual Step

  • When sending ICX into the contract, it is necessary to set the deposit amount and the deposit period.
  • Delivery times can be set from a minimum of 1 month to a maximum of 24 months.
  • Minimum deposit amount is from 5,000 ICX up to maximum 100,000 ICX.

Depending on the short or long deposit period, the number of viral steps received after each month will vary:

For example:

  • Send 10,000 ICX in with a period of 1 month. Each month receiving 80,000,000,000 Virtual Step, equivalent to 8% of the 10,000 deposit amount, is 800 ICX.
  • Send 10,000 ICX in with a 24-month period. Each month receives 202,400,000,000 Virtual Step, equivalent to 20.24% of the deposit amount of 10,000 ICX.

Note : Contract holders will be subject to a penalty if they withdraw their deposited ICX before the end of the predetermined period. The fine is the total number of Virtual Steps used in the previous period.

ICON nodes

ICON nodes have 3 types

  • Peer: can participate in consensus protocol, can create new block on the network.
  • Citizen: Blockchain data synchronization and transaction forwarding to Peer.
  • Light: Save the block header of the network, perform the task of transaction verification.

3. Write smart contract

SCORE on ICON is written in Python language.

First, you need to install the tbears tool, tbears is a tool to initiate, deploy and interact with smart contracts on the ICON network (similar to the truffle on Ethereum). The tbears settings can be found here

Hello world

We’ll start with the simplest smart contract

Step 1 : Initialization

In the newly created folder hello , we will see 3 files

  • __init.py__ : Initially empty, this file helps the Python interpreter to recognize this folder as a package.
  • hello.py : The main FIle, which contains the logic of the contract
  • package.json : This file contains the basic information of the contract such as version, name, …

Implement Token

ICON supports implementation of many different token standards (with reference to the ERC standards of Ethereum), ICON ‘s token standards are defined here.

In this example, we will try implementing the standard IRC-2 token, which is the Fungibles Token form (IRC-2 is a reference to the ERC-20 and ERC-223 standard of Ethereum). The definition of the IRC-2 standard can be found here

Deploy

Contract is finished, now let’s learn about deploying them to testnet Yeouido with tools tbears.

B1 : Create a deploy config file

deploy_hello.json

deploy_sample_token.json

Ham on_install in contract SampleToken need to pass two arguments to _decimals and _initialSupply to execute.

B2 : Create wallet

We install the ICONex extension (eg Metamask) to create an address on the ICON network. With Chrome browser, you can here

Click on the new wallet creation section, you will download the keystore file and change the extension to a json file, such as keystore.json .

B3 : Deploy to testnet with tbears

The current directory we have

Before deploying we need faucet ICX for the account on testnet at

Transaction hash will be returned after deploying, we can check whether the transaction was successful or not as well as the contract’s address on bicon.tracker.solidwallet.io page.

4. ICON SDK (Javascript SDK)

Each ICON node provides JSON-RPC APIs. To interact with an ICON node, we can either send raw JSON-RPC requests or use the ICON SDK in many different languages. ICON officially supports Java, Python, JavaScript and Swift. In the framework of the article, we will just learn about 1 type of SDK that is the Javascript SDK.

Setting

Javascript SDK is integrated in a node.js package, making it easy to install and use

Install via npm

Or CDN link

Using the SDK to interact with the deployed contract

Create an sdk directory and create an environment variable

With the readonly functions, when called, there is no need to sign a transaction

For other functions, when we call through the SDK we need to do the signing

Run:

Note : To learn the functions of the modules in the Javascript SDK, you can refer to Github above.

References

ICON Documentation

Share the news now

Source : Viblo