1. 程式人生 > >EOS實戰(二)RPC介面(使用RPC的介面建立賬戶同時購買記憶體併為其抵押CPU和NET資源)

EOS實戰(二)RPC介面(使用RPC的介面建立賬戶同時購買記憶體併為其抵押CPU和NET資源)

1. 前言

前面我們使用RPC API完成了轉賬。這篇文章繼續使用RPC API來建立賬號。在EOS中,這些行為都叫做transaction,更本質一點說是一筆transaction中的action。在轉賬的transaction中,只有一個action,它呼叫eosio.token合約中的transfer方法。而我們知道,建立賬戶時需要為賬戶購買和抵押資源。其實只需要為新賬戶購買記憶體資源,否則會建立失敗。而抵押CPU和NET資源可以不在建立賬戶時同時進行。但一般來說,為了使新賬戶可以操作一些事情,例如轉賬,都會在建立時同時為其抵押CPU和NET資源。這時就會出現一筆transaction

中包含多個action的情況。本篇文章演示了建立賬戶時存在多個action的情況。

我們需要使用eosio合約來完成下面的步驟。該合約名為eosio.system,位於eos/contracts中。

和之前一樣,我們在測試網路http://jungle.cryptolions.io:18888上,使用Postman對API進行測試。

2. 準備步驟

2.1 生成兩個公鑰

EOS7L9pb38iiqvnrsgzPVqxHnxHmxxeX6bCNbGkehh1hCScEc3ya2
EOS7eZtj6yzESob8Y3vjYwBnM25uZ3HnQa922FmcR3MZuozdiRCEj

2.2 準備錢包和錢包服務

我們使用賬戶testnetyy111來建立賬戶

開啟錢包服務keosd,這次我們指定其服務IP為8899

yuyangdeMacBook-Pro:keosd yuyang$ keosd --http-server-address=localhost:8899

通過呼叫錢包的RPC API,我們開啟並解鎖錢包,保證錢包中有testnetyy111active許可權的公私鑰。這部分不明白可以先看前面的文章

3. 大致流程

大致流程和之前一樣,只是需要多生成幾個bin字串:

  1. abi_json_to_bin_newaccount 將建立賬戶資訊由json格式序列化為bin格式字串

  2. abi_json_to_bin_buyram 將購買記憶體資訊由json格式序列化為bin格式字串

  3. abi_json_to_bin_delegatebw 將購買抵押資源資訊由json格式序列化為bin格式字串

  4. get_info 獲取當前最新的區塊編號

  5. get_block 根據區塊編號獲取區塊詳情

  6. get_required_keys(可省略) 傳入當前擁有的公鑰、bin字串,區塊等資訊,篩選出簽署交易需要的公鑰

  7. sign_transaction 傳入上面獲取的相關引數,通過錢包中私鑰對交易進行簽署

  8. push_transaction 根據第七步獲取的簽名信息,將交易提交到區塊鏈上

4. 詳細流程

4.1 生成建立賬戶的bin字串

  1. 呼叫eosio合約的newaccount方法

  2. 傳入建立者賬戶名稱和新賬戶名稱

  3. 設定兩個許可權的公鑰

api
http://jungle.cryptolions.io:18888/v1/chain/abi_json_to_bin

params
{
  "code": "eosio",
  "action": "newaccount",
  "args": {
    "creator": "testnetyy111",
    "name": "testnetyy222",
    "owner": {
      "threshold": 1,
      "keys": [
        {
          "key": "EOS7L9pb38iiqvnrsgzPVqxHnxHmxxeX6bCNbGkehh1hCScEc3ya2",
          "weight": 1
        }
      ],
      "accounts": [],
      "waits": []
    },
    "active": {
      "threshold": 1,
      "keys": [
        {
          "key": "EOS7eZtj6yzESob8Y3vjYwBnM25uZ3HnQa922FmcR3MZuozdiRCEj",
          "weight": 1
        }
      ],
      "accounts": [],
      "waits": []
    }
  }
}

return
{
    "binargs": "1042f03eab99b1ca2084f03eab99b1ca0100000001000341a9e89b10df5fb0b425e294e32c6208fc3c97becd61f111b351274cd30cd92801000000010000000100036b7a2e4feec43f2160927f34a046914d9aba7625a492597a0f888d2aaec225ba01000000"
}

