rpc 创建可投票账户

管理员组 夜小白 4月前 95

rpc 创建可投票账户

eosio账户的公私钥:

EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV 5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3

要创建的账户umidata的公私钥

EOS8BDvHYmbzqyJzLqQTE3eCPDarAeJgAAuAYH75Y28iKG3vjPZbD 5JxHgKWimh792pScgJ8VEQv46RthLBcSnsXDSdGMYHwwemGwF4e

解锁钱包

curl http://192.168.1.56:8888/v1/wallet/unlock -X POST -d '["default", "PW5JJN8KLE2akHa62NeTCmjkUbmetLfA2edAvb3ge5TR59oDASpi3"]'

私钥导入钱包

./cleos wallet import --private-key 5JxHgKWimh792pScgJ8VEQv46RthLBcSnsXDSdGMYHwwemGwF4e

将umidata账户的私钥导入钱包default

curl http://192.168.1.56:8888/v1/wallet/import_key -X POST -d '["default","5JxHgKWimh792pScgJ8VEQv46RthLBcSnsXDSdGMYHwwemGwF4e"]'

查看钱包内的公钥

cleos -u http://192.168.1.56:8889 wallet keys

获取链最新信息

curl http://192.168.1.56:8889/v1/chain/get_info

{"server_version":"e87d245d","chain_id":"cf057bbfb72640471fd910bcb67639c22df9f92470936cddc1ade0e2f2e7dc4f","head_block_num":94839,"last_irreversible_block_num":94838,"last_irreversible_block_id":"00017276ae6ed097defdf8013ec0697d853bacfb221ddd7b95d6786c219f076d","head_block_id":"00017277f8711bdbbbd1ddeae51af35895d344ca2f21cedfde7e8f58e2b2c88d","head_block_time":"2018-09-18T03:17:49.000","head_block_producer":"eosio","virtual_block_cpu_limit":200000000,"virtual_block_net_limit":1048576000,"block_cpu_limit":199900,"block_net_limit":1048576,"server_version_string":"v1.2.3-dirty"}

以下操作要用到的信息

"chain_id":"cf057bbfb72640471fd910bcb67639c22df9f92470936cddc1ade0e2f2e7dc4f" "head_block_num":94839

查看最新块信息

curl http://192.168.1.56:8889/v1/chain/get_block -X POST -d '{"block_num_or_id":94839}'

```json
```json
{"timestamp":"2018-09-18T03:17:49.000","producer":"eosio","confirmed":0,"previous":"00017276ae6ed097defdf8013ec0697d853bacfb221ddd7b95d6786c219f076d","transaction_mroot":"0000000000000000000000000000000000000000000000000000000000000000","action_mroot":"6e41a647d348bf6f1a5513c910b4d02994ed588bfa68755632023a27e9adc669","schedule_version":0,"new_producers":null,"header_extensions":[],"producer_signature":"SIG_K1_KjTK3tqmeAWioZz396A7CvDqJY3qza6T5b1QugBDoewv3FjQUFiWZpr39Hf9LSn4C6aNNAAkACAXmnmPSwDJjJ4xV1BkLb","transactions":[],"block_extensions":[],"id":"00017277f8711bdbbbd1ddeae51af35895d344ca2f21cedfde7e8f58e2b2c88d","block_num":94839,"ref_block_prefix":3940405691}

以下操作要用到的信息

"timestamp":"2018-09-18T03:17:49.000" "block_num":94839 //块号 "ref_block_prefix":3940405691 //块号相关信息 3940405691

1、POST http://192.168.1.56:8889/v1/chain/abi_json_to_bin (序列化新建账号的 json)

newaccount 的data:

