ICON Developer Portal

ICON Developer Portal

ICON Network is a decentralized smart contract protocol based on ‘loopchain’, a high-performance blockchain engine. The ICON Network aims to remove barriers among different blockchains and allow them to exchange values without intermediaries. By realizing this goal, ICON will realize the mass adoption of blockchain technology and Hyperconnect the World.

Get Started

CLI (T-Bears)

T-Bears provides the command line interface to interact with the ICON network. It implements all the JSON-RPC v3 APIs. T-Bears CLI is a handy tool to test your SCORE and DApp ideas quickly before writing a complete code using SDK.

For a detailed usage guideline, please see the T-Bears SCORE & Other JSON-RPC API Commands in T-Bears CLI Reference.

To interact with the ICON network, you don’t need to start T-Bears service.
Instead, point to the remote ICON network using -u option, or update uri value in the tbears_cli_config.json file.
The CLI commands listed below are ready to use after installing T-Bears.

$ tbears [-h] [-d] command ...
commanddescription
keystoreCreate a keystore file. Generate a private and public key pair using secp256k1 library.
deployDeploy the SCORE.
scoreapiQuery the list of APIs that the given SCORE exposes.
callRequest icx_call with user input json file.
sendtxRequest icx_sendTransaction with user input json file.
txresultGet transaction result by transaction hash.
txbyhashGet transaction info by transaction hash.
transferTransfer ICX coins.
balanceGet the balance of given address in loop.
totalsupplyQuery the total supply of ICX in loop.
lastblockGet last block info
blockbyheightGet block info using given block height.
blockbyhashGet block info using given block hash.

Prerequisite

  • Docker

We will use docker in this document to install T-Bears, however, native install on Mac or Linux is also possible. For the complete installation guideline please see the T-Bears Installation.

Installation

We will install T-Bears using docker, and send some queries to the testnet.

The below command will download the image and run the container.
On execution, configuration files and the test account keystore file are generated.
Note that you should not use the generated keystore to sign your transaction on other networks, only use the keystore_test1 file on the local T-Bears environment.

$ docker run -it --name tbears-container -p 9000:9000 iconloop/tbears:mainnet
Unable to find image 'iconloop/tbears:mainnet' locally
latest: Pulling from iconloop/tbears
124c757242f8: Pull complete 
2ebc019eb4e2: Pull complete 
dac0825f7ffb: Pull complete 
82b0bb65d1bf: Pull complete 
ef3b655c7f88: Pull complete 
abf2199d9d18: Pull complete 
dd59e2bf156a: Pull complete 
02a056d8159d: Pull complete 
Digest: sha256:cbec58fc5ae717934b510794d54bab6095de03eac013cc89a34ab1a8899e1813
Status: Downloaded newer image for iconloop/tbears:mainnet
 * Starting RabbitMQ Messaging Server rabbitmq-server                    [ OK ] 
Made tbears_cli_config.json, tbears_server_config.json, keystore_test1 successfully
Started tbears service successfully
[email protected]:/tbears#

Using the CLI

Now we will interact with the testnet to see if the installation was complete. [Testnet Info].
You can pass the node API endpoint to the -u option to make T-Bears talk to the right one.
For the sake of simplicity, we will invoke query methods that do not require a keystore file.

  • Sample query 1 : Get the genesis block of the testnet. You can verify the network ID in the response message.
    Make sure block height is in hexadecimal format.
[email protected]:/tbears# tbears blockbyheight -u https://bicon.net.solidwallet.io/api/v3 0x0
block info : {
    "jsonrpc": "2.0",
    "result": {
        "version": "0.1a",
        "prev_block_hash": "",
        "merkle_tree_root_hash": "831da0a095133e4a0dfd7b6527e8d1851a474dfface9748ec2fe2c6464d345ed",
        "time_stamp": 0,
        "confirmed_transaction_list": [
            {
                "message": "{X}iconNet",
                "accounts": [
                    {
                        "balance": "0x2961fff8ca4a62327800000",
                        "name": "god",
                        "address": "hx5a05b58a25a1e5ea0f1d5715e1f655dffc1fb30a"
                    },
                    {
                        "balance": "0x0",
                        "name": "treasury",
                        "address": "hx1000000000000000000000000000000000000000"
                    },
                    {
                        "balance": "0x2961fff8ca4a62327800000",
                        "name": "test_1",
                        "address": "hx6e1dd0d4432620778b54b2bbc21ac3df961adf89"
                    }
                ],
                "nid": "0x3"
            }
        ],
        "block_hash": "974e2a8fbefad82b30af0ebfd9939314a53cd7ce3c54b19079b59501122987fe",
        "height": 0,
        "peer_id": "",
        "signature": ""
    },
    "id": 1
}
[email protected]:/tbears# tbears scoreapi -u https://bicon.net.solidwallet.io/api/v3 cx0000000000000000000000000000000000000001
SCORE API: [
    {
        "type": "function",
        "name": "acceptScore",
        "inputs": [
            {
                "name": "txHash",
                "type": "bytes"
            }
        ],
        "outputs": []
    },
    {
        "type": "function",
        "name": "addAuditor",
        "inputs": [
            {
                "name": "address",
                "type": "Address"
            }
        ],
        "outputs": []
    },
    ...
  • Sample query 3 : Let's check the current step cost for each operation.
[email protected]:/tbears# cat stepcost.json 
{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "icx_call",
    "params": {
        "to": "cx0000000000000000000000000000000000000001",
        "dataType": "call",
        "data": {
            "method": "getStepCosts"
        }
    }
}
[email protected]:/tbears# tbears call -u https://bicon.net.solidwallet.io/api/v3 stepcost.json
response : {
    "jsonrpc": "2.0",
    "result": {
        "default": "0x186a0",
        "contractCall": "0x61a8",
        "contractCreate": "0x3b9aca00",
        "contractUpdate": "0x5f5e1000",
        "contractDestruct": "-0x11170",
        "contractSet": "0x7530",
        "get": "0x0",
        "set": "0x140",
        "replace": "0x50",
        "delete": "-0xf0",
        "input": "0xc8",
        "eventLog": "0x64",
        "apiCall": "0x0"
    },
    "id": 1
}

References

Updated about a year ago

CLI (T-Bears)


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.