4.2 生成購買記憶體的bin字串

  1. 呼叫eosio合約的buyram方法

  2. 傳入購買者賬戶名稱和接收者賬戶名稱

  3. 設定購買的金額

api
http://jungle.cryptolions.io:18888/v1/chain/abi_json_to_bin

params
{
   "code": "eosio",
   "action": "buyram",
   "args": {
        "payer": "testnetyy111",
        "receiver": "testnetyy222",
        "quant": "50.0000 EOS",
    }
 }

return
{
    "binargs": "1042f03eab99b1ca2084f03eab99b1ca20a107000000000004454f5300000000"
}

4.3 生成購買抵押資源的bin字串

  1. 呼叫eosio合約的delegatebw方法

  2. 傳入購買者賬戶名稱和接收者賬戶名稱

  3. 設定購買的資源型別和金額

  4. transfer後面講抵押和贖回資源時再詳細講

api
http://jungle.cryptolions.io:18888/v1/chain/abi_json_to_bin

params
{
    "code": "eosio",
    "action": "delegatebw",
    "args": {
        "from": "testnetyy111",
        "receiver": "testnetyy222",
        "stake_net_quantity": "20.0000 EOS",
        "stake_cpu_quantity": "20.0000 EOS",
        "transfer": 0,
    }
}

return
{
    "binargs": "1042f03eab99b1ca2084f03eab99b1ca400d03000000000004454f5300000000400d03000000000004454f530000000000"
}

4.4 獲取當前最新的區塊號

api
http://jungle.cryptolions.io:18888/v1/chain/get_info

params
無

return
{
    "server_version": "08819aae",
    "chain_id": "038f4b0fc8ff18a4f0842a8f0564611f6e96e8535901dd45e43ac8691a1c4dca",
    "head_block_num": 13995827,
    "last_irreversible_block_num": 13995503,
    "last_irreversible_block_id": "00d58defe56615c06fa05fc61639f64b3d72005ed2baff6035c82a8e83ac4b17",
    "head_block_id": "00d58f3333165a76a86f38c98ca50ece1a649a9556276d16f523192b4b5d94c4",
    "head_block_time": "2018-09-12T09:15:35.000",
    "head_block_producer": "eosldndevbp2",
    "virtual_block_cpu_limit": 200000000,
    "virtual_block_net_limit": 1048576000,
    "block_cpu_limit": 199900,
    "block_net_limit": 1048576,
    "server_version_string": "v1.2.5-dirty"
}

獲取到區塊號"head_block_num": 13995827

4.5 獲取當前區塊詳情

api
http://jungle.cryptolions.io:18888/v1/chain/get_block

params
{"block_num_or_id":"13995827"}

return
{
    "timestamp": "2018-09-12T09:15:35.000",
    "producer": "eosldndevbp2",
    "confirmed": 0,
    "previous": "00d58f32a420c7957547e410d65bca6c0e16d6a32e0c0cfbd428f6a46ca67bfe",
    "transaction_mroot": "0000000000000000000000000000000000000000000000000000000000000000",
    "action_mroot": "c71076b9b5100ccd68de98a8b0175036ab6ef26b1d8e2194fa0bf0ff95e4f702",
    "schedule_version": 222,
    "new_producers": null,
    "header_extensions": [],
    "producer_signature": "SIG_K1_KhwPrVWsyVsNL7phXXv9Q1Wf9fFCvx9VZFaLUqBbnn1EJF2M3J9ekCuYwQaDsU9shMpLgPYcNU79dSicLNeza5DmjH8z7A",
    "transactions": [],
    "block_extensions": [],
    "id": "00d58f3333165a76a86f38c98ca50ece1a649a9556276d16f523192b4b5d94c4",
    "block_num": 13995827,
    "ref_block_prefix": 3375919016
}

獲取到"timestamp": "2018-09-12T09:15:35.000""ref_block_prefix": 3375919016

4.6 簽署交易

  • 這筆交易中有三個action,將上面生成的bin字串按name填入到data

  • 過期時間我這裡加了20分鐘。2018-09-12T09:15:35.000 ==> 2018-09-12T09:35:35.000

  • 注意這裡錢包服務的埠為8899

