EOS系列 - 使用cleos(命令行)发起裸包交易

eos构造裸交易并签名

1. 需要到链上获取到的数据

  • 获取 ref_block_prefix
    1. get_info以获取最后一个不可逆的块号:last_irreversible_block_num
      这是一个屏幕截图
    2. get_block获取有关该区块的信息:这是屏幕截图
    3. 从中找出 ref_block_prefix 的数据

2.1 之后本地可离线构造出未签名交易数据

构造结果(未签名)

{
    "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
  • 4
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 12
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

搬砖魁首

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值