EOS钱包教程

官网: https://eosio.github.io/eos/group__eosiorpc.html
官方中文:https://eos.readthedocs.io/zh_CN/latest/API/EOSIO-RPC/
密钥对生成工具: https://eosfans.io/tools/generate/
1、创建钱包
 
描述:
创建新钱包
 
请求示例:
$ curl http://localhost:8888/v1/wallet/create -X POST -d '"default"'
 
参数:

参数

参数类型

是否必须

钱包名

string

 
 
 
 
 
 
返回数据:
PW5KFWYKqvt63d4iNvedfDEPVZL227D3RQ1zpVFzuUwhMAJmRAYyX
 
数据说明:
新钱包的密码,用于解锁该钱包
 
2、打开钱包
描述:
钱包默认是关闭状态,打开钱包才能进行操作
请求示例:
$ curl http://localhost:8888/v1/wallet/open-X POST -d '"default"'
参数:

参数

参数类型

是否必须

钱包名

string

 
 
 
 
 
 
返回数据:
{}
 
3、锁定钱包
描述:
锁定给定的钱包
请求示例:
$ curlhttp://localhost:8888/v1/wallet/lock -X POST -d '"default"'
参数:

参数

参数类型

是否必须

钱包名

string

 
 
 
返回数据:
{}
4、锁定所有钱包
描述:
锁定本地所有钱包
请求示例:
$ curlhttp://localhost:8888/v1/wallet/lock_all
返回数据:
{}
 
5、解锁钱包
描述:
解锁给定的钱包
请求示例:
$ curl http://localhost:8888/v1/wallet/unlock-X POST -d '["default", "PW5KFWYKqvt63d4iNvedfDEPVZL227D3RQ1zpVFzuUwhMAJmRAYyX"]'
参数:

参数

参数类型

是否必须

钱包名

string

密码

string

 
 
 
 
 
返回数据:
{}
6、钱包导入私钥
描述:
向给定的钱包中导入一个私钥
请求示例:
$ curlhttp://localhost:8888/v1/wallet/import_key -X POST -d '["default","5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"]'
参数:

参数

参数类型

是否必须

钱包名

string

私钥

string

 
 
 
 
 
返回数据:
{}
7、列出钱包
描述:
列出本地打开的所有钱包
请求示例:
$ curl http://localhost:8888/v1/wallet/list_wallets
参数:

返回数据:
["default *"]
数据说明:
*代表解锁的钱包
8、获取公钥列表
描述:
列出本地所有钱包中所有账号的公钥
请求示例:
curl http://localhost:8888/v1/wallet/get_public_keys
参数:

返回数据:
["EOS5Dz1qfz9H5cmoofUC5h2ticeNgPUAjKsWK7EWySsEDs7m8iNTw","EOS5o9u5hPF3yWceYDwvJvXdqBvEAzUETW4jzL8oJpRk7XaYRbZTZ","EOS6ERAj2QTzExko3qe3hbReQAPPhsQmqHE9nszC172kXFceoJnu7"]
数据说明:
 
9、设置钱包自动上锁
描述:
在设定的时间内(以秒为单位),钱包自动锁定
请求示例:
curl http://localhost:8888/v1/wallet/ set_timeout -X POST -d '10'
参数:
 

参数

参数类型

是否必须

时间秒数

Int

 
 
 
 
 
 
 
返回数据:
{}
数据说明:
10、交易签名
curl http://localhost:8888/v1/wallet/sign_transaction-X POST -d '[{
                 "ref_block_num":21453,
                 "ref_block_prefix":3165644999,
                 "expiration":"2017-12-08T10:28:49",
                 "scope":["initb", "initc"],
                 "read_scope":[],
                 "messages":[{
                         "code":"currency",
                         "type":"transfer",
                         "authorization":[{
                                  "account":"initb",
                                  "permission":"active"
                         }],
                         "data":"000000008093dd74000000000094dd74e803000000000000"
                }],
                 "signatures":[]
        },
        ["EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV"],""
]’
查看交易信息及智能合约,找到与此数据相关数据
 
11、获取最新区块信息
描述:
获取最新区块信息
请求示例:
curlhttp://127.0.0.1:8888/v1/chain/get_info
参数:

返回数据:
{
"server_version":"b2eb1667",
"head_block_num":259590,
"last_irreversible_block_num":259573,
"head_block_id":"0003f60677f3707f0704f16177bf5f007ebd45eb6efbb749fb1c468747f72046",
"head_block_time":"2017-12-10T17:05:36",
"head_block_producer":"initp",
"recent_slots":"1111111111111111111111111111111111111111111111111111111111111111",
"participation_rate":"1.00000000000000000"
}
数据说明:
head_block_num:区块高度,第一个区块为1,依次累加
last_irreversible_block_num:上一个不可逆转的区块高度(一般和当前区块间隔14以上)
head_block_id:区块id
head_block_producer:打包此区块的节点
 
12、查询区块
 