api
http://127.0.0.1:8899/v1/wallet/sign_transaction

params
[{
        "ref_block_num": 13995827,
        "ref_block_prefix": 3375919016,
        "expiration": "2018-09-12T09:35:35.000",
        "actions": [{
            "account": "eosio",
            "name": "newaccount",
            "authorization": [{
                "actor": "testnetyy111",
                "permission": "active"
            }],
            "data": "1042f03eab99b1ca2084f03eab99b1ca0100000001000341a9e89b10df5fb0b425e294e32c6208fc3c97becd61f111b351274cd30cd92801000000010000000100036b7a2e4feec43f2160927f34a046914d9aba7625a492597a0f888d2aaec225ba01000000"
        },
        {
            "account": "eosio",
            "name": "buyram",
            "authorization": [{
                "actor": "testnetyy111",
                "permission": "active"
            }],
            "data": "1042f03eab99b1ca2084f03eab99b1ca20a107000000000004454f5300000000"
        },
        {
            "account": "eosio",
            "name": "delegatebw",
            "authorization": [{
                "actor": "testnetyy111",
                "permission": "active"
            }],
            "data": "1042f03eab99b1ca2084f03eab99b1ca400d03000000000004454f5300000000400d03000000000004454f530000000000"
        }],
        "signatures": []
    },
    ["EOS6Z7mUQeFC2cQTT3xMyZh2wsLQoHih1bTMgRhr3dbichprTi7Rc"], "038f4b0fc8ff18a4f0842a8f0564611f6e96e8535901dd45e43ac8691a1c4dca"
]

return
{
    "expiration": "2018-09-12T09:35:35",
    "ref_block_num": 36659,
    "ref_block_prefix": 3375919016,
    "max_net_usage_words": 0,
    "max_cpu_usage_ms": 0,
    "delay_sec": 0,
    "context_free_actions": [],
    "actions": [
        {
            "account": "eosio",
            "name": "newaccount",
            "authorization": [
                {
                    "actor": "testnetyy111",
                    "permission": "active"
                }
            ],
            "data": "1042f03eab99b1ca2084f03eab99b1ca0100000001000341a9e89b10df5fb0b425e294e32c6208fc3c97becd61f111b351274cd30cd92801000000010000000100036b7a2e4feec43f2160927f34a046914d9aba7625a492597a0f888d2aaec225ba01000000"
        },
        {
            "account": "eosio",
            "name": "buyram",
            "authorization": [
                {
                    "actor": "testnetyy111",
                    "permission": "active"
                }
            ],
            "data": "1042f03eab99b1ca2084f03eab99b1ca20a107000000000004454f5300000000"
        },
        {
            "account": "eosio",
            "name": "delegatebw",
            "authorization": [
                {
                    "actor": "testnetyy111",
                    "permission": "active"
                }
            ],
            "data": "1042f03eab99b1ca2084f03eab99b1ca400d03000000000004454f5300000000400d03000000000004454f530000000000"
        }
    ],
    "transaction_extensions": [],
    "signatures": [
        "SIG_K1_Kdux2Y4uBQnTHuEChMcgVUSpxPMRZaMKjnFu6PoprBx1Lnx8k2bLP2k31VtK9V1YuCjznAVqVEMMeTixgZyYa3ELMboqYV"
    ],
    "context_free_data": []
}

獲取到signatures

4.7 提交交易

api
http://jungle.cryptolions.io:18888/v1/chain/push_transaction

