預設配置啟動GraphQL服務後,在瀏覽器中訪問http://localhost:8547 會看到如下介面。
3.2 GraphQL使用示例
GraphQL的語法詳見官網,這裡不贅述。https://spec.graphql.cn[3] 另外,在GraphQL瀏覽器中,也有請求的示例和補全,使用起來相對比較簡單。
1、查詢網路區塊同步狀態
query {
syncing {
currentBlock
highestBlock
knownStates
pulledStates
startingBlock
}
}
2、查詢事件
{
logs(filter: {fromBlock: 0,
addresses: ["0xf105795bf5d1b1894e70bd04dc846898ab19fa62"],
topics: [["0x0f0c27adfd84b60b6f456b0e87cdccb1e5fb9603991588d87fa99f5b6b61e670"]]}
) {
transaction {
hash
from {
address
}
block{
number
timestamp
}
}
}
}
3、查詢區塊資訊
query c{
blocks(from:100, to:120) {
number
hash
timestamp
}
}
4、查詢交易
{
transaction(hash:"0x0f0c27adfd84b60b6f456b0e87cdccb1e5fb9603991588d87fa99f5b6b61e670") {
nonce
from {
address
}
to {
address
}
}
}
3.3 GraphQL對JSON-RPC的向後相容
GraphQL實現了JSON-RPC節點介面提供的大部分只讀功能。可以將現有的RPC呼叫對映到GraphQL查詢, 所有介面實現大家可以在原文[4]檢視。
3.4 Quorum對GraphQL的支援
Quorum在v2.6.0版本中將Geth升級到了1.9.7,並支援GraphQL。在以太坊GraphQL服務的基礎上,增加了對隱私交易的支援。
# Transaction is an Ethereum transaction.
type Transaction {
...
# IsPrivate is an indicator of Quorum private transaction
isPrivate: Boolean
# PrivateInputData is the actual payload of Quorum private transaction
privateInputData: Bytes
}
查詢隱私交易的語法:
transaction(hash: "0x58462fa0b6074a8feb5d9b8cd0e6bb7ef4d1528471396070d9ae617c5dee40a8") {
isPrivate
inputData
privateInputData
}
References
[1] Geth: https://learnblockchain.cn/tags/Geth
[2] EIP1767: https://learnblockchain.cn/docs/eips/eip-1767.html
[3] https://spec.graphql.cn: https://spec.graphql.cn/
[4] 原文: https://learnblockchain.cn/article/1062