Slide 11
Slide 11 text
Smart Contract in Practice
$ tbear init candypoint CandyPoint
$ cat candypoint/candypoint.py
from linkservice import *
TAG = 'CandyPoint'
class CandyPoint(LinkContractBase):
def __init__(self, db: LinkServiceDatabase) -> None:
super().__init__(db)
def on_install(self) -> None:
super().on_install()
def on_update(self) -> None:
super().on_update()
@external(readonly=True)
def hello(self, name:str) -> str:
return "Hello, %s" % name
$ tbear deploy –k [keystore] candypoint
transaction hash: [txhash]
$ tbear txresult [txhash]
”scoreAddress": ”[contract_address]",
$ cat call-hello.json
{
"jsonrpc": "2.0",
"method": "icx_call",
"params": {
"from": ”[address_in_keystore]",
"to": ”[contract_address]",
"dataType": "call",
"data": {
"method": "hello",
"params": { "name": "Takami Torao" }
}
},
"id": 1
}
$ tbear call call-hello.json
response : {
"jsonrpc": "2.0",
"result": "Hello, Takami Torao",
"id": 1
}
Smart Contract JSON to call method hello of CandyPoint