params
{
  "compression": "none",
  "transaction": {
    "expiration": "2018-09-12T09:35:35.000",
    "ref_block_num": 13995827,
    "ref_block_prefix": 3375919016,
    "context_free_actions": [],
    "actions": [
        {
            "account": "eosio",
            "name": "newaccount",
            "authorization": [
                {
                    "actor": "testnetyy111",
                    "permission": "active"
                }
            ],
            "data": "1042f03eab99b1ca2084f03eab99b1ca0100000001000341a9e89b10df5fb0b425e294e32c6208fc3c97becd61f111b351274cd30cd92801000000010000000100036b7a2e4feec43f2160927f34a046914d9aba7625a492597a0f888d2aaec225ba01000000"
        },
        {
            "account": "eosio",
            "name": "buyram",
            "authorization": [
                {
                    "actor": "testnetyy111",
                    "permission": "active"
                }
            ],
            "data": "1042f03eab99b1ca2084f03eab99b1ca20a107000000000004454f5300000000"
        },
        {
            "account": "eosio",
            "name": "delegatebw",
            "authorization": [
                {
                    "actor": "testnetyy111",
                    "permission": "active"
                }
            ],
            "data": "1042f03eab99b1ca2084f03eab99b1ca400d03000000000004454f5300000000400d03000000000004454f530000000000"
        }
    ],
    "transaction_extensions": []
  },
  "signatures": [
        "SIG_K1_Kdux2Y4uBQnTHuEChMcgVUSpxPMRZaMKjnFu6PoprBx1Lnx8k2bLP2k31VtK9V1YuCjznAVqVEMMeTixgZyYa3ELMboqYV"
   ]
}

