下面的查询在near协议中使用jsonrpc中的call_function
http post https://rpc.testnet.near.org jsonrpc=2.0 id=test method=query params:='{
"request_type": "call_function",
"finality": "final",
"account_id": "dev-1591261827342",
"method_name": "get_total_supply",
"args_base64": "e30="
}'给出以下结果:
{
"id": "test",
"jsonrpc": "2.0",
"result": {
"block_hash": "FrKNvsEbqPsdT1ijLkUBNoX3SnUQbTCXjoPj7yC2WW5i",
"block_height": 9616038,
"logs": [],
"result": [
34,
49,
48,
48,
48,
48,
48,
48,
48,
48,
48,
48,
48,
48,
48,
48,
48,
34
]
}
}如何将结果转换为实际的数字'1000000000000000'?
发布于 2020-07-15 04:01:21
"result": [
34,
49,
48,
48,
48,
48,
48,
48,
48,
48,
48,
48,
48,
48,
48,
48,
48,
34
]是一个字节数组。默认情况下,NEAR SDK对输入和输出使用JSON编码,但不限于此,所以如果您转换它,就会得到"1000000000000000"。下面是用于转换它的Python代码片段:
>>> result = [34, 49, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 34]
>>> ''.join(chr(x) for x in result)
'"1000000000000000"'https://stackoverflow.com/questions/62901450
复制相似问题