我用PHP中開發了一個以太坊塊資源管理器,併成功地與個人服務器Geth節點創建了JSON-RPC通訊。然而,當我試圖找出最後一個區塊時,我陷入了困境。我在https://ethereum.gitbooks.io/frontier-guide/content/rpc.html 中讀到了很不錯的內容,可是我沒有任何方法去查詢到以太坊節點的哪個是最後一個塊。一旦我獲得了塊哈希,我就能夠有接口檢索完整的信息塊,但我不知道如何找到最新的塊哈希。php
API接口中eth_blockNumber
應該返回最新的塊號,可是如何獲得哈希?html
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
,來獲得最新塊。git
你能夠參考這個以太坊JSON RPC APIjson
若是想系統的學習php開發以太坊的話推薦一個很受歡迎的在線互動教程: php以太坊,主要是介紹使用php進行智能合約開發交互,進行帳號建立、交易、轉帳、代幣開發以及過濾器和事件等內容。api