This subgraph does not work locally. The queries execute and always return blank JSON values.
My streaming thegraph's terminal log is pretty quiet and only showing new blocks and this repeating warning:
graph-node_1 | Aug 22 07:57:28.967 WARN Trying again after eth_call RPC call failed (attempt #26) with result Err(Web3Error(Transport("Unexpected response status code: 403 Forbidden"))), block_hash: 0x359d1dc4f14f9a07cba3ae8416958978ce98f78ad7b8d505925dad9722081f04, block_number: 10008355, subgraph_id: Qmem2vQPxhZGYf32D76oFaXp36ck6cy3qzj86gDNvoW4Da, component: SubgraphInstanceManager
The v1 one works (https://github.com/graphprotocol/uniswap-subgraph) with the exact same installation method (with v1 queries only obviously.)
I have no idea why it doesn't work. I've spent hours trying to get it to work. I also have no idea what I'm doing. Am I the only one in the world who's trying to run this locally? ยฏ\(ใ)/ยฏ
Does it need an archive node to work?
I have tried installing it with and without docker on my home Ubuntu 20.04 computer and on a new, unmanaged Ubuntu 20.04 VPS. Both had all the ports open and firewalls off. Also, I tried both with Infura and a synced, fast-sync geth node. I only tried the v1 subgraph after to see if that works.
Needs to be fixed: For v1 and v2 in the package.json the "davekaj/uniswap" are exactly the same, causing an installation conflict if you want to run both
v1: "create-local": "graph create davekaj/uniswap --node http://127.0.0.1:8020",
v2: "create-local": "graph create davekaj/uniswap --node http://127.0.0.1:8020",
Local thegraph w/Uniswap v2 GraphQL POST (from my setup below)
http://IP:8000/subgraphs/name/davekaj/uniswap
{
uniswapFactories(first: 1) {
pairCount
totalVolumeUSD
totalLiquidityUSD
}
}
output (always empty JSON):
{
"data": {
"uniswapFactories": []
}
}
Local thegraph w/Uniswap V1 GraphQL POST
http://IP:8000/subgraphs/name/davekaj/uniswap (installed by itself since the URL structure conflicts with v2)
{
uniswap(id: "1") {
exchangeCount
totalVolumeInEth
totalLiquidityInEth
totalVolumeUSD
totalLiquidityUSD
totalTokenBuys
totalTokenSells
totalAddLiquidity
totalRemoveLiquidity
}
}
output
{
"data": {
"uniswap": {
"exchangeCount": 158,
"totalAddLiquidity": "1118",
"totalLiquidityInEth": "21825.539445390657723786",
"totalLiquidityUSD": "2652750.80474073422812526480807834",
"totalRemoveLiquidity": "382",
"totalTokenBuys": "10527",
"totalTokenSells": "8719",
"totalVolumeInEth": "48010.664356604455559231",
"totalVolumeUSD": "5683710.521175278208857501357184344"
}
}
}
Uniswap v2 subgraph docker setup
Fresh Ubuntu 20.04 install on an unmanaged VPS with no firewall
# apt update
# apt dist-upgrade
Install Rust
# curl https://sh.rustup.rs -sSf | sh
default option 1 selected
stable installed - rustc 1.45.2 (d3fb005a3 2020-07-31)
# source $HOME/.cargo/env
Install the correct yarn
# apt remove cmdtest
# curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
# echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
# apt update
# apt install yarn
# yarn --version
1.22.4
Install libsecret
prevents this error when installing uniswap-v2-subgraph:
"prebuild-install WARN install libsecret-1.so.0: cannot open shared object file: No such file or directDone"
# apt install -y libsecret-1-dev
Install docker + docker-compose
# apt install -y docker-compose
# docker -v
Docker version 19.03.8, build afacb8b7f0
Install extra Ubuntu packages
from https://github.com/graphprotocol/graph-node#running-a-local-graph-node
# sudo apt-get install -y clang libpq-dev libssl-dev pkg-config
Install + run thegraph and make sure it's syncing eth blocks
~# git clone https://github.com/graphprotocol/graph-node.git
~/graph-node/docker# vim docker-compose.yml
~/graph-node/docker# docker-compose up
Starting docker_ipfs_1 ... done
Starting docker_postgres_1 ... done
Recreating docker_graph-node_1 ... done
Attaching to docker_ipfs_1, docker_postgres_1, docker_graph-node_1
ipfs_1 | Changing user to ipfs
ipfs_1 | ipfs version 0.4.23
ipfs_1 | Found IPFS fs-repo at /data/ipfs
ipfs_1 | Initializing daemon...
ipfs_1 | go-ipfs version: 0.4.23-6ce9a35
ipfs_1 | Repo version: 7
ipfs_1 | System version: amd64/linux
ipfs_1 | Golang version: go1.12.16
postgres_1 |
postgres_1 | PostgreSQL Database directory appears to contain a database; Skipping initialization
postgres_1 |
postgres_1 | 2020-08-22 06:48:03.705 UTC [1] LOG: starting PostgreSQL 12.4 (Debian 12.4-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
postgres_1 | 2020-08-22 06:48:03.709 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
postgres_1 | 2020-08-22 06:48:03.709 UTC [1] LOG: listening on IPv6 address "::", port 5432
postgres_1 | 2020-08-22 06:48:03.711 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres_1 | 2020-08-22 06:48:03.730 UTC [24] LOG: database system was interrupted; last known up at 2020-08-22 06:45:17 UTC
postgres_1 | 2020-08-22 06:48:03.795 UTC [24] LOG: database system was not properly shut down; automatic recovery in progress
postgres_1 | 2020-08-22 06:48:03.796 UTC [24] LOG: redo starts at 0/1645C40
postgres_1 | 2020-08-22 06:48:03.796 UTC [24] LOG: invalid record length at 0/1645C78: wanted 24, got 0
postgres_1 | 2020-08-22 06:48:03.796 UTC [24] LOG: redo done at 0/1645C40
postgres_1 | 2020-08-22 06:48:03.804 UTC [1] LOG: database system is ready to accept connections
ipfs_1 | Swarm listening on /ip4/127.0.0.1/tcp/4001
ipfs_1 | Swarm listening on /ip4/172.18.0.2/tcp/4001
ipfs_1 | Swarm listening on /p2p-circuit
ipfs_1 | Swarm announcing /ip4/127.0.0.1/tcp/4001
ipfs_1 | Swarm announcing /ip4/172.18.0.2/tcp/4001
ipfs_1 | Swarm announcing /ip4/207.148.23.167/tcp/4001
ipfs_1 | API server listening on /ip4/0.0.0.0/tcp/5001
ipfs_1 | WebUI: http://0.0.0.0:5001/webui
ipfs_1 | Gateway (readonly) server listening on /ip4/0.0.0.0/tcp/8080
ipfs_1 | Daemon is ready
graph-node_1 | Aug 22 06:48:10.151 INFO Graph Node version: unknown (6ab7a3fd0 2020-08-21)
graph-node_1 | Aug 22 06:48:10.165 INFO Starting up
graph-node_1 | Aug 22 06:48:10.171 INFO Trying IPFS node at: http://ipfs:5001/
graph-node_1 | Aug 22 06:48:10.178 INFO Creating transport, capabilities: archive, trace, url: https://mainnet.infura.io/v3/runyourown, network: mainnet
graph-node_1 | Aug 22 06:48:10.189 INFO Successfully connected to IPFS node at: http://ipfs:5001/
graph-node_1 | Aug 22 06:48:10.196 INFO Connecting to Postgres, conn_pool_size: 10, url: postgresql://graph-node:HIDDEN_PASSWORD@postgres:5432/graph-node
graph-node_1 | Aug 22 06:48:10.235 INFO Connected to Postgres, url: postgresql://graph-node:HIDDEN_PASSWORD@postgres:5432/graph-node, pool_name: main, component: Store
graph-node_1 | Aug 22 06:48:10.244 INFO Connecting to Ethereum..., capabilities: archive, trace, network: mainnet
graph-node_1 | Aug 22 06:48:10.350 INFO Connected to Ethereum, capabilities: archive, trace, network_version: 1, network: mainnet
graph-node_1 | Aug 22 06:48:10.355 INFO Waiting for other graph-node instances to finish migrating, component: Store
graph-node_1 | Aug 22 06:48:10.357 INFO Running migrations, component: Store
graph-node_1 | Aug 22 06:48:10.736 INFO Migrations finished, component: Store
graph-node_1 | Aug 22 06:48:10.740 INFO Completed pending Postgres schema migrations, component: Store
graph-node_1 | Aug 22 06:48:10.745 INFO Creating LoadManager in disabled mode, component: LoadManager
graph-node_1 | Aug 22 06:48:10.748 INFO Starting block ingestors
graph-node_1 | Aug 22 06:48:10.750 INFO Starting block ingestor for network, network_name: mainnet
graph-node_1 | Aug 22 06:48:10.765 INFO Starting JSON-RPC admin server at: http://localhost:8020, component: JsonRpcServer
graph-node_1 | Aug 22 06:48:10.769 INFO Starting GraphQL HTTP server at: http://localhost:8000, component: GraphQLServer
graph-node_1 | Aug 22 06:48:10.771 INFO Starting index node server at: http://localhost:8030, component: IndexNodeServer
graph-node_1 | Aug 22 06:48:10.773 INFO Starting metrics server at: http://localhost:8040, component: MetricsServer
graph-node_1 | Aug 22 06:48:10.776 INFO Started all subgraphs, component: SubgraphRegistrar
graph-node_1 | Aug 22 06:48:10.778 INFO Starting GraphQL WebSocket server at: ws://localhost:8001, component: SubscriptionServer
graph-node_1 | Aug 22 06:48:10.954 INFO Downloading latest blocks from Ethereum. This may take a few minutes..., network_name: mainnet, component: BlockIngestor
graph-node_1 | Aug 22 06:49:26.366 INFO Syncing 4 blocks from Ethereum., code: BlockIngestionStatus, blocks_needed: 4, blocks_behind: 4, latest_block_head: 10708535, current_block_head: 10708531, network_name: mainnet, component: BlockIngestor
graph-node_1 | Aug 22 06:49:45.539 INFO Syncing 1 blocks from Ethereum., code: BlockIngestionStatus, blocks_needed: 1, blocks_behind: 1, latest_block_head: 10708536, current_block_head: 10708535, network_name: mainnet, component: BlockIngestor
...
Clone Uniswap v2 subgraph
If you do everything below but for uniswap v1 subgraph repo then that will work
~# git clone https://github.com/Uniswap/uniswap-v2-subgraph.git
Cloning into 'uniswap-v2-subgraph'...
remote: Enumerating objects: 135, done.
remote: Counting objects: 100% (135/135), done.
remote: Compressing objects: 100% (80/80), done.
remote: Total 1033 (delta 73), reused 86 (delta 39), pack-reused 898
Receiving objects: 100% (1033/1033), 534.19 KiB | 14.06 MiB/s, done.
Resolving deltas: 100% (552/552), done.
Yawn
~/uniswap-v2-subgraph# yarn
yarn install v1.22.4
[1/4] Resolving packages...
[2/4] Fetching packages...
info [email protected]: The platform "linux" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
[4/4] Building fresh packages...
Done in 18.81s.
Yarning
~/uniswap-v2-subgraph# yarn codegen
yarn run v1.22.4
$ graph codegen --output-dir src/types/
Skip migration: Bump mapping apiVersion from 0.0.1 to 0.0.2
Skip migration: Bump mapping apiVersion from 0.0.2 to 0.0.3
Skip migration: Bump mapping specVersion from 0.0.1 to 0.0.2
โ Apply migrations
โ Load subgraph from subgraph.yaml
Load contract ABI from abis/factory.json
Load contract ABI from abis/ERC20.json
Load contract ABI from abis/ERC20SymbolBytes.json
Load contract ABI from abis/ERC20NameBytes.json
โ Load contract ABIs
Generate types for contract ABI: Factory (abis/factory.json)
Write types to src/types/Factory/Factory.ts
Generate types for contract ABI: ERC20 (abis/ERC20.json)
Write types to src/types/Factory/ERC20.ts
Generate types for contract ABI: ERC20SymbolBytes (abis/ERC20SymbolBytes.json)
Write types to src/types/Factory/ERC20SymbolBytes.ts
Generate types for contract ABI: ERC20NameBytes (abis/ERC20NameBytes.json)
Write types to src/types/Factory/ERC20NameBytes.ts
โ Generate types for contract ABIs
Generate types for data source template Pair
Write types for templates to src/types/templates.ts
โ Generate types for data source templates
Load data source template ABI from abis/pair.json
Load data source template ABI from abis/factory.json
โ Load data source template ABIs
Generate types for data source template ABI: Pair > Pair (abis/pair.json)
Write types to src/types/templates/Pair/Pair.ts
Generate types for data source template ABI: Pair > Factory (abis/factory.json)
Write types to src/types/templates/Pair/Factory.ts
โ Generate types for data source template ABIs
โ Load GraphQL schema from schema.graphql
Write types to src/types/schema.ts
โ Generate types for GraphQL schema
Types generated successfully
Done in 3.12s.
"Yarn local"
Local even though you can query thegraph non-locally
This will fail if thegraph isn't running from above
~/uniswap-v2-subgraph# yarn create-local
yarn run v1.22.4
$ graph create davekaj/uniswap --node http://127.0.0.1:8020
Created subgraph: davekaj/uniswap
Done in 1.92s.
Magically integrate the uniswap v2 subgraph into the running thegraph node
~/uniswap-v2-subgraph# yarn deploy-local
yarn run v1.22.4
$ graph deploy davekaj/uniswap --debug --ipfs http://localhost:5001 --node http://127.0.0.1:8020
Skip migration: Bump mapping apiVersion from 0.0.1 to 0.0.2
Skip migration: Bump mapping apiVersion from 0.0.2 to 0.0.3
Skip migration: Bump mapping specVersion from 0.0.1 to 0.0.2
โ Apply migrations
โ Load subgraph from subgraph.yaml
Compile data source: Factory => build/Factory/Factory.wasm
Compile data source template: Pair => build/templates/Pair/Pair.wasm
โ Compile subgraph
Copy subgraph file build/schema.graphql
Write subgraph file build/Factory/abis/factory.json
Write subgraph file build/Factory/abis/ERC20.json
Write subgraph file build/Factory/abis/ERC20SymbolBytes.json
Write subgraph file build/Factory/abis/ERC20NameBytes.json
Write subgraph file build/Pair/abis/pair.json
Write subgraph file build/Pair/abis/factory.json
Write subgraph manifest build/subgraph.yaml
โ Write compiled subgraph to build/
Add file to IPFS build/schema.graphql
.. QmXs1LGtqmGNBpMsL4hhoi5sWR9xM3p2Y9ZRmDwum5AaHD
Add file to IPFS build/Factory/abis/factory.json
.. QmZ55G1yYFzde8Vcq4cpLfNgPSEibpLi9aYCqS1jEvCKQ9
Add file to IPFS build/Factory/abis/ERC20.json
.. QmXuTbDkNrN27VydxbS2huvKRk62PMgUTdPDWkxcr2w7j2
Add file to IPFS build/Factory/abis/ERC20SymbolBytes.json
.. QmbHnhUFZa6qqqRyubUYhXntox1TCBxqryaBM1iNGqVJzT
Add file to IPFS build/Factory/abis/ERC20NameBytes.json
.. QmQCP6Pdp1MqpwRv2qoPHuUTwZGy7Q3eDHg4w5kzwE9mBj
Add file to IPFS build/Factory/Factory.wasm
.. QmZLfiUaV9CR62UQRccEoJM6fJa5p219rvXiwi3FQVpnny
Add file to IPFS build/Pair/abis/pair.json
.. QmbPLMADBP8L6LBVP3ZBQ8RgG7ghamD8DvbdUxHAjZrLgm
Add file to IPFS build/Pair/abis/factory.json
.. QmZ55G1yYFzde8Vcq4cpLfNgPSEibpLi9aYCqS1jEvCKQ9
Add file to IPFS build/templates/Pair/Pair.wasm
.. QmdgGPjB2osMbrKoVb9PvTeM9zLoPkSsSoPAZGfLhxWLXU
โ Upload subgraph to IPFS
Build completed: Qmem2vQPxhZGYf32D76oFaXp36ck6cy3qzj86gDNvoW4Da
Deployed to http://127.0.0.1:8000/subgraphs/name/davekaj/uniswap/graphql
Subgraph endpoints:
Queries (HTTP): http://127.0.0.1:8000/subgraphs/name/davekaj/uniswap
Subscriptions (WS): http://127.0.0.1:8001/subgraphs/name/davekaj/uniswap
Done in 9.44s.
Query Time
http://OUTSIDEIP:8000/subgraphs/name/davekaj/uniswap
Now the Uniswap v2 subgraph graphql queries will execute (just like from thegraph) but the output is always empty JSON and thegraph's terminal log is quiet besides new blocks and this repeating warning:
graph-node_1 | Aug 22 07:57:28.967 WARN Trying again after eth_call RPC call failed (attempt #26) with result Err(Web3Error(Transport("Unexpected response status code: 403 Forbidden"))), block_hash: 0x359d1dc4f14f9a07cba3ae8416958978ce98f78ad7b8d505925dad9722081f04, block_number: 10008355, subgraph_id: Qmem2vQPxhZGYf32D76oFaXp36ck6cy3qzj86gDNvoW4Da, component: SubgraphInstanceManager