2

以下查询在近协议中使用 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”?

4

1 回答 1

3
"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"'
于 2020-07-14T20:01:21.187 回答