描述:
根据给定的区块高度或区块id获取指定区块信息
请求示例:
$ curl http://127.0.0.1:8888/v1/chain/get_block -X POST -d'{"block_num_or_id":5}'
$ curlhttp://127.0.0.1:8888/v1/chain/get_block -X POST -d'{"block_num_or_id":0000000445a9f27898383fd7de32835d5d6a978cc14ce40d9f327b5329de796b}'
 
参数:
区块高度/区块id
返回数据:
{
    "previous":"0000000674814e01a617ea58921f1e347b9904bd8b61c16de5d4efc73b5bd674",
    "timestamp":"2018-05-05T00:05:22",
    "transaction_merkle_root":"0000000000000000000000000000000000000000000000000000000000000000",
    "producer": "inith",
    " producer_changes":[],
    "producer_signature":"20121bd1010967fdc4839806250855652282106efbb3b16dfa768b9369f4fd5e2b011d742c8bfd61321b90c9282f1ecb33b6e9a6969a30ee8330a589065e05d910",
    "cycles": [],
    "id":"00000007103c0be2b7fa5710a3f92f4e740ccc1e5b5e201e49b4b776d599168d",
    "block_num": 7,
    " ref_block_prefix":274201271
}
数据说明:
previous:父区块id
Timestamp:产生时间
transaction_merkle_root:默克尔根节点
Producer:生产节点
producer_signature:生产节点签名
producer_changes:生产者列表的变化
Id:区块id
block_num:区块高度
ref_block_prefix:引用的区块前缀
 
13、获取账号信息
 
描述:
根据账号获取账号详情
请求示例:
$ curlhttp://127.0.0.1:8888/v1/chain/get_account -X POST -d'{"account_name":"inita"}'
参数:
账号名
返回数据:
{
    "account_name": "inita",
    "eos_balance": "999999.9992 EOS",
    " staked_balance": "0.0000EOS",
    " unstaking_balance":"0.0000 EOS",
    "last_unstaking_time": "1969-12-31T23:59:59",
    "permissions": [{
        "perm_name": "active",
        "parent": "owner",
        "required_auth": {
           "threshold": 1,
           "keys": [{
               "key":"EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
               "weight": 1
           }],
           "accounts": []
        }
    }, {
        "perm_name": "owner",
        "parent": "",
        "required_auth": {
           "threshold": 1,
           "keys": [{
               "key":"EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
               "weight": 1
           }],
           "accounts": []
        }
    }]
}
数据说明:
eos_balance:账户的eos余额
Permissions:权限设定,inita账号有两个权限,active和owner,owner为拥有者,也是active的父权限,一般操作由active权限执行,owner可以用来恢复active
Threshold:阈值
Weight:权重,当权重达到阈值时,才有权限操作
Key:公钥
 
