所有代码网上都有,这里只是记录。文末有参考链接
EOS测试链采坑记录:
git clone https://github.com/eosio/eos --recursive
cd eos
git checkout v1.0.7
git submodule update --init --recursive
./eosio_build.sh -s EOS
mkdir JungleTestnet
cd JungleTestnet
git clone https://github.com/CryptoLions/EOS-Jungle-Testnet.git ./
chmod +x ./*.sh
chmod +x ./Wallet/*.sh
- server address: p2p-server-address = YOUR_NODE_IP_ADDRESS:9876
- your producer name: producer-name = YOUR_BP_NAME
- created producer keypair: private-key = ["YOUR_PUBKEY","YOUR_PRIVKEY"]
- replace p2p-peer-address list with fresh generated on monitor site: http://jungle.cryptolions.io/#p2p
启动节点服务:
./start.sh
启动钱包服务:
./Wallet/start_wallet.sh
创建钱包:
./cleos.sh wallet create
该命令创建默认钱包 “default” 可以用-n指定钱包名称,保存返回的密码
解锁钱包:
./cleos.sh wallet unlock --password xxxxx
密码是创建钱包时返回的密码
导入之前用第三方创建的账户私钥:
./cleos.sh wallet import
不指定钱包导入默认钱包
获取测试token:http://jungle.cryptolions.io/#faucet
首次启动节点服务:
./start.sh --delete-all-blocks --genesis-json genesis.json
同步比较慢可以修改config.ini配置参数 sync-fetch-span,默认是2000,正常够了
等同步完成,节点有了,钱包有了,账户有了,命令行可以随便玩,参考资料不是特别多,尝试了几个,基本没坑。
记录使用json rpc调用过程,这个比较坑,文档暂时也没找到太好的参考。
因为我是linux服务器远程调用,需要再config.ini添加配置:
plugin = eosio::wallet_api_plugin
修改:/Wallet/start_wallet.sh
默认监听127.0.0.1:3000,
远程调用需要修改监听,启动会有安全警告或错误,但是不影响测试。
解锁和签名需要用到钱包服务。
记录一笔EOS转账记录:
获取区块高度
/v1/chain/get_info
request:
{}
response:
{
"server_version": "79651199",
"chain_id": "038f4b0fc8ff18a4f0842a8f0564611f6e96e8535901dd45e43ac8691a1c4dca",
"head_block_num": 2906706,
"last_irreversible_block_num": 2906388,
"last_irreversible_block_id": "002c5914abe87ad85a01083e85d118f7e50b096be5cc82f3fb52267e6b9bed17",
"head_block_id": "002c5a52b417a436e49de2cf6f3187daf319dc9d4bc42864cf1a3a05cf042db4",
"head_block_time": "2018-06-28T09:00:21.500",
"head_block_producer": "nakedmolerat",
"virtual_block_cpu_limit": 200000000,
"virtual_block_net_limit": 1048576000,
"block_cpu_limit": 199900,
"block_net_limit": 1048576
}
根据区块编号获取区块信息
block_num_or_id 是info返回的 head_block_num
v1/chain/get_block
request:{
"block_num_or_id":2906706
}
response:
{
"timestamp": "2018-06-28T09:00:21.500",
"producer": "nakedmolerat",
"confirmed": 0,
"previous": "002c5a51f31b247c31158356bb8c5b35d836c9a5a9ea69231431bd8b281580b0",
"transaction_mroot": "0000000000000000000000000000000000000000000000000000000000000000",
"action_mroot": "8cba383c3603a0c3325f19567092043b088cedaa7e94c2dbca0b7a8700eed940",
"schedule_version": 93,
"new_producers": null,
"header_extensions": [],
"producer_signature": "SIG_K1_KfCS4P8CGAfxPdqg6PCj5VKMpC1pHMDpp5Dqu2K2f2Povmhny7kiDNPDPXvQEQiepmYCNKRKenveRDtbLfpz3Y8asbg3Di",
"transactions": [],
"block_extensions": [],
"id": "002c5a52b417a436e49de2cf6f3187daf319dc9d4bc42864cf1a3a05cf042db4",
"block_num": 2906706,
"ref_block_prefix": 3487735268
}
查看账户信息,账户是用第三方工具生成的第一个,第二个可以在自己节点上生成,这里具体账户规则、权限没有深入研究,按照网上文档参考生成暂时无坑。
v1/chain/get_account
{
"account_name": "eric"
}
response:
{
"account_name": "eric",
"head_block_num": 2909991,
"head_block_time": "2018-06-28T09:28:40.000",
"privileged": false,
"last_code_update": "1970-01-01T00:00:00.000",
"created": "2018-06-27T01:12:52.500",
"core_liquid_balance": "19894.9761 EOS",
"ram_quota": 519496,
"net_weight": 1000000,
"cpu_weight": 1000000,
"net_limit": {
"used": 480,
"available": 20111024,
"max": 20111504
},
"cpu_limit": {
"used": 11585,
"available": 3826485,
"max": 3838070
},
"ram_usage": 3734,
"permissions": [
{
"perm_name": "active",
"parent": "owner",
"required_auth": {
"threshold": 1,
"keys": [
{
"key": "EOS6tgnE8NgDvBdvdumw83zVEs9oHJrvt3r79rp5SeS1ns7Sxy91e",
"weight": 1
}
],
"accounts": [],
"waits": []
}
},
{
"perm_name": "owner",
"parent": "",
"required_auth": {
"threshold": 1,
"keys": [
{
"key": "EOS6tgnE8NgDvBdvdumw83zVEs9oHJrvt3r79rp5SeS1ns7Sxy91e",
"weight": 1
}
],
"accounts": [],
"waits": []
}
}
],
"total_resources": {
"owner": "eric",
"net_weight": "100.0000 EOS",
"cpu_weight": "100.0000 EOS",
"ram_bytes": 519496
},
"self_delegated_bandwidth": {
"from": "eric",
"to": "eric",
"net_weight": "100.0000 EOS",
"cpu_weight": "100.0000 EOS"
},
"refund_request": null,
"voter_info": {
"owner": "eric",
"proxy": "",
"producers": [],
"staked": 2200000,
"last_vote_weight": "0.00000000000000000",
"proxied_vote_weight": "0.00000000000000000",
"is_proxy": 0
}
}
解锁钱包
v1/wallet/unlock
request:["default", "PW5JhWc7azWi66Bj7N2pBc5DqdBnXsHQwsz5HbZ51USiRuynAp4ro"]
response:
{}
交易信息
/v1/chain/abi_json_to_bin
request:{
"code": "eosio.token",
"action": "transfer",
"args": {
"from": "eric",
"to": "bitker2121er",
"quantity": "1 EOS",
"memo": "001"
}
}
response:
{
"binargs": "000000000080dc55705510415c05b33b010000000000000000454f530000000003303031"
}
v1/chain/get_required_keys
request:
{
"available_keys": [
"EOS8QBiUwkGpgpvayx2V5Ktty6haMjVPpWrWdT5hUf3z5gFps9ujC",
"EOS6tgnE8NgDvBdvdumw83zVEs9oHJrvt3r79rp5SeS1ns7Sxy91e"
],
"transaction": {
"actions": [
{
"account": "eosio.token",
"authorization": [
{
"actor": "eric",
"permission": "active"
}
],
"data": "000000000080dc55705510415c05b33b010000000000000000454f530000000003303031",
"name": "transfer"
}
],
"context_free_actions": [
],
"context_free_data": [
],
"delay_sec": 0,
"expiration": "2018-06-28T06:50:45.500",
"max_kcpu_usage": 0,
"max_net_usage_words": 0,
"ref_block_num": 2884794,
"ref_block_prefix": 27519887,
"signatures": [
]
}
}
response:
{
"required_keys": [
"EOS6tgnE8NgDvBdvdumw83zVEs9oHJrvt3r79rp5SeS1ns7Sxy91e"
]
}
用发起转账的账户公钥签名
/v1/wallet/sign_transaction
request:[
{
"ref_block_num": 2929481,
"ref_block_prefix": 1572717041,
"expiration": "2018-06-28T12:20:52.500",
"actions": [
{
"account": "eosio.token",
"name": "transfer",
"authorization": [
{
"actor": "eric",
"permission": "active"
}
],
"data": "000000000080dc55705510415c05b33b40420f000000000004454f5300000000086d656d6f20303031"
}
],
"signatures": []
},
[
"EOS6tgnE8NgDvBdvdumw83zVEs9oHJrvt3r79rp5SeS1ns7Sxy91e"
],
"038f4b0fc8ff18a4f0842a8f0564611f6e96e8535901dd45e43ac8691a1c4dca"
]
response:
{
"expiration": "2018-06-28T12:20:52",
"ref_block_num": 45897,
"ref_block_prefix": 1572717041,
"max_net_usage_words": 0,
"max_cpu_usage_ms": 0,
"delay_sec": 0,
"context_free_actions": [],
"actions": [
{
"account": "eosio.token",
"name": "transfer",
"authorization": [
{
"actor": "eric",
"permission": "active"
}
],
"data": "000000000080dc55705510415c05b33b40420f000000000004454f5300000000086d656d6f20303031"
}
],
"transaction_extensions": [],
"signatures": [
"SIG_K1_K2F18yTGe6jeME2pVNhz19NEWdgkw2AKBZbkcnXZj24vYtPSMjRRFrBTGNoJRYQjMh41YY7BjZfCKZgd85Tg4SaSapZTUA"
],
"context_free_data": []
}
发起交易:
v1/chain/push_transaction
request:{
"compression": "none",
"transaction": {
"ref_block_num": 2929481,
"ref_block_prefix": 1572717041,
"expiration": "2018-06-28T12:20:52.500",
"context_free_actions": [],
"actions": [
{
"account": "eosio.token",
"name": "transfer",
"authorization": [
{
"actor": "eric",
"permission": "active"
}
],
"data": "000000000080dc55705510415c05b33b40420f000000000004454f5300000000086d656d6f20303031"
}
],
"transaction_extensions": []
},
"signatures": [
"SIG_K1_K2F18yTGe6jeME2pVNhz19NEWdgkw2AKBZbkcnXZj24vYtPSMjRRFrBTGNoJRYQjMh41YY7BjZfCKZgd85Tg4SaSapZTUA"
]
}
response:
{
"transaction_id": "d53f50ef54a58ea6921ea84330336c45631ab3bd17b3b89671fc9f6e5db163c2",
"processed": {
"id": "d53f50ef54a58ea6921ea84330336c45631ab3bd17b3b89671fc9f6e5db163c2",
"receipt": {
"status": "executed",
"cpu_usage_us": 1605,
"net_usage_words": 17
},
"elapsed": 1605,
"net_usage": 136,
"scheduled": false,
"action_traces": [
{
"receipt": {
"receiver": "eosio.token",
"act_digest": "c4ee8324faf84c7afae49e2e32abc92eeca3165e30ae2477e1ec01b2a965842c",
"global_sequence": 11340787,
"recv_sequence": 739112,
"auth_sequence": [
[
"eric",
19
]
],
"code_sequence": 1,
"abi_sequence": 1
},
"act": {
"account": "eosio.token",
"name": "transfer",
"authorization": [
{
"actor": "eric",
"permission": "active"
}
],
"data": {
"from": "eric",
"to": "bitker2121er",
"quantity": "100.0000 EOS",
"memo": "memo 001"
},
"hex_data": "000000000080dc55705510415c05b33b40420f000000000004454f5300000000086d656d6f20303031"
},
"elapsed": 982,
"cpu_usage": 0,
"console": "",
"total_cpu_usage": 0,
"trx_id": "d53f50ef54a58ea6921ea84330336c45631ab3bd17b3b89671fc9f6e5db163c2",
"inline_traces": [
{
"receipt": {
"receiver": "eric",
"act_digest": "c4ee8324faf84c7afae49e2e32abc92eeca3165e30ae2477e1ec01b2a965842c",
"global_sequence": 11340788,
"recv_sequence": 10,
"auth_sequence": [
[
"eric",
20
]
],
"code_sequence": 1,
"abi_sequence": 1
},
"act": {
"account": "eosio.token",
"name": "transfer",
"authorization": [
{
"actor": "eric",
"permission": "active"
}
],
"data": {
"from": "eric",
"to": "bitker2121er",
"quantity": "100.0000 EOS",
"memo": "memo 001"
},
"hex_data": "000000000080dc55705510415c05b33b40420f000000000004454f5300000000086d656d6f20303031"
},
"elapsed": 11,
"cpu_usage": 0,
"console": "",
"total_cpu_usage": 0,
"trx_id": "d53f50ef54a58ea6921ea84330336c45631ab3bd17b3b89671fc9f6e5db163c2",
"inline_traces": []
},
{
"receipt": {
"receiver": "bitker2121er",
"act_digest": "c4ee8324faf84c7afae49e2e32abc92eeca3165e30ae2477e1ec01b2a965842c",
"global_sequence": 11340789,
"recv_sequence": 5,
"auth_sequence": [
[
"eric",
21
]
],
"code_sequence": 1,
"abi_sequence": 1
},
"act": {
"account": "eosio.token",
"name": "transfer",
"authorization": [
{
"actor": "eric",
"permission": "active"
}
],
"data": {
"from": "eric",
"to": "bitker2121er",
"quantity": "100.0000 EOS",
"memo": "memo 001"
},
"hex_data": "000000000080dc55705510415c05b33b40420f000000000004454f5300000000086d656d6f20303031"
},
"elapsed": 20,
"cpu_usage": 0,
"console": "",
"total_cpu_usage": 0,
"trx_id": "d53f50ef54a58ea6921ea84330336c45631ab3bd17b3b89671fc9f6e5db163c2",
"inline_traces": []
}
]
}
],
"except": null
}
}
这整个流程都有完整的参考,按理没坑,但是:
我尝试调用曾经返回:
{这是个大坑,参考了许多文档,我这个是由于签名导致的,注意签名最后一个参数,是你的chainid,如果你有同样的错误,可以检查下是不是由于这个导致的。
参考链接:
https://developers.eos.io/eosio-nodeos/reference#wallet_sign_trx
https://developers.eos.io/eosio-cleos/reference#cleos-version
https://github.com/CryptoLions/EOS-Jungle-Testnet
https://steemit.com/eos/@noprom/eos-rpc