Transactions
如何使用“eth_sendTransaction”呼叫合約並獲取日誌?
我已經部署:
contract test { function multiply(uint a) returns(uint d) { return a * 7; } }
我可以用“ eth_call ”呼叫合約:
mpsp@ubuntu-slave2:~$ curl http://10.10.67.217:8545 --data '{"jsonrpc":"2.0","method":"eth_call","params":[{"to": "0x8e6f99f04148b1fb918cde7e44a94375f94dc745","data":"0xc6888fa10000000000000000000000000000000000000000000000000000000000000007"},"latest"],"id":1}'
輸出是:
{"jsonrpc":"2.0","id":1,"result":"0x0000000000000000000000000000000000000000000000000000000000000031"}
但是當我使用“ eth_sendTransaction ”呼叫合約時,挖礦後使用“ eth_getTransactionReceipt ”得到結果,合約似乎沒有被呼叫。這是我的步驟:
eth_sendTransaction
run: mpsp@ubuntu-slave2:~$ curl http://10.10.67.217:8545 --data '{"jsonrpc":"2.0","method":"eth_sendTransaction","params":[{"from":"0xc60ec7c68d47814288bdfdaa71b88ff922d735a7","to":"0x8e6f99f04148b1fb918cde7e44a94375f94dc745","gas":"0xC350","gasPrice":"0x1388","data":"0xc6888fa10000000000000000000000000000000000000000000000000000000000000003"}],"id":1}' outputs: {"jsonrpc":"2.0","id":1,"result":"0xcff6d91d1693abe876c25ba03a58bc6ca693078b3a90e836f656e0dddb08a4cd"}
eth_getTransactionReceipt
run: curl http://10.10.67.217:8545 --data '{"jsonrpc":"2.0","method":"eth_getTransactionReceipt","params":["0xcff6d91d1693abe876c25ba03a58bc6ca693078b3a90e836f656e0dddb08a4cd"],"id":1}' outputs: {"jsonrpc":"2.0","id":1,"result":{"blockHash":"0x26e23d45caf0c57159e88d9835c573a79f59a4fad0e7a7d70ea7a49780d14448","blockNumber":"0xc3a1","contractAddress":null,"cumulativeGasUsed":"0x5449","from":"0xc60ec7c68d47814288bdfdaa71b88ff922d735a7","gasUsed":"0x5449","logs":[],"root":"c42b14419677df59e3f593fccf03ea28f65bbd8927dcc9239dad6e77eb85f1a3","to":"0x8e6f99f04148b1fb918cde7e44a94375f94dc745","transactionHash":"0xcff6d91d1693abe876c25ba03a58bc6ca693078b3a90e836f656e0dddb08a4cd","transactionIndex":"0x0"}}
eth_getTransactionReceipt 輸出中的日誌為空。
你有什麼建議嗎?
謝謝!
測試合約沒有發出事件,這就是沒有日誌的原因。返回值不會自動包含在日誌中。
嘗試:
contract test { event R(uint x); function multiply(uint a) returns(uint d) { R(a * 7); return a * 7; } }
如果這不起作用,您可能需要增加汽油(您還剩下大約 28,423 汽油)。
除了使用事件之外,如果我真正想做的只是在交易收據中生成日誌條目,我有時會發現直接呼叫“低級”Solidity 日誌功能更簡單:
log1( value, 'log_topic');
將創建一個包含
value
主題的日誌條目"log_topic"
。
log2(value,topic1,topic2)
允許您創建一個包含 2 個主題的條目,依此類推。