命令行接口实现一条命令 ae转账

###########################################中文版
命令行接口实现一条命令 ae转账
使用linux expect交互实现 ae批量转账shell接口
sudo apt-get install tcl tk expect

tx shell接收4个参数,参数1:收款地址,参数2:发送数量(整数)想要小数自己改代码,参数3,发送钱包的当前nonce ,参数4,当前块高(程序里设定解锁高度比当前高10个块)
vi tx #贴入内容如下 如果ubuntu18 版本 vi 出现错乱行错误可以执行: echo “set pastetoggle=” >> ~/.vimrc

#!/usr/bin/expect
set recepientAdd [lindex $argv 0]
set sendAmount [lindex $argv 1]
set accountNonce [lindex $argv 2]
set blockHeight [lindex $argv 3]
incr accountNonce
set unlockHeight [expr {$blockHeight + 10}]
puts $recepientAdd
puts $sendAmount
puts $accountNonce
puts $unlockHeight

spawn bin/epoch remote_console
expect “)1>"
send “{ok, EncryptedPrivKeyBin} = file:read_file("generated_keys/key").\r”
expect "
)2>”
send “Password = "secretpassword123".\r”
expect “)3>"
send “DecryptedPrivKeyBin = crypto:block_decrypt(aes_ecb, crypto:hash(sha256, Password), EncryptedPrivKeyBin).\r”
expect "
)4>”
send “{ok, EncryptedPubKeyBin} = file:read_file("generated_keys/key.pub").\r”
expect “)5>"
send “DecryptedPubKeyBin = crypto:block_decrypt(aes_ecb, crypto:hash(sha256, Password), EncryptedPubKeyBin).\r”
expect "
)6>”
send “RecepientAddress = <<"{recepientAdd}\">>.\r" expect "*)7>" send "{ok, RecepientPubKey} = aehttp_api_encoder:safe_decode(account_pubkey, RecepientAddress).\r" expect "*)8>" send "Nonce = {accountNonce}.\r”
expect “)9>"
send “{ok, SpendTx} = aec_spend_tx:new(#{
sender_id => aec_id:create(account, DecryptedPubKeyBin),
recipient_id => aec_id:create(account, RecepientPubKey),
amount => round({sendAmount}.0e18), fee => 20000, ttl => {blockHeight},
nonce => ${accountNonce},
payload => <<"">>
}).\r”
expect "
)10>”
send “EncodedSpendTx = aetx:serialize_to_binary(SpendTx),
EncodedSpendTxForNetwork = aec_governance:add_network_id(EncodedSpendTx),
Signature = enacl:sign_detached(EncodedSpendTxForNetwork, DecryptedPrivKeyBin),
SignedSpendTx = aetx_sign:new(SpendTx,[Signature]).\r”
expect “)11>"
send “aec_tx_pool:push(SignedSpendTx).\r”
expect "
)12>”

例子:
先找到你node钱包的当前nonce 数。
#curl -G ‘http://127.0.0.1:3013/v2/accounts/ak_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
回显:
{“balance”:733,“id”:“ak_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”,“nonce”:4}
对!nonce is 4 就是4,记住!
随便找个浏览器看下当前块高。看到现在是几就行,行不用怕一会变,记住这个数。比如 7948
https://explorer.aepps.com or https://www.aeknow.org/

可以发送了!发送格式例子:
./tx ak_2a9icm3Ed3BSboch3L2VomrgurgRzr46Uw1BTromTx3uWUS5P6 10 3 7948
注意! ak_2a9icm3Ed3BSboch3L2VomrgurgRzr46Uw1BTromTx3uWUS5P6 是我的接收地址,改成你交易的接受地址。

(注意!执行./tx时 确保你当前在epoch目录下,确保你node在运行着!)

如果本文给你带来了方便,请给我捐一点AE吧!谢谢!

地址: ak_2a9icm3Ed3BSboch3L2VomrgurgRzr46Uw1BTromTx3uWUS5P6
一点就行!谢谢!

QQ:86558732

如果你的node在正常运行,运行还提示 node is not running
请不要用它编译好的epoch版本按照

自行下载源代码编译node即可。!!!重装前别忘了备份你的钱包!