泰岳区块链-传统应用如何和链交互(一)
区块链既然是一个分布式的存储数据库,那么链外的应用应该如何访问链上数据呢?链外数据又如何上链呢?
1、链外的应用应该如何访问链上数据呢?
首先,我们需要了解一下,区块链对外的接口。
其实:区块链系统里面有一个RPC服务,里面已经支持了JavaSDK,和JSSDK
我们看看链接:
java调用接口和方法:https://github.com/taiyuechain/TaiWeb3j.git
JS 调用接口和方法:https://github.com/taiyuechain/TaiWeb3js.git
其中这些Java的接口里面有很多方法可以访问到链:
https://github.com/taiyuechain/docs/blob/master/docs/source/taiyuepublic/RPC-API.md
详细举例:这个例子就是 getBalance的RPC 请求规范,
gtai_getBalance
Returns the balance of the account of given address.
Parameters
-
DATA
, 20 Bytes - address to check for balance. -
QUANTITY|TAG
- integer block number, or the string"latest"
,"earliest"
or"pending"
, see the default block parameter
Example Parameters
params: [ '0xc94770007dda54cF92009BFF0dE90c06F603a09f', 'latest' ]
Returns
QUANTITY
- integer of the current balance in wei.
Example
// Request curl -X POST --data '{"jsonrpc":"2.0","method":"gtai_getBalance","params":["0xc94770007dda54cF92009BFF0dE90c06F603a09f", "latest"],"id":1}' // Result { "id":1, "jsonrpc": "2.0", "result": "0x0234c8a3397aab58" // 158972490234375000 }
那么这个规范如何调用了,就是用上面讲的JavaSDK来调用。因为JavaSDK已经把这个RPC调用进行了封装。
2、链外数据又如何上链呢?
下期分享