Available with the latest EOS Dawn 4.0/4.1

preface

Recently, I was studying THE RPC API of EOS. However, due to the lack of detailed official API documents, the operation of creating a New Account took more than a week. Heaven pays off to those who wait, finally tune through the new account, token transfer is also easy to solve. I am writing this article (for EOS Dawn 4.0 and 4.1) to help those who are preparing to use EOS RPC for Dapp development.

Cut the crap and look at things first

1, POST http://127.0.0.1:8888/v1/chain/abi_json_to_bin (json serialization new account)

{ "code": "eosio", "action": "newaccount", "args": { "creator": "bitcoin", "name": "eason", "owner": { "threshold": 1, "keys": [ { "key": "EOS4ufZoTw95yHJS6Cyz3h4w5a2W4cyYpMYRnd7gbFZuCfPxUFS6r", //owner public key "weight": 1 } ], "accounts": [], "waits": [] }, "active": { "threshold": 1, "keys": [ { "key": "EOS4ufZoTw95yHJS6Cyz3h4w5a2W4cyYpMYRnd7gbFZuCfPxUFS6r", //active public key "weight": 1 } ], "accounts": [], "waits": []}}}Copy the code

2, POST http://127.0.0.1:8888/v1/wallet/sign_transaction (signed new account)

[{"ref_block_num": 363759."ref_block_prefix": 4033496171."expiration": "The 2018-05-17 T09:54:06. 500"."actions": [{"account": "eosio"."name": "newaccount"."authorization": [{"actor": "bitcoin"."permission": "active"}]."data": "000000603a8ab23b000000ca3d364dfb0100000001000202aba1b7d9fc5de9dd93308dc5ebedcb066c8e5b36970bfd82ae715d9e8c3060010000000 100000001000202aba1b7d9fc5de9dd93308dc5ebedcb066c8e5b36970bfd82ae715d9e8c306001000000"}]."signatures"} : [], ["EOS5wQ4HaFFDxyfc23dZNXUTGBHepM1vXGfr1vkfWHfRfvAMXP7VV"].""
]
Copy the code

3, http://127.0.0.1:8888/v1/chain/push_transaction (after the signature of transaction push pushed to the EOS system, the new account)

{
  "compression": "none"."transaction": {
    "expiration": "The 2018-05-17 T09:54:06. 500"."ref_block_num": 363759."ref_block_prefix": 4033496171."actions": [{"account": "eosio"."name": "newaccount"."authorization": [{"actor": "bitcoin"."permission": "active"}]."data": "000000603a8ab23b000000ca3d364dfb0100000001000202aba1b7d9fc5de9dd93308dc5ebedcb066c8e5b36970bfd82ae715d9e8c3060010000000 100000001000202aba1b7d9fc5de9dd93308dc5ebedcb066c8e5b36970bfd82ae715d9e8c306001000000"}},"signatures": ["SIG_K1_KY58QhP4jWLJWr7cVkahgL3JAjC8QMK5jnHurFUmn8xU71v6Mh4DmgjY75DxmWE6Je457N6MRM7GapxU43hywnAWKEmC1W"]}Copy the code

(Token transfer is similar to sign_TRANSACTION and PUSH_transaction of a new account, except that the smart contract is different, the action is called differently, and the specific parameters of the action are different.)

To create a newaccount, use an existing account to create a newaccount.

Internally, an existing account invokes the action of newAccount in eoSIO

A transaction for a new account needs to be signed with the creator’s private key and push_transaction is pushed to the blockchain.

A. sign_transaction icon

B. push_transaction icon

Specific interface

1, the POSThttp://127.0.0.1:8888/v1/chain/abi_json_to_binSerialize json for the new account.

Request parameters:

The parameter name The parameter types describe
code string System smart contract, eoSIO by default
action string For action in smart contracts, the default value is “NewAccount”.
creator string The creator
name string Creating an Account name
key string Create the public key of the account

Example request:

{ "code": "eosio", "action": "newaccount", "args": { "creator": "bitcoin", "name": "eason", "owner": { "threshold": 1, "keys": [ { "key": "EOS4ufZoTw95yHJS6Cyz3h4w5a2W4cyYpMYRnd7gbFZuCfPxUFS6r", //owner public key "weight": 1 } ], "accounts": [], "waits": [] }, "active": { "threshold": 1, "keys": [ { "key": "EOS4ufZoTw95yHJS6Cyz3h4w5a2W4cyYpMYRnd7gbFZuCfPxUFS6r", //active public key "weight": 1 } ], "accounts": [], "waits": []}}}Copy the code

Response parameters

The parameter name The parameter types describe
binargs string Serialization result, as in sign_TRANSACTION and PUSH_TRANSACTIONdataRequest parameters

In response to the sample

{
    "binargs": "000000603a8ab23b000000ca3d364dfb0100000001000202aba1b7d9fc5de9dd93308dc5ebedcb066c8e5b36970bfd82ae715d9e8c3060010000000 100000001000202aba1b7d9fc5de9dd93308dc5ebedcb066c8e5b36970bfd82ae715d9e8c306001000000"
}
Copy the code

2, GEThttp://127.0.0.1:8888/v1/chain/get_info(Obtain the latest block number of EOS blockchain)

Response parameters

The parameter name The parameter types describe
head_block_num number Latest Block Number

In response to the sample

{
    "server_version": "13952d45"."head_block_num": 359934."last_irreversible_block_num": 359934."last_irreversible_block_id": "a69af2c4aa56b5c4bd1cdf9c2acb1a7796bbc3043954e36da182a144ddcf58fb"."head_block_id": "a69af2c4aa56b5c4bd1cdf9c2acb1a7796bbc3043954e36da182a144ddcf58fb"."head_block_time": "2018-05-17T09:02:12"."head_block_producer": "eosio"."virtual_block_cpu_limit": 100000000."virtual_block_net_limit": 1048576000."block_cpu_limit": 99900."block_net_limit": 1048576
}
Copy the code

3, POSThttp://127.0.0.1:8888/v1/chain/get_block(Get specific information about the latest block)

Request parameters

The parameter name The parameter types describe
block_num_or_id number The latest block number, head_block_num in the previous response result
{
  "block_num_or_id":359934
}
Copy the code

Response parameters

The parameter name The parameter types describe
timestamp string The generation time of the latest block
block_num number Block number, as in SIGN_TRANSACTION and PUSH_TRANSACTIONref_block_numRequest parameters
ref_block_prefix number As in sign_TRANSACTION and PUSH_TRANSACTIONref_block_prefixRequest parameters

In response to the sample

{
    "timestamp": "The 2018-05-17 T09:02:12. 500"."producer": "eosio"."confirmed": 0."previous": "00057dfd5044aba0d750eff1fbb84ac92cbf29db1354968816fd2a9aefb0a0b4"."transaction_mroot": "0000000000000000000000000000000000000000000000000000000000000000"."action_mroot": "dee87e5d025383574ac12c310faf6b759fba52bd19977399b7ebf6ccdd81c7fa"."schedule_version": 0."header_extensions": []."producer_signature": "SIG_K1_KVX3RRTS4ch9m6bWDctsAhDWtFydTrg3mW7PaqCXnBZZWezBW23enggeW4ijuWBHBVsDoxzjMvspoFtPsU5nmau4ZYomZo"."transactions": []."block_extensions": []."id": "a69af2c4aa56b5c4bd1cdf9c2acb1a7796bbc3043954e36da182a144ddcf58fb"."block_num": 359934."ref_block_prefix": 1943477914
}
Copy the code

4, POSThttp://127.0.0.1:8888/v1/wallet/unlock(To unlock the wallet, you need to unlock the wallet where the account is before signing the transaction)

Request parameters

The parameter name The parameter types describe
string Name of the wallet
string The wallet password

Sample request

["liu"."PW5KjWHnhL5kSRxpWyHQj321dFsZN62HAbZjVSqnDvzKMuEKBZ1T9"]
Copy the code

In response to the sample

{} // Unlock wallet successfully, return {}Copy the code

5, POSThttp://127.0.0.1:8888/v1/wallet/sign_transaction (signed new account)

Requested parameters

The parameter name The parameter types describe
ref_block_num number The latest block number obtained above
ref_block_prefix number The latest block number information obtained above
expiration string Expiration time = TIMESTAMP plus a period of time, such as 1 minute
account string The account name for invoking the system smart contract is EOSIO by default
name string The default action of a newaccount is newaccount
actor string Creator account name
data string Abi_json_to_bin Serialized value binargs
string Creator’s public key

Sample request

[{"ref_block_num": 363759, "ref_block_prefix": 4033496171, "expiration": "2018-05-17t09:54:06.500 ", "actions": [{"ref_block_num": 363759, "ref_block_prefix": 4033496171, "expiration":" 2018-05-17t09:54:06.500 ", "actions": [{" account ":" eosio ", / / a newaccount of action of the intelligent contract account "name" : "newaccount", "authorization" : [{" actor ": "bitcoin", "permission": "active" } ], "data": "000000603a8ab23b000000ca3d364dfb0100000001000202aba1b7d9fc5de9dd93308dc5ebedcb066c8e5b36970bfd82ae715d9e8c3060010000000 100000001000202 aba1b7d9fc5de9dd93308dc5ebedcb066c8e5b36970bfd82ae715d9e8c306001000000 "/ / / / abi_json_to_bin response parameters binargs } ], "signatures": } [], [" EOS5wQ4HaFFDxyfc23dZNXUTGBHepM1vXGfr1vkfWHfRfvAMXP7VV "/ / the creator's public key (public key transaction originator), actually is to use the public key of the corresponding private key to sign, You need to unlock the wallet containing this private key before signing], ""]Copy the code

Response parameters

The parameter name The parameter types describe
signatures string The signing result of the transaction for the new account, which is used in push_TRANSACTION

In response to the sample

{
    "expiration": "2018-05-17T09:54:06"."ref_block_num": 36079."ref_block_prefix": 4033496171."max_net_usage_words": 0."max_cpu_usage_ms": 0."delay_sec": 0."context_free_actions": []."actions": [{"account": "eosio"."name": "newaccount"."authorization": [{"actor": "bitcoin"."permission": "active"}]."data": "000000603a8ab23b000000ca3d364dfb0100000001000202aba1b7d9fc5de9dd93308dc5ebedcb066c8e5b36970bfd82ae715d9e8c3060010000000 100000001000202aba1b7d9fc5de9dd93308dc5ebedcb066c8e5b36970bfd82ae715d9e8c306001000000"}]."transaction_extensions": []."signatures": [
    "SIG_K1_KY58QhP4jWLJWr7cVkahgL3JAjC8QMK5jnHurFUmn8xU71v6Mh4DmgjY75DxmWE6Je457N6MRM7GapxU43hywnAWKEmC1W"// Signature used in push_transaction],"context_free_data": []}Copy the code

6,http://127.0.0.1:8888/v1/chain/push_transaction(Push the signed transaction to EOS system, that is, create a new account.)

Request parameters

The parameter name The parameter types describe
compression string By default, none
data string Abi_json_to_bin Serialized value binargs
signatures string The result of a signed transaction

Sample request

{
  "compression": "none"."transaction": {
    "expiration": "The 2018-05-17 T09:54:06. 500"."ref_block_num": 363759."ref_block_prefix": 4033496171."actions": [{"account": "eosio"."name": "newaccount"."authorization": [{"actor": "bitcoin"."permission": "active"}]."data": "000000603a8ab23b000000ca3d364dfb0100000001000202aba1b7d9fc5de9dd93308dc5ebedcb066c8e5b36970bfd82ae715d9e8c3060010000000 100000001000202aba1b7d9fc5de9dd93308dc5ebedcb066c8e5b36970bfd82ae715d9e8c306001000000"//abi_json_to_bin response parameter binargs}]},"signatures": ["SIG_K1_KY58QhP4jWLJWr7cVkahgL3JAjC8QMK5jnHurFUmn8xU71v6Mh4DmgjY75DxmWE6Je457N6MRM7GapxU43hywnAWKEmC1W"]}Copy the code

In response to the sample

{
    "transaction_id": "2047702bfdc4678aabe123f335b4b5f604203edf7b4de8e42fa2c9211d4de075"."processed": {
        "id": "2047702bfdc4678aabe123f335b4b5f604203edf7b4de8e42fa2c9211d4de075"."receipt": {
            "status": "executed"."cpu_usage_us": 390."net_usage_words": 25
        },
        "elapsed": 390."net_usage": 200."scheduled": false."action_traces": [{"receipt": {
                    "receiver": "eosio"."act_digest": "ae18e275184e7defe81be175711cd24206990518963f857715e98755f713957c"."global_sequence": 365444."recv_sequence": 365419."auth_sequence": [["bitcoin".27]]},"act": {
                    "account": "eosio"."name": "newaccount"."authorization": [{"actor": "bitcoin"."permission": "active"}]."data": {
                        "creator": "bitcoin"."name": "zhangjie"."owner": {
                            "threshold": 1."keys": [{"key": "EOS4ufZoTw95yHJS6Cyz3h4w5a2W4cyYpMYRnd7gbFZuCfPxUFS6r"."weight": 1}]."accounts": []."waits": []},"active": {
                            "threshold": 1."keys": [{"key": "EOS4ufZoTw95yHJS6Cyz3h4w5a2W4cyYpMYRnd7gbFZuCfPxUFS6r"."weight": 1}]."accounts": []."waits": []}},"hex_data": "000000603a8ab23b000000ca3d364dfb0100000001000202aba1b7d9fc5de9dd93308dc5ebedcb066c8e5b36970bfd82ae715d9e8c3060010000000 100000001000202aba1b7d9fc5de9dd93308dc5ebedcb066c8e5b36970bfd82ae715d9e8c306001000000"
                },
                "elapsed": 163."cpu_usage": 0."console": ""."total_cpu_usage": 0."trx_id": "2047702bfdc4678aabe123f335b4b5f604203edf7b4de8e42fa2c9211d4de075"."inline_traces": []}],"except": null}}Copy the code

Related articles and videos recommended

[Xu Xiaodi] In-depth understanding of EOS account permission mapping

Yuan Yuan Institute brings together a large number of blockchain masters to create high-quality blockchain technology courses. There are high quality free public courses on all major platforms for a long time, welcome to sign up and watch. Open course address: ke.qq.com/course/3451…