The Graph 是一種使用 GraphQL 在以太坊和 IPFS 上快速建立去中心化應用程式 (dApp) 的協定。
Graph Node 是一個開源 Rust 實現,它的事件來源來自以太坊區塊鏈,以確定性地更新可透過 GraphQL 端點查詢的資料儲存。
有關詳細說明和更多上下文,請查看入門指南。
要建置並執行此項目,您需要在系統上安裝以下軟體:
rustfmt
是預設 Rust 安裝的一部分,是建置時的要求。對於以太坊網路數據,您可以運行自己的以太坊節點或使用您選擇的以太坊節點提供者。
最低硬體需求:
cargo
建立圖形節點,需要 8GB RAM。運行圖形節點最簡單的方法是使用官方 Docker compose 設定。這將啟動 Postgres 資料庫、IPFS 節點和圖形節點。請按照此處的說明進行操作。
這是一個顯示工作圖形節點的快速範例。它是 Gravatars 的子圖。
ipfs init
然後執行ipfs daemon
。initdb -D .postgres -E UTF8 --locale=C
然後執行pg_ctl -D .postgres -l logfile start
和createdb graph-node
。sudo apt-get install -y clang libpq-dev libssl-dev pkg-config
yarn
yarn codegen
cargo build
。設定完所有依賴項後,您可以執行以下命令:
cargo run -p graph-node --release --
--postgres-url postgresql://USERNAME[:PASSWORD]@localhost:5432/graph-node
--ethereum-rpc NETWORK_NAME:[CAPABILITIES]:URL
--ipfs 127.0.0.1:5001
嘗試使用您的作業系統使用者名稱作為USERNAME
和PASSWORD
。有關設定連接字串的詳細信息,請查看 Postgres 文件。 graph-node
使用一些 Postgres 擴充功能。如果執行graph-node
的 Postgres 用戶是超級用戶, graph-node
會在初始化資料庫時啟用這些擴充功能。如果 Postgres 用戶不是超級用戶,您將需要手動建立擴展,因為只有超級用戶才可以這樣做。要建立它們,您需要以超級使用者身分連接,在許多安裝中都是postgres
使用者:
psql -q -X -U < SUPERUSER > graph-node << EOF
create extension pg_trgm;
create extension pg_stat_statements;
create extension btree_gist;
create extension postgres_fdw;
grant usage on foreign data wrapper postgres_fdw to <USERNAME>;
EOF
這也將在http://127.0.0.1:8000/
上啟動 GraphiQL 介面。
yarn create-local
然後您可以部署子圖:
yarn deploy-local
這將建立子圖並將其部署到圖節點。它應該立即開始為子圖建立索引。
USAGE:
graph-node [FLAGS] [OPTIONS] --ethereum-ipc <NETWORK_NAME:FILE> --ethereum-rpc <NETWORK_NAME:URL> --ethereum-ws <NETWORK_NAME:URL> --ipfs <HOST:PORT> --postgres-url <URL>
FLAGS:
--debug Enable debug logging
-h, --help Prints help information
-V, --version Prints version information
OPTIONS:
--admin-port <PORT> Port for the JSON-RPC admin server [default: 8020]
--elasticsearch-password <PASSWORD>
Password to use for Elasticsearch logging [env: ELASTICSEARCH_PASSWORD]
--elasticsearch-url <URL>
Elasticsearch service to write subgraph logs to [env: ELASTICSEARCH_URL=]
--elasticsearch-user <USER> User to use for Elasticsearch logging [env: ELASTICSEARCH_USER=]
--ethereum-ipc <NETWORK_NAME:[CAPABILITIES]:FILE>
Ethereum network name (e.g. 'mainnet'), optional comma-separated capabilities (eg full,archive), and an Ethereum IPC pipe, separated by a ':'
--ethereum-polling-interval <MILLISECONDS>
How often to poll the Ethereum node for new blocks [env: ETHEREUM_POLLING_INTERVAL=] [default: 500]
--ethereum-rpc <NETWORK_NAME:[CAPABILITIES]:URL>
Ethereum network name (e.g. 'mainnet'), optional comma-separated capabilities (eg 'full,archive'), and an Ethereum RPC URL, separated by a ':'
--ethereum-ws <NETWORK_NAME:[CAPABILITIES]:URL>
Ethereum network name (e.g. 'mainnet'), optional comma-separated capabilities (eg `full,archive), and an Ethereum WebSocket URL, separated by a ':'
--node-id <NODE_ID>
A unique identifier for this node instance. Should have the same value between consecutive node restarts [default: default]
--http-port <PORT> Port for the GraphQL HTTP server [default: 8000]
--ipfs <HOST:PORT> HTTP address of an IPFS node
--postgres-url <URL> Location of the Postgres database used for storing entities
--subgraph <[NAME:]IPFS_HASH> Name and IPFS hash of the subgraph manifest
--ws-port <PORT> Port for the GraphQL WebSocket server [default: 8001]
命令列參數通常是運行graph-node
實例所需的全部內容。對於進階用途,可以透過環境變數進一步配置graph-node
的各個方面。非常大的graph-node
實例還可以跨多個資料庫拆分查詢和索引工作。
node
— 本地圖節點。graph
— 提供系統元件特徵和通用資料類型的函式庫。core
— 提供核心元件實作的函式庫,供所有節點使用。chain/ethereum
— 一個包含用於從以太坊取得資料的元件的函式庫。graphql
— 具有 API 模式產生、內省等功能的 GraphQL 實作。mock
— 為所有系統元件提供模擬實作的函式庫。runtime/wasm
— 用於執行 WASM 資料擷取腳本的函式庫。server/http
— 透過 HTTP 提供 GraphQL 伺服器的函式庫。store/postgres
— 具有 GraphQL 友善介面和審核日誌的 Postgres 儲存。 ? = 進行中
? = 功能完成。需要額外的測試。
✅ = 功能完整
特徵 | 地位 |
---|---|
以太坊 | |
索引智能合約事件 | ✅ |
處理鏈條重組 | ✅ |
對應 | |
基於 WASM 的映射 | ✅ |
TypeScript 到 WASM 工具鏈 | ✅ |
自動產生的 TypeScript 類型 | ✅ |
GraphQL | |
透過ID查詢實體 | ✅ |
查詢實體集合 | ✅ |
分頁 | ✅ |
濾 | ✅ |
基於區塊的過濾 | ✅ |
實體關係 | ✅ |
訂閱 | ✅ |
請檢查 CONTRIBUTING.md 以了解我們使用的開發流程和約定。以下是優先考慮的問題清單。
版權所有 © 2018-2019 Graph Protocol, Inc. 和貢獻者。
Graph 獲得 MIT 授權和 Apache 授權 2.0 版的雙重授權。
除非適用法律要求或書面同意,否則根據許可分發的軟體均以「原樣」分發,不帶任何明示或暗示的保證或條件。請參閱許可證,了解許可證下管理權限和限制的特定語言。