您好,登錄后才能下訂單哦!
php怎樣使用JSON-RPC查找以太坊中的最新塊哈希hash值,很多新手對(duì)此不是很清楚,為了幫助大家解決這個(gè)難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來學(xué)習(xí)下,希望你能有所收獲。
我用PHP中開發(fā)了一個(gè)以太坊塊資源管理器,并成功地與我的服務(wù)器Geth節(jié)點(diǎn)建立了JSON-RPC通信。然而,當(dāng)我試圖找出最后一個(gè)區(qū)塊時(shí),我陷入了困境。我在https://ethereum.gitbooks.io/frontier-guide/content/rpc.html 中讀到了很不錯(cuò)的內(nèi)容,但是我沒有任何方法去查詢到以太坊節(jié)點(diǎn)的哪一個(gè)是最后一個(gè)塊。一旦我得到了塊哈希,我就可以有接口檢索完整的信息塊,但我不知道如何找到最新的塊哈希。
API接口中eth_blockNumber
應(yīng)該返回最新的塊號(hào),但是如何得到哈希?
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
,來得到最新塊。
看完上述內(nèi)容是否對(duì)您有幫助呢?如果還想對(duì)相關(guān)知識(shí)有進(jìn)一步的了解或閱讀更多相關(guān)文章,請(qǐng)關(guān)注億速云行業(yè)資訊頻道,感謝您對(duì)億速云的支持。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。