Version 0.1
Click here to view the course video
Rpc API: http://dev-docs.ont.io/#/docs-en/API/01-rpc_api
Restful API: http://dev-docs.ont.io/#/docs-en/API/02-restful_api
Websocket API: http://dev-docs.ont.io/#/docs-en/API/03-websocket_api
Toolkit introduction:
Open SmartX, create a python project and select "Hello World" template.
Click the "Restful" button on the panel and then enter the "Restful" panel.
There are 23 restful APIs. You can select the network and then use the API. For example, we select Main-Net and click "Send" button of the first API. Then we receive the result as shown below.
You can get the code of Rpc API at the following address.
Rpc code: https://github.com/ontio/ontology-python-sdk/blob/master/ontology/rpc/rpc.py
Request parameter description:
Response parameter description:
For example, If you call the "getbestblockhash" API, the following request will be sent.
{"jsonrpc": "2.0","method": "getbestblockhash","params": [],"id": 1}
And you will receive the following response.
{"desc":"SUCCESS","error":0,"jsonrpc": "2.0","id": 1,"result": "773dd2dae4a9c9275290f89b56e67d7363ea4826dfd4fc13cc01cf73a44b0d0e"}
If the execution fails, you will receive the error code.
Error code instruction
Field | Type | Description |
---|---|---|
0 | int64 | SUCCESS |
41001 | int64 | SESSION _ EXPIRED: invalided or expired session |
41002 | int64 | SERVICE _ CEILING: reach service limit |
41003 | int64 | ILLEGAL _ DATAFORMAT: illegal dataformat |
41004 | int64 | INVALID _ VERSION: invalid version |
42001 | int64 | INVALID _ METHOD: invalid method |
42002 | int64 | INVALID _ PARAMS: invalid params |
43001 | int64 | INVALID _ TRANSACTION: invalid transaction |
43002 | int64 | INVALID _ ASSET: invalid asset |
43003 | int64 | INVALID _ BLOCK: invalid block |
44001 | int64 | UNKNOWN _ TRANSACTION: unknown transaction |
44002 | int64 | UNKNOWN _ ASSET: unknown asset |
44003 | int64 | UNKNOWN _ BLOCK: unknown block |
45001 | int64 | INTERNAL _ ERROR: internel error |
47001 | int64 | SMARTCODE _ ERROR: smartcode error |
pip install ontology-python-sdk
from ontology.ont_sdk import OntologySdk
Now, we use the Private-Net. So we set Rpc address to http://127.0.0.1:20336.
sdk = OntologySdk()rpc_address = 'http://127.0.0.1:20336'sdk.rpc.set_address(rpc_address)
version = sdk.rpc.get_version()count = sdk.rpc.get_node_count()print(version)print(count)
v1.0.51
Please feel free to give any suggestionContact: Yue ZhaoWechat: 16621171248Email: messixaviinsta0303@163.com