|
3 | 3 | [](https://github.com/graphprotocol/graph-node/actions/workflows/ci.yml?query=branch%3Amaster)
|
4 | 4 | [](docs/getting-started.md)
|
5 | 5 |
|
6 |
| -[The Graph](https://thegraph.com/) is a protocol for building decentralized applications (dApps) quickly on Ethereum and IPFS using GraphQL. |
| 6 | +[The Graph](https://thegraph.com/) is a protocol that organizes and serves web3 data. |
7 | 7 |
|
8 |
| -Graph Node is an open source Rust implementation that event sources the Ethereum blockchain to deterministically update a data store that can be queried via the GraphQL endpoint. |
| 8 | +Graph Node extracts and transforms blockchain data and makes the transformed |
| 9 | +data available to decentralized applications (dApps) via GraphQL queries. |
| 10 | +You can find more details on how to write these transformations, called |
| 11 | +_subgraphs_, in the official [Graph |
| 12 | +documentation](https://thegraph.com/docs/en/subgraphs/quick-start/). If you |
| 13 | +are not familiar already with subgraphs, we highly recommend at least |
| 14 | +reading through that documentation first. |
9 | 15 |
|
10 |
| -For detailed instructions and more context, check out the [Getting Started Guide](docs/getting-started.md). |
| 16 | +The rest of this page is geared towards two audiences: |
11 | 17 |
|
12 |
| -## Quick Start |
| 18 | +1. Subgraph developers who want to run `graph-node` locally so they can test |
| 19 | + their subgraphs during development |
| 20 | +2. Developers who want to contribute bug fixes and features to `graph-node` |
| 21 | + itself |
| 22 | + |
| 23 | +## Running `graph-node` from Docker images |
| 24 | + |
| 25 | +For subgraph developers, it is highly recommended to use prebuilt Docker |
| 26 | +images to set up a local `graph-node` environment. Please read [these |
| 27 | +instructions](./docker/README.md) to learn how to do that. |
| 28 | + |
| 29 | +## Running `graph-node` from source |
| 30 | + |
| 31 | +This is usually only needed for developers who want to contribute to `graph-node`. |
13 | 32 |
|
14 | 33 | ### Prerequisites
|
15 | 34 |
|
16 | 35 | To build and run this project you need to have the following installed on your system:
|
17 | 36 |
|
18 | 37 | - Rust (latest stable) – [How to install Rust](https://www.rust-lang.org/en-US/install.html)
|
19 |
| - - Note that `rustfmt`, which is part of the default Rust installation, is a build-time requirement. |
20 |
| -- PostgreSQL – [PostgreSQL Downloads](https://www.postgresql.org/download/) |
| 38 | + has general instructions. Run `rustup install stable` in this directory to make |
| 39 | + sure all required components are installed. The `graph-node` code assumes that the |
| 40 | + latest available `stable` compiler is used. |
| 41 | +- PostgreSQL – [PostgreSQL Downloads](https://www.postgresql.org/download/) lists |
| 42 | + downloads for almost all operating systems. For OSX users, we highly recommend |
| 43 | + using [Postgres.app](https://postgresapp.com/). Linux users can simply use the |
| 44 | + Postgres version that comes with their distribution. |
21 | 45 | - IPFS – [Installing IPFS](https://docs.ipfs.io/install/)
|
22 | 46 | - Protobuf Compiler - [Installing Protobuf](https://grpc.io/docs/protoc-installation/)
|
23 | 47 |
|
24 | 48 | For Ethereum network data, you can either run your own Ethereum node or use an Ethereum node provider of your choice.
|
25 | 49 |
|
26 |
| -**Minimum Hardware Requirements:** |
27 |
| - |
28 |
| -- To build graph-node with `cargo`, 8GB RAM are required. |
29 |
| - |
30 |
| -### Docker |
31 |
| - |
32 |
| -The easiest way to run a Graph Node is to use the official Docker compose setup. This will start a Postgres database, IPFS node, and Graph Node. |
33 |
| -[Follow the instructions here](./docker/README.md). |
34 |
| - |
35 |
| -### Running a Local Graph Node |
36 |
| - |
37 |
| -This is a quick example to show a working Graph Node. It is a [subgraph for Gravatars](https://github.com/graphprotocol/example-subgraph). |
38 |
| - |
39 |
| -1. Install IPFS and run `ipfs init` followed by `ipfs daemon`. |
40 |
| -2. Install PostgreSQL and run `initdb -D .postgres -E UTF8 --locale=C` followed by `pg_ctl -D .postgres -l logfile start` and `createdb graph-node`. |
41 |
| -3. If using Ubuntu, you may need to install additional packages: |
42 |
| - - `sudo apt-get install -y clang libpq-dev libssl-dev pkg-config` |
43 |
| -4. In the terminal, clone https://github.com/graphprotocol/example-subgraph, and install dependencies and generate types for contract ABIs: |
| 50 | +### Create a database |
44 | 51 |
|
45 |
| -``` |
46 |
| -yarn |
47 |
| -yarn codegen |
48 |
| -``` |
49 |
| - |
50 |
| -5. In the terminal, clone https://github.com/graphprotocol/graph-node, and run `cargo build`. |
51 |
| - |
52 |
| -Once you have all the dependencies set up, you can run the following: |
53 |
| - |
54 |
| -``` |
55 |
| -cargo run -p graph-node --release -- \ |
56 |
| - --postgres-url postgresql://USERNAME[:PASSWORD]@localhost:5432/graph-node \ |
57 |
| - --ethereum-rpc NETWORK_NAME:[CAPABILITIES]:URL \ |
58 |
| - --ipfs 127.0.0.1:5001 |
59 |
| -``` |
60 |
| - |
61 |
| -Try your OS username as `USERNAME` and `PASSWORD`. For details on setting |
62 |
| -the connection string, check the [Postgres |
63 |
| -documentation](https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING). |
64 |
| -`graph-node` uses a few Postgres extensions. If the Postgres user with which |
65 |
| -you run `graph-node` is a superuser, `graph-node` will enable these |
66 |
| -extensions when it initializes the database. If the Postgres user is not a |
67 |
| -superuser, you will need to create the extensions manually since only |
68 |
| -superusers are allowed to do that. To create them you need to connect as a |
69 |
| -superuser, which in many installations is the `postgres` user: |
| 52 | +Once Postgres is running, you need to issue the following commands to create a database |
| 53 | +and set it up so that `graph-node` can use it. The name of the `SUPERUSER` depends |
| 54 | +on your installation, but is usually `postgres` or your username. |
70 | 55 |
|
71 | 56 | ```bash
|
72 |
| - psql -q -X -U <SUPERUSER> graph-node <<EOF |
| 57 | +psql -U <SUPERUSER> <<EOF |
| 58 | +create user graph with password '<password>'; |
| 59 | +create database "graph-node" with owner=graph template=template0 encoding='UTF8' locale='C'; |
73 | 60 | create extension pg_trgm;
|
74 |
| -create extension pg_stat_statements; |
75 | 61 | create extension btree_gist;
|
76 | 62 | create extension postgres_fdw;
|
77 |
| -grant usage on foreign data wrapper postgres_fdw to <USERNAME>; |
| 63 | +grant usage on foreign data wrapper postgres_fdw to graph; |
78 | 64 | EOF
|
79 | 65 |
|
| 66 | +# Save this in ~/.bashrc or similar |
| 67 | +export POSTGRES_URL=postgresql://graph:<password>@localhost:5432/graph-node |
80 | 68 | ```
|
81 | 69 |
|
82 |
| -This will also spin up a GraphiQL interface at `http://127.0.0.1:8000/`. |
83 |
| - |
84 |
| -6. With this Gravatar example, to get the subgraph working locally run: |
85 |
| - |
86 |
| -``` |
87 |
| -yarn create-local |
88 |
| -``` |
89 |
| - |
90 |
| -Then you can deploy the subgraph: |
| 70 | +With this setup, the URL that you will use to have `graph-node` connect to the |
| 71 | +database will be `postgresql://graph:<password>@localhost:5432/graph-node`. If |
| 72 | +you ever need to manually inspect the contents of your database, you can do |
| 73 | +that by running `psql $POSTGRES_URL`. |
91 | 74 |
|
92 |
| -``` |
93 |
| -yarn deploy-local |
94 |
| -``` |
| 75 | +### Build `graph-node` |
95 | 76 |
|
96 |
| -This will build and deploy the subgraph to the Graph Node. It should start indexing the subgraph immediately. |
97 |
| - |
98 |
| -### Command-Line Interface |
| 77 | +To build `graph-node`, clone this repository and run this command at the |
| 78 | +root of the repository: |
99 | 79 |
|
| 80 | +```bash |
| 81 | +export GRAPH_LOG=debug |
| 82 | +cargo run -p graph-node --release -- \ |
| 83 | + --postgres-url $POSTGRES_URL \ |
| 84 | + --ethereum-rpc NETWORK_NAME:[CAPABILITIES]:URL \ |
| 85 | + --ipfs 127.0.0.1:5001 |
100 | 86 | ```
|
101 |
| -USAGE: |
102 |
| - 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> |
103 |
| -
|
104 |
| -FLAGS: |
105 |
| - --debug Enable debug logging |
106 |
| - -h, --help Prints help information |
107 |
| - -V, --version Prints version information |
108 |
| -
|
109 |
| -OPTIONS: |
110 |
| - --admin-port <PORT> Port for the JSON-RPC admin server [default: 8020] |
111 |
| - --elasticsearch-password <PASSWORD> |
112 |
| - Password to use for Elasticsearch logging [env: ELASTICSEARCH_PASSWORD] |
113 | 87 |
|
114 |
| - --elasticsearch-url <URL> |
115 |
| - Elasticsearch service to write subgraph logs to [env: ELASTICSEARCH_URL=] |
| 88 | +The argument for `--ethereum-rpc` contains a network name (e.g. `mainnet`) and |
| 89 | +a list of provider capabilities (e.g. `archive,traces`). The URL is the address |
| 90 | +of the Ethereum node you want to connect to, usually a `https` URL, so that the |
| 91 | +entire argument might be `mainnet:archive,traces:https://provider.io/some/path`. |
116 | 92 |
|
117 |
| - --elasticsearch-user <USER> User to use for Elasticsearch logging [env: ELASTICSEARCH_USER=] |
118 |
| - --ethereum-ipc <NETWORK_NAME:[CAPABILITIES]:FILE> |
119 |
| - Ethereum network name (e.g. 'mainnet'), optional comma-separated capabilities (eg full,archive), and an Ethereum IPC pipe, separated by a ':' |
| 93 | +When `graph-node` starts, it prints the various ports that it is listening on. |
| 94 | +The most important of these is the GraphQL HTTP server, which is by default |
| 95 | +is at `http://localhost:8000`. You can use routes like `/subgraphs/name/<subgraph-name>` |
| 96 | +and `/subgraphs/id/<IPFS hash>` to query subgraphs once you have deployed them. |
120 | 97 |
|
121 |
| - --ethereum-polling-interval <MILLISECONDS> |
122 |
| - How often to poll the Ethereum node for new blocks [env: ETHEREUM_POLLING_INTERVAL=] [default: 500] |
| 98 | +### Deploying a Subgraph |
123 | 99 |
|
124 |
| - --ethereum-rpc <NETWORK_NAME:[CAPABILITIES]:URL> |
125 |
| - Ethereum network name (e.g. 'mainnet'), optional comma-separated capabilities (eg 'full,archive'), and an Ethereum RPC URL, separated by a ':' |
126 |
| -
|
127 |
| - --ethereum-ws <NETWORK_NAME:[CAPABILITIES]:URL> |
128 |
| - Ethereum network name (e.g. 'mainnet'), optional comma-separated capabilities (eg `full,archive), and an Ethereum WebSocket URL, separated by a ':' |
129 |
| -
|
130 |
| - --node-id <NODE_ID> |
131 |
| - A unique identifier for this node instance. Should have the same value between consecutive node restarts [default: default] |
132 |
| -
|
133 |
| - --http-port <PORT> Port for the GraphQL HTTP server [default: 8000] |
134 |
| - --ipfs <HOST:PORT> HTTP address of an IPFS node |
135 |
| - --postgres-url <URL> Location of the Postgres database used for storing entities |
136 |
| - --subgraph <[NAME:]IPFS_HASH> Name and IPFS hash of the subgraph manifest |
137 |
| - --ws-port <PORT> Port for the GraphQL WebSocket server [default: 8001] |
138 |
| -``` |
| 100 | +Instructions for how to deploy subgraphs can be found [here](https://thegraph.com/docs/en/subgraphs/developing/introduction/) After setting up `graph-cli` as described there, you can deploy a subgraph to your local Graph Node instance. |
139 | 101 |
|
140 | 102 | ### Advanced Configuration
|
141 | 103 |
|
142 | 104 | The command line arguments generally are all that is needed to run a
|
143 | 105 | `graph-node` instance. For advanced uses, various aspects of `graph-node`
|
144 | 106 | can further be configured through [environment
|
145 |
| -variables](https://github.com/graphprotocol/graph-node/blob/master/docs/environment-variables.md). Very |
146 |
| -large `graph-node` instances can also split the work of querying and |
147 |
| -indexing across [multiple databases](./docs/config.md). |
148 |
| - |
149 |
| -## Project Layout |
150 |
| - |
151 |
| -- `node` — A local Graph Node. |
152 |
| -- `graph` — A library providing traits for system components and types for |
153 |
| - common data. |
154 |
| -- `core` — A library providing implementations for core components, used by all |
155 |
| - nodes. |
156 |
| -- `chain/ethereum` — A library with components for obtaining data from |
157 |
| - Ethereum. |
158 |
| -- `graphql` — A GraphQL implementation with API schema generation, |
159 |
| - introspection, and more. |
160 |
| -- `mock` — A library providing mock implementations for all system components. |
161 |
| -- `runtime/wasm` — A library for running WASM data-extraction scripts. |
162 |
| -- `server/http` — A library providing a GraphQL server over HTTP. |
163 |
| -- `store/postgres` — A Postgres store with a GraphQL-friendly interface |
164 |
| - and audit logs. |
165 |
| - |
166 |
| -## Roadmap |
167 |
| - |
168 |
| -🔨 = In Progress |
169 |
| - |
170 |
| -🛠 = Feature complete. Additional testing required. |
171 |
| - |
172 |
| -✅ = Feature complete |
173 |
| - |
174 |
| - |
175 |
| -| Feature | Status | |
176 |
| -| ------- | :------: | |
177 |
| -| **Ethereum** | | |
178 |
| -| Indexing smart contract events | ✅ | |
179 |
| -| Handle chain reorganizations | ✅ | |
180 |
| -| **Mappings** | | |
181 |
| -| WASM-based mappings| ✅ | |
182 |
| -| TypeScript-to-WASM toolchain | ✅ | |
183 |
| -| Autogenerated TypeScript types | ✅ | |
184 |
| -| **GraphQL** | | |
185 |
| -| Query entities by ID | ✅ | |
186 |
| -| Query entity collections | ✅ | |
187 |
| -| Pagination | ✅ | |
188 |
| -| Filtering | ✅ | |
189 |
| -| Block-based Filtering | ✅ | |
190 |
| -| Entity relationships | ✅ | |
191 |
| -| Subscriptions | ✅ | |
| 107 | +variables](https://github.com/graphprotocol/graph-node/blob/master/docs/environment-variables.md). |
192 | 108 |
|
| 109 | +Very large `graph-node` instances can also be configured using a |
| 110 | +[configuration file](./docs/config.md) That is usually only necessary when |
| 111 | +the `graph-node` needs to connect to multiple chains or if the work of |
| 112 | +indexing and querying needs to be split across [multiple databases](./docs/config.md). |
193 | 113 |
|
194 | 114 | ## Contributing
|
195 | 115 |
|
|
0 commit comments