curl http://192.168.1.56:8889/v1/chain/abi_json_to_bin -X POST -d 
'{
    "code": "eosio",
    "action": "newaccount",
    "args": {
        "creator": "eosio",
        "name": "umidata",
        "owner": {
            "threshold": 1,
            "keys": [
                {
                    "key": "EOS8BDvHYmbzqyJzLqQTE3eCPDarAeJgAAuAYH75Y28iKG3vjPZbD",
                    "weight": 1
                }
            ],
            "accounts": [

            ],
            "waits": [

            ]
        },
        "active": {
            "threshold": 1,
            "keys": [
                {
                    "key": "EOS8BDvHYmbzqyJzLqQTE3eCPDarAeJgAAuAYH75Y28iKG3vjPZbD",
                    "weight": 1
                }
            ],
            "accounts": [

            ],
            "waits": [

            ]
        }
    }
}'
{"binargs":"0000000000ea3055000000c064939cd401000000010003b115ab056de0a9026a8f83e29c3f9aa8450b09ac02ac60d4cb1196a7e9682efc0100000001000000010003b115ab056de0a9026a8f83e29c3f9aa8450b09ac02ac60d4cb1196a7e9682efc01000000"}

buyram 的 data

curl http://192.168.1.56:8889/v1/chain/abi_json_to_bin -X POST -d 
'{
    "code": "eosio",
    "action": "buyram",
    "args": {
        "payer": "eosio",
        "receiver": "umidata",
        "quant": "20.0000 SYS",

    }
}'
{"binargs":"0000000000ea3055000000c064939cd4400d0300000000000453595300000000"}

delegatebw的data

curl http://192.168.1.56:8889/v1/chain/abi_json_to_bin -X POST -d 
'{
    "code": "eosio",
    "action": "delegatebw",
    "args": {
        "from": "eosio",
        "receiver": "umidata",
        "stake_net_quantity": "20.0000 SYS",
        "stake_cpu_quantity": "20.0000 SYS",
        "transfer": 0,

    }
}'
{"binargs":"0000000000ea3055000000c064939cd4400d0300000000000453595300000000400d030000000000045359530000000000"}

2、POST http://192.168.1.56:8888/v1/wallet/sign_transaction(签名新建账号的交易

curl http://192.168.1.56:8888/v1/wallet/sign_transaction -X POST -d

'[
    {
        "ref_block_num": 94839,
        "ref_block_prefix": 3940405691,
        "expiration": "2018-09-18T03:45:49.000",
        "actions": [
            {
                "account": "eosio",
                "name": "newaccount",
                "authorization": [
                    {
                        "actor": "eosio",
                        "permission": "owner"
                    }
                ],
                "data": "0000000000ea3055000000c064939cd401000000010003b115ab056de0a9026a8f83e29c3f9aa8450b09ac02ac60d4cb1196a7e9682efc0100000001000000010003b115ab056de0a9026a8f83e29c3f9aa8450b09ac02ac60d4cb1196a7e9682efc01000000"
            },
            {
                "account": "eosio",
                "name": "delegatebw",
                "authorization": [
                    {
                        "actor": "eosio",
                        "permission": "owner"
                    }
                ],
                "data": "0000000000ea3055000000c064939cd4400d0300000000000453595300000000400d030000000000045359530000000000"
            },
            {
                "account": "eosio",
                "name": "buyram",
                "authorization": [
                    {
                        "actor": "eosio",
                        "permission": "owner"
                    }
                ],
                "data": "0000000000ea3055000000c064939cd4400d0300000000000453595300000000"
            }
        ],
        "signatures": [

        ]
    },
    [
        "EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV"
    ],
    "cf057bbfb72640471fd910bcb67639c22df9f92470936cddc1ade0e2f2e7dc4f"
]'
{"expiration":"2018-09-18T03:45:49","ref_block_num":29303,"ref_block_prefix":3940405691,"max_net_usage_words":0,"max_cpu_usage_ms":0,"delay_sec":0,"context_free_actions":[],"actions":[{"account":"eosio","name":"newaccount","authorization":[{"actor":"eosio","permission":"owner"}],"data":"0000000000ea3055000000c064939cd401000000010003b115ab056de0a9026a8f83e29c3f9aa8450b09ac02ac60d4cb1196a7e9682efc0100000001000000010003b115ab056de0a9026a8f83e29c3f9aa8450b09ac02ac60d4cb1196a7e9682efc01000000"},{"account":"eosio","name":"delegatebw","authorization":[{"actor":"eosio","permission":"owner"}],"data":"0000000000ea3055000000c064939cd4400d0300000000000453595300000000400d030000000000045359530000000000"},{"account":"eosio","name":"buyram","authorization":[{"actor":"eosio","permission":"owner"}],"data":"0000000000ea3055000000c064939cd4400d0300000000000453595300000000"}],"transaction_extensions":[],"signatures":["SIG_K1_KmSw3Fy1zPxmKVk19zJgQLGWVi9wbAM79Rz3BCCps77YTeW3oyjrtyKwgSvQwbhhx8jHtanRyhrEe7sYXhSWoMiS5bAAj3"],"context_free_data":[]}

