1) SCORE is a smart contract platform on ICON that allows developers to write, deploy and interact with smart contracts using Python.
2) T-Bears is a SCORE development suite that provides tools to develop, test, deploy and interact with SCORE contracts. It includes a CLI, sample templates and supports local emulation of contract execution.
3) SCORE contracts are deployed to and run on the ICON blockchain. They can store data on-chain, be invoked by transactions to update state, and trigger events.
2. 2
What is a Smart Contract?
● A smart contract is a computer protocol intended to digitally
facilitate, verify, or enforce the negotiation or performance of
a contract. - from Wikipedia
● SCORE (Smart Contract on Reliable Environment)
○ A collection of code (functions) and data (states) that
resides at a specific address on the blockchain.
○ Written in Python - easy learning curve
○ Can use state DB abstractions
■ VarDB, DictDB, ArrayDB
○ SCORE must follow sandbox policy.
3. 3
SCORE Model
● State transition machine
● State transition by transaction
● Sandbox policy
○ Should be deterministic
○ No random operation
○ No network call
○ No system call
○ No long-running operation
● Address starts with ‘cx’
SCORE
def __init__(self, db)
super().__init__(db)
...
def on_install(self)
...
def transfer(self, _from, _to,
_value)
...
VarDB / DictDB / ArrayDB
State DB (leveldb)
4. 4
T-Bears (SCORE Development Suite)
● Provide a SCORE project template to help you start right
away
● Can test your SCORE on a locally emulated SCORE
execution environment
● When ready, can deploy SCORE onto the ICON network
through CLI (command-line interface) command
● Provide additional CLI commands to interact with the ICON
network (implements JSON-RPC v3 APIs)
● https://github.com/icon-project/t-bears
6. 6
T-Bears (SCORE Development Suite)
● Install on local file system
● Using Docker
$ virtualenv -p python3.6 .venv
$ source .venv/bin/activate
(.venv) $ pip install tbears
(.venv) $ tbears start
$ docker run -it -p 9000:9000 iconloop/tbears
7. 7
T-Bears (SCORE Development Suite)
● T-Bears CLIs
init - Initialize a SCORE project
keystore - Create a keystore file
deploy - Deploy the SCORE
scoreapi - Query the list of APIs that SCORE exposes
call - Request icx_call
sendtx - Request icx_sendTransaction
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
...
(* 1 ICX == 10 ^ 18 loop)
8. 8
SCORE Syntax
● IconScoreBase
○ The main entry class must inherit IconScoreBase
● __init__
○ a Python init function (constructor)
● on_install
○ Called when the SCORE is deployed
● @external
○ Can be called from outside the SCORE
● @payable
○ Permitted to receive incoming ICX coins
● @eventlog
○ Include logs in its TxResult as 'eventlogs'
9. 9
SCORE Syntax
● fallback
○ Reserved function executed whenever the SCORE
receives plain ICX coins without data
● VarDB, DictDB, ArrayDB
○ State DB abstractions
○ VarDB - simple key-value state
○ DictDB - dictionary-base store like Python dict
○ ArrayDB - one dimensional array
● Score call (InterfaceScore)
○ Used to invoke other SCORE's function
● https://icon-project.github.io/score-guide/
10. 10
SCORE Sample - Token standard (IRC2)
● Project initialization
➔ sample_token: a project folder
➔ SampleToken: main entry class name
● https://github.com/icon-project/IIPs/blob/master/IIPS/iip-2.md
● https://github.com/sink772/IRC2-token-standard
$ tbears init sample_token SampleToken
(.venv) $ tbears init sample_token SampleToken
Initialized tbears successfully
(.venv) $ ls sample_token/
__init__.py package.json sample_token.py
15. 15
Interacting with SCORE
● JSON-RPC API v3
○ https://github.com/icon-project/icon-rpc-
server/blob/master/docs/icon-json-rpc-v3.md
● icx_call
○ Call a read-only external function of SCORE
○ Does not make state transition
● icx_sendTransaction
○ Transfer designated amount of ICX coins from 'from'
address to 'to' address
○ Install a new SCORE
○ Invoke a external function of SCORE
○ Transfer a message
○ Cause state transition
18. 18
Transaction Fee
● Fee = usedStep * stepPrice
○ stepPrice = ICX exchange rate (1 ICX == 10 ^ 8 Step)
○ usedStep will be increased whenever some operations
are performed (DB access, function call, input params
size, log write, …)
● stepLimit = maximum Step allowance that can be used by
the transaction
● If (usedStep > stepLimit), then tx fails and fee (stepLimit *
stepPrice) is deducted.
● If (your balance < stepLimit * stepPrice), then tx fails
immediately.
● ICON Transaction Fee and SCORE Operation Policy
19. 19
We are Hiring!
● All levels of engineers are welcome.
● If you are interested in a career at ICON SF Office, please
send your resume to sf@icon.foundation
Thank you!