14、 获取智能合约
描述:
获取智能合约abi
请求示例:
curlhttp://127.0.0.1:8888/v1/chain/get_code -X POST -d '{"account_name":"currency"}'
参数:
智能合约名(同时也是部署此智能合约的名字,二者都用currency这个名字)
返回数据:
{
       "name":"currency",
       "code_hash":"a1c8c84b4700c09c8edb83522237439e33cf011a4d7ace51075998bd002e04c9",
       "wast":"(module\n  (type $0 (func (parami64 i64 i32) (result i32)))\n ...truncated",
       "abi":{
               "types":[{
                        "new_type_name":"account_name",
                        "type":"name"
               }],
               "structs":[{
                        "name":"transfer",
                        "base":"",
                        "fields":[{
                                        "name":"from",
                                        "type":"account_name"
                                },
                                {
                                        "name":"to",
                                        "type":"account_name"
                                },
                                {
                                        "name":"quantity",
                                        "type":"uint64"
                                }
                        ]
               },{
                        "name":"account",
                        "base":"",
                        "fields":[{
                                        "name":"key",
                                        "type":"name"
                                },
                                {
                                        "name":"balance",
                                        "type":"uint64"
                                }
                        ]
               }],
               "actions":[{
                        "name":"transfer",
                        "type":"transfer"
               }],
               "tables":[{
                        "name":"account",
                        "type":"account",
                        "index_type":"i64",
                        "key_names":["key"],
                        "key_types":["name"]
               }]
       }
数据说明:
此只能合约currency部署在currency账号上面,主要功能为交易”transfer”
 
 
15、get_table_rows
描述:
获取指定账号在智能合约上的数据
请求示例:
$ curl http://127.0.0.1:8888/v1/chain/get_table_rows -XPOST -d '{"scope":"inita","code":"currency", "table":"account","json": true}'
$ curl http://127.0.0.1:8888/v1/chain/get_table_rows -XPOST -d '{"scope":"inita","code":"currency", "table":"account","json": true, "lower_bound":0, "upper_bound":-1,"limit":10}'
参数:
Scope:帐户名
Code:智能合约名
Table:表名
Json:是否以json格式显示
 
返回数据:
{
"rows": [{
"key": "account",
"balance": 1000
}],
"more": false
}
数据说明:
Key:表名
Balance:所查询账户余额
16、json转16进制
描述:
把json序列化,结果常用作交易中的参数
请求示例:
$ curlhttp://127.0.0.1:8888/v1/chain/abi_json_to_bin -X POST -d'{"code":"currency","action":"transfer","args":{"from":"currency","to":"inita", "quantity":100}}'
参数:
Code:智能合约名
action:智能合约中的规定动作,transfer为转账动作
initb账户向initc账户转账1000
返回数据:
{"binargs":"000000008093dd74000000000094dd74e803000000000000","required_scope":[],"required_auth":[]}
数据说明:
 
17、16进制转json
描述:
把上面得到的结果反序列化
请求示例:
$ curl http://127.0.0.1:8888/v1/chain/abi_bin_to_json-X POST -d '{"code":"currency","action":"transfer","binargs":"000000008093dd74000000000094dd74e803000000000000"}'
参数:
Code:智能合约名
action:智能合约中的规定动作,transfer为转账动作
Json:是否以json格式显示
 
返回数据:
{
"args": {
"from": "initb",
"to": "initc",
"quantity": 1000
},
"required_scope": [],
"required_auth": []
}
数据说明:
 
18、发送交易
此方法需要一条json格式的交易信息,会尝试把交易在链上执行。
响应:
成功会返回 HTTP200和交易id
{
'transaction_id' : "..."
}
交易是在本地发送的,并不意味着交易已经上链。
若发生错误会返回http400(无效的参数)或500(内部服务器错误)
HTTP/1.1 500 Internal Server Error
Content-Length: 1466
...error message...
请求示例:
下面的示例假定了一条转账操作,这里的ref_block_num和ref_block_prefix是 “/v1/chain/get_block +上一个不可逆的区块”提供的结果. 你还需要使用 /v1/wallet/sign_transaction获得正确的签名
curl http://localhost:8888/v1/chain/push_transaction -X POST -d'{"ref_block_num":10975,"ref_block_prefix":2385262967,"expiration":"2018-05-10T17:26:21","scope":["currency","inita"],"messages":[{"code":"currency","type":"transfer","recipients":["currency","inita"],"authorization":[{"account":"currency","permission":"active"}],"data":"0000001e4d75af46000000000093dd746400000000000000"}],"signatures":["1f7088ee47102461c2e1e25f7e17034802c3d067e82c5e02b81951199a00e7dbe74018f7c3a3d5eac9a89e30cde3b7705add8ebccf7b50f3675d60789b3a2ca7f5"],"authorizations":[]}'
19、发送多条交易
请求示例:
curl http://localhost:8888/v1/chain/push_transaction -XPOST -d '[{"ref_block_num":10975,"ref_block_prefix":2385262967,"expiration":"2018-05-10T17:26:21","scope":["currency","inita"],"messages":[{"code":"currency","type":"transfer","recipients":["currency","inita"],"authorization":[{"account":"currency","permission":"active"}],"data":"0000001e4d75af46000000000093dd746400000000000000"}],"signatures":["1f7088ee47102461c2e1e25f7e17034802c3d067e82c5e02b81951199a00e7dbe74018f7c3a3d5eac9a89e30cde3b7705add8ebccf7b50f3675d60789b3a2ca7f5"],"authorizations":[]}, {"ref_block_num":10975,"ref_block_prefix":2385262967,"expiration":"2018-05-10T17:26:21","scope":["currency","initb"],"messages":[{"code":"currency","type":"transfer","recipients":["currency","initb"],"authorization":[{"account":"currency","permission":"active"}],"data":"0000001e4d75af46000000008093dd746400000000000000"}],"signatures":["1f7088ee47102461c2e1e25f7e17034802c3d067e82c5e02b81951199a00e7dbe74018f7c3a3d5eac9a89e30cde3b7705add8ebccf7b50f3675d60789b3a2ca7f5"],"authorizations":[]}]'
20、获取所需key
Getrequired keys to sign a transaction from list of your keys.
从列表中获取签署一条交易所需的key
请求示例:
curl http://localhost:8888/v1/chain/ get_required_keys-X POST -d '{"transaction":{"ref_block_num":"100","ref_block_prefix":"137469861","expiration":"2017-09-25T06:28:49","scope":["initb","initc"],"actions":[{"code":"currency","type":"transfer","recipients":["initb","initc"],"authorization":[{"account":"initb","permission":"active"}],"data":"000000000041934b000000008041934be803000000000000"}],"signatures":[],"authorizations":[]},"available_keys":["EOS4toFS3YXEQCkuuw1aqDLrtHim86Gz9u3hBdcBw5KNPZcursVHq","EOS7d9A3uLe6As66jzN8j44TXJUqJSK3bFjjEEqR4oTvNAB3iM9SA","EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV"]}'
返回数据:
{
"required_keys": [
"EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV"
]
}
 
自定义接口:
 
创建私钥
 
POST http://localhost:7001/createKey
 
签名校验
 
POST http://localhost:7001/sign/verify
 
创建账户
 
POST http://localhost:7001/account/create
 
转账
 
POST http://localhost:7001/transfer
 
查询账户
 
GET http://localhost:7001/account/info/:account
 
查询余额
 
GET http://localhost:7001/balance/:contract/:account
 
交易查询
 
GET http://localhost:7001/transactions/:name/:page/:size
 

你可能感兴趣的:(EOS)