3、http://192.168.1.56:8889/v1/chain/push_transaction (把签名后的交易push 推送到 EOS 系统中,即新建账号完成)

curl http://192.168.1.56:8889/v1/chain/push_transaction -X POST -d
'{
    "transaction": {
        "expiration": "2018-09-18T03:45:49.000",
        "ref_block_num": 94839,
        "ref_block_prefix": 3940405691,
        "max_net_usage_words": 0,
        "max_cpu_usage_ms": 0,
        "delay_sec": 0,
        "context_free_actions": [

        ],
        "actions": [
            {
                "account": "eosio",
                "name": "newaccount",
                "authorization": [
                    {
                        "actor": "eosio",
                        "permission": "owner"
                    }
                ],
                "data": "0000000000ea3055000000c064939cd401000000010003b115ab056de0a9026a8f83e29c3f9aa8450b09ac02ac60d4cb1196a7e9682efc0100000001000000010003b115ab056de0a9026a8f83e29c3f9aa8450b09ac02ac60d4cb1196a7e9682efc01000000"
            },
            {
                "account": "eosio",
                "name": "delegatebw",
                "authorization": [
                    {
                        "actor": "eosio",
                        "permission": "owner"
                    }
                ],
                "data": "0000000000ea3055000000c064939cd4400d0300000000000453595300000000400d030000000000045359530000000000"
            },
            {
                "account": "eosio",
                "name": "buyram",
                "authorization": [
                    {
                        "actor": "eosio",
                        "permission": "owner"
                    }
                ],
                "data": "0000000000ea3055000000c064939cd4400d0300000000000453595300000000"
            }
        ],
        "transaction_extensions": [

        ],
        "context_free_data": [

        ]
    },
    "signatures": [
        "SIG_K1_KmSw3Fy1zPxmKVk19zJgQLGWVi9wbAM79Rz3BCCps77YTeW3oyjrtyKwgSvQwbhhx8jHtanRyhrEe7sYXhSWoMiS5bAAj3"
    ],
    "compression": "none"
}'

查看创建的账户信息 cleos -u http://192.168.1.56:8889 get account umidata

curl http://192.168.1.56:8889/v1/chain/get_account -X POST -d '{"account_name":"umidata"}'

(代币转账 和 新建账号的 sign_transaction、push_transaction 类似,主要就是 智能合约的不同 和 调用的action 的不同 以及 action 中具体的参数不同。) 新建账号(newaccount)需要用 「已有的账号」 创建「 新账号」 内部是 已有账号 调用系统智能合约eosio中的 newaccount 的 action 新建账号的交易需要用 创建者 的 私钥签名交易(sign_transaction),然后 推送签名后的交易 (push_transaction)到区块链中。

还没有人收藏过本帖~
最新回复 (2)
  • 管理员组 Surou 4月前
    0 引用 2
    赞,给你颗小星星
  • 管理员组 夜小白 4月前
    0 引用 3
    surou 赞,给你颗小星星
    没看到 小星星
返回