return
{
    "transaction_id": "19f84ed92b1b5b4987f65b3c581ac5a59c814fca29a106d7154332d23755de60",
    "processed": {
        "id": "19f84ed92b1b5b4987f65b3c581ac5a59c814fca29a106d7154332d23755de60",
        "receipt": {
            "status": "executed",
            "cpu_usage_us": 5966,
            "net_usage_words": 43
        },
        "elapsed": 5966,
        "net_usage": 344,
        "scheduled": false,
        "action_traces": [
            {
                "receipt": {
                    "receiver": "eosio",
                    "act_digest": "3c4d74c9634ac8adb4efe534575de240c6bd0c5571e1569fbb61bdbc24fda1f7",
                    "global_sequence": 33340943,
                    "recv_sequence": 15451045,
                    "auth_sequence": [
                        [
                            "testnetyy111",
                            54
                        ]
                    ],
                    "code_sequence": 11,
                    "abi_sequence": 12
                },
                "act": {
                    "account": "eosio",
                    "name": "newaccount",
                    "authorization": [
                        {
                            "actor": "testnetyy111",
                            "permission": "active"
                        }
                    ],
                    "data": {
                        "creator": "testnetyy111",
                        "name": "testnetyy222",
                        "owner": {
                            "threshold": 1,
                            "keys": [
                                {
                                    "key": "EOS7L9pb38iiqvnrsgzPVqxHnxHmxxeX6bCNbGkehh1hCScEc3ya2",
                                    "weight": 1
                                }
                            ],
                            "accounts": [],
                            "waits": []
                        },
                        "active": {
                            "threshold": 1,
                            "keys": [
                                {
                                    "key": "EOS7eZtj6yzESob8Y3vjYwBnM25uZ3HnQa922FmcR3MZuozdiRCEj",
                                    "weight": 1
                                }
                            ],
                            "accounts": [],
                            "waits": []
                        }
                    },
                    "hex_data": "1042f03eab99b1ca2084f03eab99b1ca0100000001000341a9e89b10df5fb0b425e294e32c6208fc3c97becd61f111b351274cd30cd92801000000010000000100036b7a2e4feec43f2160927f34a046914d9aba7625a492597a0f888d2aaec225ba01000000"
                },
                "elapsed": 1112,
                "cpu_usage": 0,
                "console": "",
                "total_cpu_usage": 0,
                "trx_id": "19f84ed92b1b5b4987f65b3c581ac5a59c814fca29a106d7154332d23755de60",
                "inline_traces": []
            },
            {
                "receipt": {
                    "receiver": "eosio",
                    "act_digest": "a7884494c409371fcfa5df12aad8a061906416e687ab6aa4f58fca8be5d88035",
                    "global_sequence": 33340944,
                    "recv_sequence": 15451046,
                    "auth_sequence": [
                        [
                            "testnetyy111",
                            55
                        ]
                    ],
                    "code_sequence": 11,
                    "abi_sequence": 12
                },
                "act": {
                    "account": "eosio",
                    "name": "buyram",
                    "authorization": [
                        {
                            "actor": "testnetyy111",
                            "permission": "active"
                        }
                    ],
                    "data": {
                        "payer": "testnetyy111",
                        "receiver": "testnetyy222",
                        "quant": "50.0000 EOS"
                    },
                    "hex_data": "1042f03eab99b1ca2084f03eab99b1ca20a107000000000004454f5300000000"
                },
                "elapsed": 1457,
                "cpu_usage": 0,
                "console": "",
                "total_cpu_usage": 0,
                "trx_id": "19f84ed92b1b5b4987f65b3c581ac5a59c814fca29a106d7154332d23755de60",
                "inline_traces": [
                    {
                        "receipt": {
                            "receiver": "eosio.token",
                            "act_digest": "3002817afe2f79146cff845d5a633c20b4481676a9a058414d9e5ce0d301fd8d",
                            "global_sequence": 33340945,
                            "recv_sequence": 1726107,
                            "auth_sequence": [
                                [
                                    "eosio.ram",
                                    240361
                                ],
                                [
                                    "testnetyy111",
                                    56
                                ]
                            ],
                            "code_sequence": 3,
                            "abi_sequence": 3
                        },
                        "act": {
                            "account": "eosio.token",
                            "name": "transfer",
                            "authorization": [
                                {
                                    "actor": "testnetyy111",
                                    "permission": "active"
                                },
                                {
                                    "actor": "eosio.ram",
                                    "permission": "active"
                                }
                            ],
                            "data": {
                                "from": "testnetyy111",
                                "to": "eosio.ram",
                                "quantity": "49.7500 EOS",
                                "memo": "buy ram"
                            },
                            "hex_data": "1042f03eab99b1ca000090e602ea30555c9707000000000004454f5300000000076275792072616d"
                        },
                        "elapsed": 522,
                        "cpu_usage": 0,
                        "console": "",
                        "total_cpu_usage": 0,
                        "trx_id": "19f84ed92b1b5b4987f65b3c581ac5a59c814fca29a106d7154332d23755de60",
                        "inline_traces": [
                            {
                                "receipt": {
                                    "receiver": "testnetyy111",
                                    "act_digest": "3002817afe2f79146cff845d5a633c20b4481676a9a058414d9e5ce0d301fd8d",
                                    "global_sequence": 33340946,
                                    "recv_sequence": 21,
                                    "auth_sequence": [
                                        [
                                            "eosio.ram",
                                            240362
                                        ],
                                        [
                                            "testnetyy111",
                                            57
                                        ]
                                    ],
                                    "code_sequence": 3,
                                    "abi_sequence": 3
                                },
                                "act": {
                                    "account": "eosio.token",
                                    "name": "transfer",
                                    "authorization": [
                                        {
                                            "actor": "testnetyy111",
                                            "permission": "active"
                                        },
                                        {
                                            "actor": "eosio.ram",
                                            "permission": "active"
                                        }
                                    ],
                                    "data": {
                                        "from": "testnetyy111",
                                        "to": "eosio.ram",
                                        "quantity": "49.7500 EOS",
                                        "memo": "buy ram"
                                    },
                                    "hex_data": "1042f03eab99b1ca000090e602ea30555c9707000000000004454f5300000000076275792072616d"
                                },
                                "elapsed": 64,
                                "cpu_usage": 0,
                                "console": "",
                                "total_cpu_usage": 0,
                                "trx_id": "19f84ed92b1b5b4987f65b3c581ac5a59c814fca29a106d7154332d23755de60",
                                "inline_traces": []
                            },
                            {
                                "receipt": {
                                    "receiver": "eosio.ram",
                                    "act_digest": "3002817afe2f79146cff845d5a633c20b4481676a9a058414d9e5ce0d301fd8d",
                                    "global_sequence": 33340947,
                                    "recv_sequence": 267887,
                                    "auth_sequence": [
                                        [
                                            "eosio.ram",
                                            240363
                                        ],
                                        [
                                            "testnetyy111",
                                            58
                                        ]
                                    ],
                                    "code_sequence": 3,
                                    "abi_sequence": 3
                                },
                                "act": {
                                    "account": "eosio.token",
                                    "name": "transfer",
                                    "authorization": [
                                        {
                                            "actor": "testnetyy111",
                                            "permission": "active"
                                        },
                                        {
                                            "actor": "eosio.ram",
                                            "permission": "active"
                                        }
                                    ],
                                    "data": {
                                        "from": "testnetyy111",
                                        "to": "eosio.ram",
                                        "quantity": "49.7500 EOS",
                                        "memo": "buy ram"
                                    },
                                    "hex_data": "1042f03eab99b1ca000090e602ea30555c9707000000000004454f5300000000076275792072616d"
                                },
                                "elapsed": 7,
                                "cpu_usage": 0,
                                "console": "",
                                "total_cpu_usage": 0,
                                "trx_id": "19f84ed92b1b5b4987f65b3c581ac5a59c814fca29a106d7154332d23755de60",
                                "inline_traces": []
                            }
                        ]
                    },
                    {
                        "receipt": {
                            "receiver": "eosio.token",
                            "act_digest": "caa4b0daeab300e365be174604ceb8c971e8981013b936b526110562f73f15d5",
                            "global_sequence": 33340948,
                            "recv_sequence": 1726108,
                            "auth_sequence": [
                                [
                                    "testnetyy111",
                                    59
                                ]
                            ],
                            "code_sequence": 3,
                            "abi_sequence": 3
                        },
                        "act": {
                            "account": "eosio.token",
                            "name": "transfer",
                            "authorization": [
                                {
                                    "actor": "testnetyy111",
                                    "permission": "active"
                                }
                            ],
                            "data": {
                                "from": "testnetyy111",
                                "to": "eosio.ramfee",
                                "quantity": "0.2500 EOS",
                                "memo": "ram fee"
                            },
                            "hex_data": "1042f03eab99b1caa0d492e602ea3055c40900000000000004454f53000000000772616d20666565"
                        },
                        "elapsed": 365,
                        "cpu_usage": 0,
                        "console": "",
                        "total_cpu_usage": 0,
                        "trx_id": "19f84ed92b1b5b4987f65b3c581ac5a59c814fca29a106d7154332d23755de60",
                        "inline_traces": [
                            {
                                "receipt": {
                                    "receiver": "testnetyy111",
                                    "act_digest": "caa4b0daeab300e365be174604ceb8c971e8981013b936b526110562f73f15d5",
                                    "global_sequence": 33340949,
                                    "recv_sequence": 22,
                                    "auth_sequence": [
                                        [
                                            "testnetyy111",
                                            60
                                        ]
                                    ],
                                    "code_sequence": 3,
                                    "abi_sequence": 3
                                },
                                "act": {
                                    "account": "eosio.token",
                                    "name": "transfer",
                                    "authorization": [
                                        {
                                            "actor": "testnetyy111",
                                            "permission": "active"
                                        }
                                    ],
                                    "data": {
                                        "from": "testnetyy111",
                                        "to": "eosio.ramfee",
                                        "quantity": "0.2500 EOS",
                                        "memo": "ram fee"
                                    },
                                    "hex_data": "1042f03eab99b1caa0d492e602ea3055c40900000000000004454f53000000000772616d20666565"
                                },
                                "elapsed": 68,
                                "cpu_usage": 0,
                                "console": "",
                                "total_cpu_usage": 0,
                                "trx_id": "19f84ed92b1b5b4987f65b3c581ac5a59c814fca29a106d7154332d23755de60",
                                "inline_traces": []
                            },
                            {
                                "receipt": {
                                    "receiver": "eosio.ramfee",
                                    "act_digest": "caa4b0daeab300e365be174604ceb8c971e8981013b936b526110562f73f15d5",
                                    "global_sequence": 33340950,
                                    "recv_sequence": 267803,
                                    "auth_sequence": [
                                        [
                                            "testnetyy111",
                                            61
                                        ]
                                    ],
                                    "code_sequence": 3,
                                    "abi_sequence": 3
                                },
                                "act": {
                                    "account": "eosio.token",
                                    "name": "transfer",
                                    "authorization": [
                                        {
                                            "actor": "testnetyy111",
                                            "permission": "active"
                                        }
                                    ],
                                    "data": {
                                        "from": "testnetyy111",
                                        "to": "eosio.ramfee",
                                        "quantity": "0.2500 EOS",
                                        "memo": "ram fee"
                                    },
                                    "hex_data": "1042f03eab99b1caa0d492e602ea3055c40900000000000004454f53000000000772616d20666565"
                                },
                                "elapsed": 10,
                                "cpu_usage": 0,
                                "console": "",
                                "total_cpu_usage": 0,
                                "trx_id": "19f84ed92b1b5b4987f65b3c581ac5a59c814fca29a106d7154332d23755de60",
                                "inline_traces": []
                            }
                        ]
                    }
                ]
            },
            {
                "receipt": {
                    "receiver": "eosio",
                    "act_digest": "3b1f73c0ca73dce2a8c6bcc3a397071a860ecc9798f3cd688382381648dcee10",
                    "global_sequence": 33340951,
                    "recv_sequence": 15451047,
                    "auth_sequence": [
                        [
                            "testnetyy111",
                            62
                        ]
                    ],
                    "code_sequence": 11,
                    "abi_sequence": 12
                },
                "act": {
                    "account": "eosio",
                    "name": "delegatebw",
                    "authorization": [
                        {
                            "actor": "testnetyy111",
                            "permission": "active"
                        }
                    ],
                    "data": {
                        "from": "testnetyy111",
                        "receiver": "testnetyy222",
                        "stake_net_quantity": "20.0000 EOS",
                        "stake_cpu_quantity": "20.0000 EOS",
                        "transfer": 0
                    },
                    "hex_data": "1042f03eab99b1ca2084f03eab99b1ca400d03000000000004454f5300000000400d03000000000004454f530000000000"
                },
                "elapsed": 1561,
                "cpu_usage": 0,
                "console": "",
                "total_cpu_usage": 0,
                "trx_id": "19f84ed92b1b5b4987f65b3c581ac5a59c814fca29a106d7154332d23755de60",
                "inline_traces": [
                    {
                        "receipt": {
                            "receiver": "eosio.token",
                            "act_digest": "034a15a7b1f83236e705f90e22fe246499a990e3699e1f3d8985fe65f1abaa32",
                            "global_sequence": 33340952,
                            "recv_sequence": 1726109,
                            "auth_sequence": [
                                [
                                    "testnetyy111",
                                    63
                                ]
                            ],
                            "code_sequence": 3,
                            "abi_sequence": 3
                        },
                        "act": {
                            "account": "eosio.token",
                            "name": "transfer",
                            "authorization": [
                                {
                                    "actor": "testnetyy111",
                                    "permission": "active"
                                }
                            ],
                            "data": {
                                "from": "testnetyy111",
                                "to": "eosio.stake",
                                "quantity": "40.0000 EOS",
                                "memo": "stake bandwidth"
                            },
                            "hex_data": "1042f03eab99b1ca0014341903ea3055801a06000000000004454f53000000000f7374616b652062616e647769647468"
                        },
                        "elapsed": 471,
                        "cpu_usage": 0,
                        "console": "",
                        "total_cpu_usage": 0,
                        "trx_id": "19f84ed92b1b5b4987f65b3c581ac5a59c814fca29a106d7154332d23755de60",
                        "inline_traces": [
                            {
                                "receipt": {
                                    "receiver": "testnetyy111",
                                    "act_digest": "034a15a7b1f83236e705f90e22fe246499a990e3699e1f3d8985fe65f1abaa32",
                                    "global_sequence": 33340953,
                                    "recv_sequence": 23,
                                    "auth_sequence": [
                                        [
                                            "testnetyy111",
                                            64
                                        ]
                                    ],
                                    "code_sequence": 3,
                                    "abi_sequence": 3
                                },
                                "act": {
                                    "account": "eosio.token",
                                    "name": "transfer",
                                    "authorization": [
                                        {
                                            "actor": "testnetyy111",
                                            "permission": "active"
                                        }
                                    ],
                                    "data": {
                                        "from": "testnetyy111",
                                        "to": "eosio.stake",
                                        "quantity": "40.0000 EOS",
                                        "memo": "stake bandwidth"
                                    },
                                    "hex_data": "1042f03eab99b1ca0014341903ea3055801a06000000000004454f53000000000f7374616b652062616e647769647468"
                                },
                                "elapsed": 54,
                                "cpu_usage": 0,
                                "console": "",
                                "total_cpu_usage": 0,
                                "trx_id": "19f84ed92b1b5b4987f65b3c581ac5a59c814fca29a106d7154332d23755de60",
                                "inline_traces": []
                            },
                            {
                                "receipt": {
                                    "receiver": "eosio.stake",
                                    "act_digest": "034a15a7b1f83236e705f90e22fe246499a990e3699e1f3d8985fe65f1abaa32",
                                    "global_sequence": 33340954,
                                    "recv_sequence": 238454,
                                    "auth_sequence": [
                                        [
                                            "testnetyy111",
                                            65
                                        ]
                                    ],
                                    "code_sequence": 3,
                                    "abi_sequence": 3
                                },
                                "act": {
                                    "account": "eosio.token",
                                    "name": "transfer",
                                    "authorization": [
                                        {
                                            "actor": "testnetyy111",
                                            "permission": "active"
                                        }
                                    ],
                                    "data": {
                                        "from": "testnetyy111",
                                        "to": "eosio.stake",
                                        "quantity": "40.0000 EOS",
                                        "memo": "stake bandwidth"
                                    },
                                    "hex_data": "1042f03eab99b1ca0014341903ea3055801a06000000000004454f53000000000f7374616b652062616e647769647468"
                                },
                                "elapsed": 8,
                                "cpu_usage": 0,
                                "console": "",
                                "total_cpu_usage": 0,
                                "trx_id": "19f84ed92b1b5b4987f65b3c581ac5a59c814fca29a106d7154332d23755de60",
                                "inline_traces": []
                            }
                        ]
                    }
                ]
            }
        ],
        "except": null
    }
}

