您好,登錄后才能下訂單哦!
php怎樣使用JSON-RPC查找以太坊中的最新塊哈希hash值,很多新手對此不是很清楚,為了幫助大家解決這個難題,下面小編將為大家詳細講解,有這方面需求的人可以來學習下,希望你能有所收獲。
我用PHP中開發了一個以太坊塊資源管理器,并成功地與我的服務器Geth節點建立了JSON-RPC通信。然而,當我試圖找出最后一個區塊時,我陷入了困境。我在https://ethereum.gitbooks.io/frontier-guide/content/rpc.html 中讀到了很不錯的內容,但是我沒有任何方法去查詢到以太坊節點的哪一個是最后一個塊。一旦我得到了塊哈希,我就可以有接口檢索完整的信息塊,但我不知道如何找到最新的塊哈希。
API接口中eth_blockNumber
應該返回最新的塊號,但是如何得到哈希?
user@Kumquat:~$ curl -X POST --data '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["latest", false],"id":1}' localhost:8545 {"jsonrpc":"2.0","id":1,"result":{"difficulty":"0x31962a3fc82b", "extraData":"0x4477617266506f6f6c", "gasLimit":"0x47c3d8", "gasUsed":"0x0", "hash":"0x78bfef68fccd4507f9f4804ba5c65eb2f928ea45b3383ade88aaa720f1209cba", "logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "miner":"0x2a65aca4d5fc5b5c859090a6c34d164135398226", "nonce":"0xa5e8fb780cc2cd5e", "number":"0x1e655a", "parentHash":"0x8b535592eb3192017a527bbf8e3596da86b3abea51d6257898b2ced9d3a83826", "receiptRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", "sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", "size":"0x20e", "stateRoot":"0xdc6ed0a382e50edfedb6bd296892690eb97eb3fc88fd55088d5ea753c48253dc", "timestamp":"0x579f4981", "totalDifficulty":"0x25cff06a0d96f4bee", "transactions":[], "transactionsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", "uncles":[]}}
用latest
也可以用eth_blockNumber
,來得到最新塊。
看完上述內容是否對您有幫助呢?如果還想對相關知識有進一步的了解或閱讀更多相關文章,請關注億速云行業資訊頻道,感謝您對億速云的支持。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。