eos構造裸交易并簽名
1. 需要到鏈上獲取到的資料
- 獲取
ref_block_prefixget_info以獲取最后一個不可逆的塊號:last_irreversible_block_num
這是一個螢屏截圖get_block獲取有關該區塊的資訊:這是螢屏截圖- 從中找出
ref_block_prefix的資料
2.1 之后本地可離線構造出未簽名交易資料
-
然后計算
ref_block_numconst ref_block_num = (info.last_irreversible_block_num) & 0xFFFF -
expiration:- 當前系統時間(按與節點相同的時區算) + 300秒 (cleos默認是30秒)
-
編碼構造
data:-
組裝物件
{ "code": "eosio.token", "action": "transfer", "args": { "from": "fromaccount", "to": "toaccount", "quantity": "1.0000 EOS", "memo": "memo" } } -
編碼
參考 https://developers.eos.io/eosio-nodeos/reference#abi_bin_to_json
參考 https://github.com/OracleChain/PocketEOS-IOS/blob/ca34cd96ebaa773d806a6aa7ddf913504d6a66d5/pocketEOS/SecureModule/EC/EosByteWriter.m
-
通過api介面構造action所需的
datacurl http://192.168.1.201:30088/v1/chain/abi_json_to_bin -X POST -d '{"code":"eosio.token", "action":"transfer", "args":{"from":"xxx", "to":"xxx", "quantity":"xxx", "memo":"xxx"}}'
-
-
簽名
- chainid
- sha256
- ECDSA-K1
構造結果(未簽名)
{
"compression": "none",
"transaction": {
"expiration": "2018-08-01T06:11:23",
"ref_block_num": 10855,
"ref_block_prefix": 473148127,
"max_net_usage_words": 0,
"max_cpu_usage_ms": 0,
"delay_sec": 0,
"context_free_actions": [],
"actions": [{
"account": "eosio.token",
"name": "transfer",
"authorization": [{
"actor": "fromaccount",
"permission": "active"
}],
"data": "0000000000ea305500000000487a2b9d102700000000000004454f53000000001163726561746564206279206e6f70726f6d"
}],
"transaction_extensions": [],
"signatures": null,
"context_free_data": []
},
"signatures": ["SIG_K1_JwLVG5pRdhvLfJGWkDEBPa7wdLbNeqeRFdvFrKDEryahSwCRpPb75m4auZh8frq6cXsm3dHit8GMbmuuBWxEjH"]
}
2.2 也可以通過cleos命令構造未簽名交易資料
cleos push action eosio.token transfer '{"from":"xxx", "to":"xxx", "quantity":"xxx", "memo":"xxx"}' -p fromaccount@active -jds
-j: print result as json
-d: don't broadcast transaction to the network (just print to stdout)
-s: Specify if unlocked wallet keys should be used to sign transaction
3. 簽名并發送交易
使用上面構造的 [transaction json], 和傳入的私鑰簽名, 并發送交易
./cleos sign -p -k [private-key] '[transaction json]'
-k,--private-key TEXT The private key that will be used to sign the transaction
-p,--push-transaction Push transaction after signing
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/186473.html
標籤:其他
上一篇:研究生學習生活日記——第二次組會
