使用RPC接口新建EOS账户
##1、POST http://127.0.0.1:8888/v1/chain/abi_json_to_bin (序列化新建账号的 json)
{
"code": "eosio",
"action": "newaccount",
"args": {
"creator": "bitcoin",
"name": "eason",
"owner": {
"threshold": 1,
"keys": [{
"key": "EOS4ufZoTw95yHJS6Cyz3h4w5a2W4cyYpMYRnd7gbFZuCfPxUFS6r",
"weight": 1
}],
"accounts": [],
"waits": []
},
"active": {
"threshold": 1,
"keys": [{
"key": "EOS4ufZoTw95yHJS6Cyz3h4w5a2W4cyYpMYRnd7gbFZuCfPxUFS6r",
"weight": 1
}],
"accounts": [],
"waits": []
}
}
}
##2、POST http://127.0.0.1:8888/v1/wallet/sign_transaction(签名新建账号的交易)
[
{
"expiration" : "2018-05-17T09:54:06.500",
"signatures" : [
],
"actions" : [
{
"account" : "eosio",
"data" : "000000603a8ab23b000000ca3d364dfb0100000001000202aba1b7d9fc5de9dd93308dc5ebedcb066c8e5b36970bfd82ae715d9e8c3060010000000100000001000202aba1b7d9fc5de9dd93308dc5ebedcb066c8e5b36970bfd82ae715d9e8c306001000000",
"authorization" : [
{
"actor" : "bitcoin",
"permission" : "active"
}
],
"name" : "newaccount"
}
],
"ref_block_prefix" : 4033496171,
"ref_block_num" : 363759
},
[
"EOS5wQ4HaFFDxyfc23dZNXUTGBHepM1vXGfr1vkfWHfRfvAMXP7VV"
],
""
]
##3、http://127.0.0.1:8888/v1/chain/push_transaction (把签名后的交易push 推送到 EOS 系统中,即新建账号完成
{
"compression" : "none",
"transaction" : {
"ref_block_prefix" : 4033496171,
"actions" : [
{
"account" : "eosio",
"data" : "000000603a8ab23b000000ca3d364dfb0100000001000202aba1b7d9fc5de9dd93308dc5ebedcb066c8e5b36970bfd82ae715d9e8c3060010000000100000001000202aba1b7d9fc5de9dd93308dc5ebedcb066c8e5b36970bfd82ae715d9e8c306001000000",
"authorization" : [
{
"actor" : "bitcoin",
"permission" : "active"
}
],
"name" : "newaccount"
}
],
"expiration" : "2018-05-17T09:54:06.500",
"ref_block_num" : 363759
},
"signatures" : [
"SIG_K1_KY58QhP4jWLJWr7cVkahgL3JAjC8QMK5jnHurFUmn8xU71v6Mh4DmgjY75DxmWE6Je457N6MRM7GapxU43hywnAWKEmC1W"
]
}
(代币转账 和 新建账号的 sign_transaction、push_transaction 类似,主要就是 智能合约的不同 和 调用的action 的不同 以及 action 中具体的参数不同。)
新建账号(newaccount)需要用 「已有的账号」 创建「 新账号」
内部是 已有账号 调用系统智能合约eosio中的 newaccount 的 action
新建账号的交易需要用 创建者 的 私钥签名交易(sign_transaction),然后 推送签名后的交易 (push_transaction)到区块链中。
a. sign_transaction 图示
b. push_transaction 图示
#具体接口
1、POST http://127.0.0.1:8888/v1/chain/abi_json_to_bin (序列化新建账号的 json)
请求参数
请求参数:
参数名称 参数类型 描述
code string 系统智能合约,默认填写“eosio”
action string 智能合约中的action,默认填写“newaccount”
creator string 创建者
name string 新建账号名
key string 新建账号的公钥
请求示例:
{
"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": []
}
}
}
响应参数
参数名称 参数类型 描述
binargs string 序列化的结果,在sign_transaction 和 push_transaction 中作为 data 请求参数
响应示例
{
"binargs": "000000603a8ab23b000000ca3d364dfb0100000001000202aba1b7d9fc5de9dd93308dc5ebedcb066c8e5b36970bfd82ae715d9e8c3060010000000100000001000202aba1b7d9fc5de9dd93308dc5ebedcb066c8e5b36970bfd82ae715d9e8c306001000000"
}
2、GET http://127.0.0.1:8888/v1/chain/get_info (获取 EOS 区块链的最新区块号)
响应参数
参数名称 参数类型 描述
head_block_num number 最新区块号
响应示例
{
"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
}
3、POST http://127.0.0.1:8888/v1/chain/get_block (获取最新区块的具体信息)
请求参数
参数名称 参数类型 描述
block_num_or_id number 最新区块号,上一个响应结果中的 head_block_num
{
"block_num_or_id":359934
}
响应参数
参数名称 参数类型 描述
timestamp string 最新区块的生成时间
block_num number 区块号,作为sign_transaction 和 push_transaction中的 ref_block_num请求参数
ref_block_prefix number 作为sign_transaction 和 push_transaction中的 ref_block_prefix 请求参数
响应示例
{
"timestamp": "2018-05-17T09: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
}
4、POST http://127.0.0.1:8888/v1/wallet/unlock (解锁钱包,签名交易前,需要解锁账号所在的钱包)
请求参数
参数名称 参数类型 描述
string 钱包名称
string 钱包密码
请求示例
["liu","PW5KjWHnhL5kSRxpWyHQj321dFsZN62HAbZjVSqnDvzKMuEKBZ1T9"]
响应示例
{} //成功解锁钱包,返回{}
5、POST http://127.0.0.1:8888/v1/wallet/sign_transaction(签名新建账号的交易)
请求的参数
参数名称 参数类型 描述
ref_block_num number 上面获得的最新区块号
ref_block_prefix number 上面获得的最新区块号相关信息
expiration string 过期时间 = timestamp 加上 一段时间 ,例如1分钟
account string 调用系统智能合约账号名,默认为 eosio
name string 新建账号的action,默认为 newaccount
actor string 创建者 账户名
data string abi_json_to_bin 序列化后的 值 binargs
string 创建者的 公钥
请求示例
[
{
"ref_block_num": 363759,
"ref_block_prefix": 4033496171,
"expiration": "2018-05-17T09:54:06.500",
"actions": [
{
"account": "eosio", //有 newaccount 的 action 的智能合约账号
"name": "newaccount",
"authorization": [
{
"actor": "bitcoin",
"permission": "active"
}
],
"data": "000000603a8ab23b000000ca3d364dfb0100000001000202aba1b7d9fc5de9dd93308dc5ebedcb066c8e5b36970bfd82ae715d9e8c3060010000000100000001000202aba1b7d9fc5de9dd93308dc5ebedcb066c8e5b36970bfd82ae715d9e8c306001000000" // //abi_json_to_bin 的响应参数 binargs
}
],
"signatures": []
},
[
"EOS5wQ4HaFFDxyfc23dZNXUTGBHepM1vXGfr1vkfWHfRfvAMXP7VV" //创建者的公钥(交易发起者的公钥),其实是用的公钥对应的私钥进行签名的,签名前需要先解锁包含此私钥的钱包
],
""
]
响应参数
参数名称 参数类型 描述
signatures string 新建账号的交易 的签名结果,最后 push_transaction 中使用
响应示例
{
"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": "000000603a8ab23b000000ca3d364dfb0100000001000202aba1b7d9fc5de9dd93308dc5ebedcb066c8e5b36970bfd82ae715d9e8c3060010000000100000001000202aba1b7d9fc5de9dd93308dc5ebedcb066c8e5b36970bfd82ae715d9e8c306001000000"
}
],
"transaction_extensions": [],
"signatures": [
"SIG_K1_KY58QhP4jWLJWr7cVkahgL3JAjC8QMK5jnHurFUmn8xU71v6Mh4DmgjY75DxmWE6Je457N6MRM7GapxU43hywnAWKEmC1W" // 签名 用在 push_transaction 中
],
"context_free_data": []
}
6、http://127.0.0.1:8888/v1/chain/push_transaction (把签名后的交易push 推送到 EOS 系统中,即新建账号完成)
请求参数
参数名称 参数类型 描述
compression string 默认 none
data string abi_json_to_bin 序列化后的 值 binargs
signatures string 交易签名后的结果
请求示例
{
"compression": "none",
"transaction": {
"expiration": "2018-05-17T09:54:06.500",
"ref_block_num": 363759,
"ref_block_prefix": 4033496171,
"actions": [
{
"account": "eosio",
"name": "newaccount",
"authorization": [
{
"actor": "bitcoin",
"permission": "active"
}
],
"data": "000000603a8ab23b000000ca3d364dfb0100000001000202aba1b7d9fc5de9dd93308dc5ebedcb066c8e5b36970bfd82ae715d9e8c3060010000000100000001000202aba1b7d9fc5de9dd93308dc5ebedcb066c8e5b36970bfd82ae715d9e8c306001000000" //abi_json_to_bin 的响应参数 binargs
}
]
},
"signatures": ["SIG_K1_KY58QhP4jWLJWr7cVkahgL3JAjC8QMK5jnHurFUmn8xU71v6Mh4DmgjY75DxmWE6Je457N6MRM7GapxU43hywnAWKEmC1W"]
}
响应示例
{
"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": "000000603a8ab23b000000ca3d364dfb0100000001000202aba1b7d9fc5de9dd93308dc5ebedcb066c8e5b36970bfd82ae715d9e8c3060010000000100000001000202aba1b7d9fc5de9dd93308dc5ebedcb066c8e5b36970bfd82ae715d9e8c306001000000"
},
"elapsed": 163,
"cpu_usage": 0,
"console": "",
"total_cpu_usage": 0,
"trx_id": "2047702bfdc4678aabe123f335b4b5f604203edf7b4de8e42fa2c9211d4de075",
"inline_traces": []
}
],
"except": null
}
}
From:使用RPC接口新建EOS账户 - 实战
EOS测试账号
节点:192.168.50.159,
其中nodeosd相关API请访问 http://192.168.50.159:8888,
Wallet相关API请访问 http://192.168.50.159:3000
##1.测试网
http://jungle.cryptolions.io/#accountInfo
##2.测试API
https://github.com/CryptoLions/EOS-Jungle-Testnet
##2.测试账号
liulian12345
Description | EOS Token Sale Claim Key |
---|---|
Public key | EOS7LAzv5dbrzprL8DZuHYMKfTjQQ9AUXPAKzQfSFUed1GoJuTXmd |
Private key | 5Hsk6wB2MPqGPrU53jSVGHm3uvoqWJk3rCrnkGzEGc7HrH28n7t |
localhost
Private key: 5JUJHBJF18Qs8WMdXnb5488AFzdAZcfKZ5QAX1srMLWa62rsL4e
Public key: EOS6BQZmWhPKZLVg4YDcR6KdrYb1dqjDAWxyGPHRTD6mpqJ1dACAp
Private key: 5KXZjxLz4qczfCGmWYUzxhiKyRN1eYaGCRZaT1hHAFJs9xsmCKS
Public key: EOS5uLxwJQgpEJteBxBTKiqWnyWiJTQAzAqx71M5AuMZ917oMv4g4
Jungle:
测试网络账号创建的block: 13658485
{
"timestamp": "2018-09-10T09:33:29.000",
"producer": "funnyhamster",
"confirmed": 0,
"previous": "00d06974a6485b5e6c80d804313d6c0058870848f103735fb24ae63851a61f66",
"transaction_mroot": "00eb3fbea28360f5ab26cae9cf50c081baf5579800aa6062f059808ad9b44d7a",
"action_mroot": "10a2e5ea43847603f2d68bc5b403eea5ec744b70d38ff1d73e859fbe9413e6c6",
"schedule_version": 217,
"new_producers": null,
"header_extensions": [],
"producer_signature": "SIG_K1_K26xvdaxUhQcE6Cga1fQfDLKxVYKpAG9nNk8isA4Pby8ZH2Jp8y8Z6ki8p3ZHAvuBFTJDrNTAW6va9Xbd1R7E8DoosQdXE",
"transactions": [
{
"status": "executed",
"cpu_usage_us": 7238,
"net_usage_words": 43,
"trx": {
"id": "929ecaca3aa6aa09a515239ff79e78b4df62bf87809a45a7baf2848696c3f094",
"signatures": [
"SIG_K1_KVJz9woQUmHRCot6prUeeY3H8vjZBSStUhefQhrmzsCDKS8MkqYV2ANgfPeSpdEgmAnqX39WnKraCGiwJYedzKkbu5nBnS"
],
"compression": "none",
"packed_context_free_data": "",
"context_free_data": [],
"packed_trx": "e03a965b2868e3b6720100000000030000000000ea305500409e9a2264b89a0150c810611a17b58b00000000a8ed32326650c810611a17b58b208269a69996b1ca01000000010002aa1bf6ea68794eb7ad364ea9e3438171866a557f1db49f596c67eab2a6a0d7230100000001000000010002aa1bf6ea68794eb7ad364ea9e3438171866a557f1db49f596c67eab2a6a0d723010000000000000000ea3055000000004873bd3e0150c810611a17b58b00000000a8ed32322050c810611a17b58b208269a69996b1caa08601000000000004454f53000000000000000000ea305500003f2a1ba6a24a0150c810611a17b58b00000000a8ed32323150c810611a17b58b208269a69996b1caa08601000000000004454f5300000000a08601000000000004454f53000000000100",
"transaction": {
"expiration": "2018-09-10T09:35:28",
"ref_block_num": 26664,
"ref_block_prefix": 24295139,
"max_net_usage_words": 0,
"max_cpu_usage_ms": 0,
"delay_sec": 0,
"context_free_actions": [],
"actions": [
{
"account": "eosio",
"name": "newaccount",
"authorization": [
{
"actor": "liulian12345",
"permission": "active"
}
],
"data": {
"creator": "liulian12345",
"name": "testhahaha12",
"owner": {
"threshold": 1,
"keys": [
{
"key": "EOS6BQZmWhPKZLVg4YDcR6KdrYb1dqjDAWxyGPHRTD6mpqJ1dACAp",
"weight": 1
}
],
"accounts": [],
"waits": []
},
"active": {
"threshold": 1,
"keys": [
{
"key": "EOS6BQZmWhPKZLVg4YDcR6KdrYb1dqjDAWxyGPHRTD6mpqJ1dACAp",
"weight": 1
}
],
"accounts": [],
"waits": []
}
},
"hex_data": "50c810611a17b58b208269a69996b1ca01000000010002aa1bf6ea68794eb7ad364ea9e3438171866a557f1db49f596c67eab2a6a0d7230100000001000000010002aa1bf6ea68794eb7ad364ea9e3438171866a557f1db49f596c67eab2a6a0d72301000000"
},
{
"account": "eosio",
"name": "buyram",
"authorization": [
{
"actor": "liulian12345",
"permission": "active"
}
],
"data": {
"payer": "liulian12345",
"receiver": "testhahaha12",
"quant": "10.0000 EOS"
},
"hex_data": "50c810611a17b58b208269a69996b1caa08601000000000004454f5300000000"
},
{
"account": "eosio",
"name": "delegatebw",
"authorization": [
{
"actor": "liulian12345",
"permission": "active"
}
],
"data": {
"from": "liulian12345",
"receiver": "testhahaha12",
"stake_net_quantity": "10.0000 EOS",
"stake_cpu_quantity": "10.0000 EOS",
"transfer": 1
},
"hex_data": "50c810611a17b58b208269a69996b1caa08601000000000004454f5300000000a08601000000000004454f530000000001"
}
],
"transaction_extensions": []
}
}
}
],
"block_extensions": [],
"id": "00d06975eb6fb6c7c281c3f68819489c27a2f876e3820f8bc37bb09f09f6d4ef",
"block_num": 13658485,
"ref_block_prefix": 4140007874
}
Copyright © 2015 Powered by MWeb, 豫ICP备09002885号-5