T-Bears is a simple tool developed by ICON Foundation https://icon.foundation/?lang=en and provides the Command Line Interface (CLI) to interact with the ICON Blockchain Network.
As explained in , T-Bears implements the JSON-RPC v3 APIs, called ICON JSON-RPC API. It makes communication with the ICON Blockchain Network simple and easy.
There is also a detailed usage guideline developed by ICON Foundation at . If you like you can go directly to www.icondev.io for background and detailed up-to-date information. Here is a short explanation about T-Bears and it's usage.
T-Bears Development Suite
Source:
Please note that to interact with the ICON Blockchain Network, you do not need to start T-Bears service. You can actually point to the remote ICON Blockchain Network using -u option [alternatively --node-uri], or simply update "uri" value in the tbears_cli_config.json file.
root@327360362eba:/work# more tbears_cli_config.json
{
"uri": "http://127.0.0.1:9000/api/v3",
"nid": "0x3",
"keyStore": null,
"from": "hxe7af5fcfd8dfc67530a01a0e403882687528dfcb",
"to": "cx0000000000000000000000000000000000000000",
"deploy": {
"stepLimit": "0x10000000",
"mode": "install",
"scoreParams": {}
},
"txresult": {},
"transfer": {
"stepLimit": "0xf4240"
}
}
The CLI commands listed below are simply ready to use after installing T-Bears.
$ tbears [-h] [-d] command ...
where;
| Command | Description |
|---|---|
keystore | Create a keystore file. Generate a private and public key pair using secp256k1 library. |
deploy | Deploy the SCORE. |
scoreapi | Query the list of APIs that the given SCORE exposes. |
call | Request icx_call with user input json file. |
sendtx | Request icx_send transaction with user input json file. |
txresult | Get transaction result by transaction hash. |
txbyhash | Get transaction info by transaction hash. |
transfer | Transfer ICX coins. |
balance | Get the balance of given address in loop. |
totalsupply | Query the total supply of ICX in loop. |
lastblock | Get last block info |
blockbyheight | Get block info using given block height. |
blockbyhash | Get block info using given block hash. |
Let's install T-Bears using docker, and send some queries to the ICON Testnet.
Now just install and run T-Bears with docker as explained in details at . The below command will download the image and run the container. On execution, configuration files and the test account
keyfile are generated.
Note as well 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
mainnet: Pulling from iconloop/tbears
27833a3ba0a5: Pull complete
ad5023f26108: Pull complete
35d55d99e929: Pull complete
c73ae40fc363: Pull complete
35b7d6938a3d: Pull complete
6be76c52c359: Pull complete
a37897d48931: Pull complete
5897d41d0939: Pull complete
66166b9c5f24: Pull complete
c383a2af0d9b: Pull complete
d52c0c48ae96: Pull complete
89f4fb08688b: Pull complete
Digest: sha256:3210c20ae9d65b2084e9a38c594ce6226551b61d956501bb9850dacf870faea3
Status: Downloaded newer image for iconloop/tbears:mainnet
[ ok ] Starting RabbitMQ Messaging Server: rabbitmq-server.
Made tbears_cli_config.json, keystore_test1 successfully
[2019-05-28 11:46:30 +0000] [703] [INFO] Starting gunicorn 19.9.0
[2019-05-28 11:46:30 +0000] [703] [INFO] Listening at: http://0.0.0.0:9000 (703)
[2019-05-28 11:46:30 +0000] [703] [INFO] Using worker: sanic.worker.GunicornWorker
[2019-05-28 11:46:30 +0000] [709] [INFO] Booting worker with pid: 709
[2019-05-28 11:46:30 +0000] [716] [INFO] Booting worker with pid: 716
[2019-05-28 11:46:30 +0000] [723] [INFO] Booting worker with pid: 723
[2019-05-28 11:46:30 +0000] [730] [INFO] Booting worker with pid: 730
[2019-05-28 11:46:30 +0000] [737] [INFO] Booting worker with pid: 737
[2019-05-28 11:46:30 +0000] [744] [INFO] Booting worker with pid: 744
[2019-05-28 11:46:30 +0000] [751] [INFO] Booting worker with pid: 751
[2019-05-28 11:46:30 +0000] [758] [INFO] Booting worker with pid: 758
[2019-05-28 11:46:30 +0000] [765] [INFO] Booting worker with pid: 765
[2019-05-28 11:46:30 +0000] [772] [INFO] Booting worker with pid: 772
[2019-05-28 11:46:31 +0000] [779] [INFO] Booting worker with pid: 779
[2019-05-28 11:46:31 +0000] [786] [INFO] Booting worker with pid: 786
[2019-05-28 11:46:31 +0000] [793] [INFO] Booting worker with pid: 793
[2019-05-28 11:46:31 +0000] [800] [INFO] Booting worker with pid: 800
[2019-05-28 11:46:31 +0000] [807] [INFO] Booting worker with pid: 807
[2019-05-28 11:46:31 +0000] [814] [INFO] Booting worker with pid: 814
[2019-05-28 11:46:31 +0000] [821] [INFO] Booting worker with pid: 821
[2019-05-28 11:46:31 +0000] [828] [INFO] Booting worker with pid: 828
[2019-05-28 11:46:31 +0000] [835] [INFO] Booting worker with pid: 835
[2019-05-28 11:46:31 +0000] [842] [INFO] Booting worker with pid: 842
[2019-05-28 11:46:31 +0000] [849] [INFO] Booting worker with pid: 849
[2019-05-28 11:46:31 +0000] [856] [INFO] Booting worker with pid: 856
[2019-05-28 11:46:31 +0000] [863] [INFO] Booting worker with pid: 863
[2019-05-28 11:46:31 +0000] [870] [INFO] Booting worker with pid: 870
[2019-05-28 11:46:31 +0000] [877] [INFO] Booting worker with pid: 877
Started tbears service successfully
root@9e0162b15989:/work#
Let's see the contents of tbears root directory:
root@9e0162b15989:/work# ls -lai
total 196
35915452 drwxr-xr-x 1 root root 4096 May 28 11:46 .
35915498 drwxr-xr-x 1 root root 4096 May 28 11:46 ..
35915453 drwxr-xr-x 3 root root 4096 May 22 09:16 .score
35915476 drwxr-xr-x 1 root root 4096 May 22 09:16 .statedb
35915489 drwxr-xr-x 1 root root 4096 May 22 09:16 exc
35915555 -rw-r--r-- 1 root root 675 May 28 11:46 keystore_test1
35915492 -rw-r--r-- 1 root root 153792 May 28 11:46 tbears.log
35915554 -rw-r--r-- 1 root root 386 May 28 11:46 tbears_cli_config.json
35654107 -rw-r--r-- 1 root root 1283 Apr 2 13:24 tbears_server_config.json
Now we will interact with the testnet. As stated above that you can pass the node API endpoint with the -u option [alternatively --node-uri], or simply update "uri" value in the tbears_cli_config.json file, to make T-Bears talk to the right node API endpoint. For the sake of simplicity, now we will invoke query methods that do not require a keystore file.
root@9e0162b15989:/work# 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
}
Query the built-in Governance SCORE https://github.com/icon-project/governance/blob/master/README.md APIs. Note that Governance SCORE is a built-in SCORE that manages adjustable characteristics of ICON network.
SCORE Address: cx0000000000000000000000000000000000000001
root@9e0162b15989:/work# 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": []
},
{
"type": "function",
"name": "addDeployer",
"inputs": [
{
"name": "address",
"type": "Address"
}
],
"outputs": []
},
...
root@9e0162b15989:/work# cat stepcost.json
{
"jsonrpc": "2.0",
"id": 1,
"method": "icx_call",
"params": {
"to": "cx0000000000000000000000000000000000000001",
"dataType": "call",
"data": {
"method": "getStepCosts"
}
}
}
root@9e0162b15989:/work# 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
}