发布时间: 2018-05-16 06:49:00
和这个:https://blog.csdn.net/guokaikevin/article/details/79060095(包含了发送)
命令形如;
$ curl 127.0.0.1:8545 -X POST --header "Content-Type: application/json" --data '{"jsonrpc":"2.0", "method":"eth_call", "params":[{"to":"0xf2eab3a2034d3f6b63734d2e08262040e3ff7b48", "data":"0x70a082310000000000000000000000008f5ae589fd2467396c8b25559637dbf5c4401464"}, "latest"], "id": 33}'
说明:
1. curl 命令, 后面紧跟geth的 本地地址
2. 加上HEADER
3. method: eth_call 这个命令,没啥好说的
4.1 params, 1. to: 这个是你要查询的token的地址(Contract Address) , 例如; 0xf2eab3a2034d3f6b63734d2e08262040e3ff7b48 这个是Candy 这个Token的地址. https://etherscan.io/token/0xf2eab3a2034d3f6b63734d2e08262040e3ff7b48
4.2 params. 2. data, 这里就有意思了. 这里是要查询的参数. 这个参数是根据转换来的
"0x" 表示这是个16进制的东东
"70a08231" 表示geth 的 get_balance方法的sha3转换的前8个字节"
( transfer(address,uint256): 0xa9059cbb balanceOf(address):0x70a08231 这是两个重要方法,更多参考 https://blog.csdn.net/u012491783/article/details/81090500 )
"000000000000000000000000" 是用来占位的. (这个跟下面的地址加起来是64位) (固定24位长度)
"8f5ae589fd2467396c8b25559637dbf5c4401464" 是要查询的目标的钱包地址 (固定40位长度)
"latest" 表示查询到最高的区块. 当前最新的区块.
5. 结果形如:
{"jsonrpc":"2.0","id":33,"result":"0x000000000000000000000000000000000000000000000977c9c54af82a3c0000"}
后面的这个 result, 表示当前钱包的 CANDY余额.是个16进制的数字. 进过转换后就可以得到正常的数字了.
command = %Q{curl --data '{ \ "method":"personal_sendTransaction", \ "params":[ \ { \ "from":"#{from}", \ // from: 从哪个钱包 "to":"#{contract_address}", \ // 这个必须是erc-20的合约地址 // 这里规定了3部分: 1. 方法名称, 2. 发送给谁。 3. 数量多少。 "data":"0x#{ABI_TRANSFER}#{ABI_ZERO_PLACEHOLDER}#{to}#{get_amount_for_abi(amount)}", \ // 这里是固定的 0x0. "value":"0x0", \ // 这里需要是20w 的 gas, 不能是 eth -> eth 时候的 9w gas. "gas":"#{TRANSACTION_GAS_LIMIT}", \ "gasPrice": "#{gas_price}" \ }, \ "#{password}" \ ], \ "id":#{rpc_id}, \ "jsonrpc":"2.0" \ }' -H "Content-Type: application/json" -X POST #{ENV['ETH_RPC_SERVER']}} Rails.logger.info "== send_transaction command: #{command}"
下面是个例子:
curl --data '{ "method":"personal_sendTransaction", "params":[ { "from":"0x9270afa6d078bf4882c3e8e8ae868df00049bb45", "to":"0x977b0584b50cdd64e2f8185b682a1f256448c7c8", "data":"0xa9059cbb000000000000000000000000925ccd95f17640be707c4c8ae713177dfc91ce7e00000000000000000000000000000000000000000000003635c9adc5dea00000", "value":"0x0", "gas":"0x33450", "gasPrice": "0x12a05f200" }, "EiSaO2S!密码" ], "id":0, "jsonrpc":"2.0" }' -H "Content-Type: application/json" -X POST http://172.31.12.248:8800Back