4.8 查詢新賬戶狀態

api
http://jungle.cryptolions.io:18888/v1/chain/get_account

params
{"account_name":"testnetyy222"}

return
{
    "account_name": "testnetyy222",
    "head_block_num": 13997774,
    "head_block_time": "2018-09-12T09:32:28.500",
    "privileged": false,
    "last_code_update": "1970-01-01T00:00:00.000",
    "created": "2018-09-12T09:29:54.500",
    "ram_quota": 822899,
    "net_weight": 200000,
    "cpu_weight": 200000,
    "net_limit": {
        "used": 0,
        "available": 3835267,
        "max": 3835267
    },
    "cpu_limit": {
        "used": 0,
        "available": 730289,
        "max": 730289
    },
    "ram_usage": 2996,
    "permissions": [
        {
            "perm_name": "active",
            "parent": "owner",
            "required_auth": {
                "threshold": 1,
                "keys": [
                    {
                        "key": "EOS7eZtj6yzESob8Y3vjYwBnM25uZ3HnQa922FmcR3MZuozdiRCEj",
                        "weight": 1
                    }
                ],
                "accounts": [],
                "waits": []
            }
        },
        {
            "perm_name": "owner",
            "parent": "",
            "required_auth": {
                "threshold": 1,
                "keys": [
                    {
                        "key": "EOS7L9pb38iiqvnrsgzPVqxHnxHmxxeX6bCNbGkehh1hCScEc3ya2",
                        "weight": 1
                    }
                ],
                "accounts": [],
                "waits": []
            }
        }
    ],
    "total_resources": {
        "owner": "testnetyy222",
        "net_weight": "20.0000 EOS",
        "cpu_weight": "20.0000 EOS",
        "ram_bytes": 821499
    },
    "self_delegated_bandwidth": null,
    "refund_request": null,
    "voter_info": null
}

使用cleos查詢:

yuyangdeMacBook-Pro:cleos yuyang$ cleos -u "http://jungle.cryptolions.io:18888" get account testnetyy222
permissions: 
     owner     1:    1 EOS7L9pb38iiqvnrsgzPVqxHnxHmxxeX6bCNbGkehh1hCScEc3ya2
        active     1:    1 EOS7eZtj6yzESob8Y3vjYwBnM25uZ3HnQa922FmcR3MZuozdiRCEj
memory: 
     quota:     803.6 KiB    used:     2.926 KiB  

net bandwidth: 
     delegated:      20.0000 EOS           (total staked delegated to account from others)
     used:                 0 bytes
     available:        3.658 MiB  
     limit:            3.658 MiB  

cpu bandwidth:
     delegated:      20.0000 EOS           (total staked delegated to account from others)
     used:                 0 us   
     available:        730.3 ms   
     limit:            730.3 ms