Json-Rpc
自定義字節碼記錄數據但不在 eth_call 上返回,為什麼不呢?
我正在為項目創建自定義字節碼
0x4160005260206000a0 // OP-Codes // COINBASE // PUSH1 0x00 // MSTORE // PUSH1 0x20 // PUSH1 0x20 // LOG0
創建上述內容時,交易收據在其日誌中包含以下數據
0x00000000000000000000000085f7c2480b66ca340e9f2a534dbf8b660137889f
但是由於某種原因,當我嘗試相同但返回操作碼
f3
時,0x4160005260206000f3 // OP-Codes // COINBASE // PUSH1 0x00 // MSTORE // PUSH1 0x20 // PUSH1 0x20 // RETURN
但它返回
{ "jsonrpc": "2.0", "id": 8, "result": "0x" }
當我期待
{ "jsonrpc": "2.0", "id": 8, "result": "0x00000000000000000000000085f7c2480b66ca340e9f2a534dbf8b660137889f" }
確切的呼叫看起來像這樣
// to create contract { "jsonrpc":"2.0", "method":"eth_sendTransaction", "params": [ { "from": "{{Account1}}", "data": "0x4160005260206000f3" } ], "id": 1 } > response { "jsonrpc": "2.0", "id": 1, "result": "0xe81e280e6fa833e9f65b1d933fcb2183b7241f46e52afe7ff1501759d01d52ed" } // To get the transaction receipt { "jsonrpc":"2.0", "method":"eth_getTransactionReceipt", "params": [ "0xe81e280e6fa833e9f65b1d933fcb2183b7241f46e52afe7ff1501759d01d52ed" ], "id": 1 } > response { "jsonrpc": "2.0", "id": 1, "result": { "blockHash": "0x40cce6d74ceafaf0dd005a83adc614fc6bbc438ad4bcadb014f3cb2ccdd0b775", "blockNumber": "0xd1", "contractAddress": "0xee408b2d602d94e06a9d0241cc9dc0092eed1d53", "cumulativeGasUsed": "0xe891", "from": "0x85f7c2480b66ca340e9f2a534dbf8b660137889f", "gasUsed": "0xe891", "logs": [], "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "status": "0x1", "to": null, "transactionHash": "0xe81e280e6fa833e9f65b1d933fcb2183b7241f46e52afe7ff1501759d01d52ed", "transactionIndex": "0x0" } } // Finally making the call { "jsonrpc":"2.0", "method":"eth_call", "params": [{ "from": "{{Account1}}", "to": "0xee408b2d602d94e06a9d0241cc9dc0092eed1d53" }, "latest"], "id": 1 } > response { "jsonrpc": "2.0", "id": 1, "result": "0x" }
上述呼叫是使用郵遞員以 JSON RPC API 模式對我的本地開發 geth 區塊鏈進行的。
我在混音中嘗試了這個,它按預期工作
web3.eth.sendTransaction({ data: “0x684160005260206000f360005260096017f3", from: "0x...."})
輸入數據的工作方式如下
684160005260206000f3 PUSH 4160005260206000f3 ; payload 6000 PUSH 0 52 MSTORE
從 0 記憶體地址開始保存有效負載。由於它是 9 個字節,它將用零填充到 32 個字節。
address content 00 00000000000000000000000000000000 10 000000000000004160005260206000f3
我們的有效載荷從位置 23 開始,它的長度是 9 個字節,我們在 RETURN 之前推送長度和偏移量
6009 PUSH 9 6017 PUSH 23 f3 RETURN
現在我們可以驗證部署的合約是有效載荷
> web3.eth.getCode("<Contract_address>") 0x4160005260206000f3