Based on the background of the team’s development of The Graph and its application of Subgraph, this paper introduces the construction of its environment: the offline developed machine is relatively complex, so the MAC machine is taken as an example to explain the step-by-step configuration; the online environment is relatively clean but lacks auxiliary software, so it needs to be deployed from scratch, so readers can read it as needed.

The Graph development environment is set up

Ganache deployment

In addition to the official documentation on local deployment, there is also this documentation on local deployment

NPM/Yarn installs truffle ganache-cli globally

$ npm install -g truffle ganache-cli
   or 
$ yarn global add truffle ganache-cli

Ganache – cli start

$ ganache-cli -h 0.0.0.0

Ganache CLI v6.12.2 (Ganache – core: 2.13.2) Available Accounts = 0 (0) x373548217c1c6d3f896833418ccdc14426be91cd ETH (100) (1) 0x65f77651165C132252ea43E34f3aE24048216ce8 (100 ETH) (2) 0x1861c71ABC4Ccd4990bb42638C4966e9012A8fc9 (100 ETH) (3) 0x919A60B34B05feCdB712301120677236B9a3FadE (100 ETH) (4) 0x7C9E7100d4EA8B25Af4c56aBcf1E2C854e7c363E (100 ETH) (5) 0xD5f03B34884F57bC9b1E4be4dA6c65c0b5ed8d0e (100 ETH) (6) 0x79919c9e8832317c0757734C8F01164bBba1B6E3 (100 ETH) (7) 0xCf135Fa7F9c77Ba5251B55E4A2D6F27f337f4A32 (100 ETH) (8) 0xfD17D90c6C85C91fd0B81d65964336BC924A0113 (100 ETH) (9) 0x7887465f89eD278960a55Bf6e391b61528747A60 (100 ETH) Private Keys = (0) 0xa9b479e9304251d7f2f4dfcbc143fd037cfdb02fc3bb70f6826297bc4206b945 (1) 0x0feef1514167b7c1b4cdc11e5d8eb407ab4d04661771f3efc9ccc185c0103ee0

Note: Startup with parameters can reproduce most of the historical environment such as: Ganach-cli-h 0.0.0.0-v/db-b 6-a 8-e 1000-d expect chair toe trade spider wedding say item scare fog shrimp Garlic opens the existence library, set the automatic mining time 6, set 8 1000gas account, import the existing private key, (-D, can be outside, can also be used -M generation)

Pull Graph – Node (complex environment history at this level)

Download https://download.docker.com/m… , install into the APP, run and enter the password, the command line is available.

Everything looks fine, but subsequent installments can cause various problems, depending on the hardware and software environment on your machine, but both need to be properly handled.

$ brew install jq
$ docker -v

Doing the brew install install updates, filling holes see the brew upgrade installation error to solve the brew upgrade legacy MAC update component. Docker version 20.10.5, build 55c4c88 is OK. Graph – node node

$ git clone https://github.com/graphprotocol/graph-node/

The common human inaccessible areas such as git resource agent and mirror pit Sometimes repeatedly try it in the past, the past work is appreciated and backup some resources that have the force majeure can take these files in the future copy/paste (or directly use your colleague’s clean environment for local file, go back to solve the problem of your environment)

Configure to launch The Graph

$ cd graph-node/docker
$ ./setup.sh #write the host IP address into docker-compose.yml.
$ docker-compose up #Start a local Graph Node that will connect to Ganache on your host

Graph – node_1 | Jun 22 11:13:56. 395 INFO Starting JSON xml-rpc admin server at: http://localhost:8020, component: JsonRpcServer graph – node_1 | Jun 22 11:13:56. 395 INFO Started all subgraphs, component: SubgraphRegistrar graph – node_1 | Jun 22 11:13:56. 397 INFO Starting GraphQL HTTP server at: http://localhost:8000, component: GraphQLServer graph – node_1 | Jun 22 11:13:56. 397 INFO Starting index node server at: http://localhost:8030, component: IndexNodeServer graph – node_1 | Jun 22 11:13:56. 399 INFO Starting GraphQL WebSocket server at: Ws: / / localhost: 8001, component: SubscriptionServer graph – node_1 | Jun 22 11:13:56. 399 INFO Starting metrics server at: http://localhost:8040, component: MetricsServer

Start the docker – compose up

The error was caused by accessing the host IP

Close the node docker-compose down-v;

docker-compose down -v;

if [ -d”data” ] thenecho”Found old data for the graph node – deleting it”; # we need to sudo this to remove system locked filessudorm-rf data/;

fi

Client Graphprotocol/Graph – CLI installation

$ npm install -g @graphprotocol/graph-cli
$ graph init --from-example moluoping/mark-cion 
 #graph init --from-example <GITHUB_USERNAME>/<SUBGRAPH_NAME> [<DIRECTORY>]

Yarn produced by the function of the lock file lock depends on package version, also locked source url can’t solve with mirror: backup the lock, use NPM down all packages (taobao mirror is not complete, using official http://registry.npmjs.org/) version (depend on) resource agent and mirror pit

Above are the examples of producing contracts and subgraphs

You can also generate a Subgraph project directly from the Container Contract Wizard:

$ graph init --from-contract 0x1e1215caD01aD7192832e0DACfA930Caf0132b43  --network mainnet --abi markdemo4.json moluoping/markdemo4

Compile & deploy contracts

Compiling vs. new compilation

$ truffle compile

(truffle compile compile – all new https://www.trufflesuite.com/…). Compiling your contracts… Attempt #1. Compiler. Attempt #1. Compiling ./contracts/Gravity.sol Compiling ./contracts/Migrations.sol Artifacts written to /Users/gaoxiaoqing/Documents/swork/feature/markggg/build/contracts Compiled successfully using: solc: 0.4.25 + commit. 59 dbf8f1. Emscripten. Clang

Release and redeploy

$ truffle migrate

(truffle migrate – reset to redeploy https://www.trufflesuite.com/… Network name: ‘development’ Network id: 1624441310514 Block gas limit: 6721975 (0x6691b7) 1_initial_migration.js Deploying ‘Migrations’ transaction hash: 0x92950fa746934bed8f1af3e1ea915c76669858c7e9b396c1dfa74276cfdb2745 Blocks: 0 Seconds: 0 contract address: 0x0A994866b43562c083C81E1B4AD6145214f56c56 block number: 1 block timestamp: 1624441330

The monitor contract is configured by the contract ID

$ sed -i -e 's/0x2E645469f354BB4F5c8a05B3b30A929361cf77eC/0x71e11bC372507d508E05f65c096d32F1eF62Cdf7/g'     subgraph.yaml
$ sed -i -e 's/0x2E645469f354BB4F5c8a05B3b30A929361cf77eC/0x0A994866b43562c083C81E1B4AD6145214f56c56/g'     subgraph.yaml

Make a silly mistake here, and the second contract is really valid, But the next instruction to achieve effect sed – I – e ‘s / 0 x2e645469f354bb4f5c8a05b3b30a929361cf77ec / 0 x0a994866b43562c083c81e1b4ad6145214f56c56 / g’ Subgraph. Yaml should be changed to sed – I – e ‘s / 0 x71e11bc372507d508e05f65c096d32f1ef62cdf7/0 x0a994866b43562c083c81e1b4ad6145214f56c56 / g’ subgraph.yaml

Because the first command has replaced the text

Compile, create Subgarph, and publish The Graph App

Download the dependency package and compile it

$ yarn && yarn codegen

$NPM install $yarn codegen Yaml Load contract ABI from abis/Gravity. JSON Load contract ABI from abis/Gravity Generate types for contract ABI: Gravity (abis/Gravity. Json) Write types to generated/Gravity Gravity. Ts ✔ the Generate types for contract abis ✔ the Generate Types for data source templates Load data source template ABIs banner banner banner banner banner Generate types for data source template ABIs banner banner banner banner banner Generate types for GraphQL schema types from schema.graphql Write types to generated/schema.ts bookmarks generated successfully

Create subgarph and publish it

$ yarn create-local
$ yarn deploy-local

$yarn create-local graph creates a oping/markg –node http://127.0.0.1:8020 Created subgraph: Compiled subgraph to build/ Add file to IPFS build/schema.graphql.. QmbSFRGGvHM7Cn8YSjDL41diDMxN4LQUDEMqaa5VVc5sC4 Add file to IPFS build/Gravity/abis/Gravity.json .. QmajZTadknSpgsCWRz9fG6bXFHdpVXPMWpx9yMipz3VtMQ Add file to IPFS build/Gravity/Gravity.wasm .. QmbK8bwncci52cstF3P8Q8i4oGjrMt1pUqdv5Uf1VXqXdb ✔ Upload subgraph to IPFS Build completed: Qmd77mi1ATxscqsBvLANrw9gP1dJNsQMTexvErw5XVyFLc ✖ Failed to deploy to Graph node http://127.0.0.1:8020/: Ethereum network not supported by registrar: mainnet error Command failed with exit code 1. Find the docker/docker – compose. Yml, e ethereum: ‘mainnet: http://host.docker.internal:8545’ changed to local: ethereum: ✔ ‘mainnet: http://192.168.0.136:8545’ Upload subgraph to IPFS Build completed: QmYNgbF7YfDs6Y8YV7aqYGS7cVx5vpt1uNhk3y7wmkAUgm Deployed to http://127.0.0.1:8000/subgrap… Subgraph endpoints: Queries (HTTP) : http://127.0.0.1:8000/subgrap… Subscriptions (WS) : http://127.0.0.1:8001/subgrap… ✨ Done in 21.16 s.

Port 8001 is in conflict with the VRay HTTP proxy port, change the VRay HTTP proxy port to 8701, and resolve the git clone and yarn download proxy issues

Proxy with mirror pit points

Note in particular that port 8001 conflicts with the VRay HTTP proxy port

Modify the VRay HTTP proxy port to 8701, and remove the git clone and yarn download proxy issues

Pay special attention to agents, agents, agents

We are not proxying, we are on the way to mirroring, and sometimes git and yarn still have synchronization errors. This can be repeated as follows

Git config --global http.proxy socks5://127.0.0.1:1080 git config --global https.proxy socks5://127.0.0.1:1080 git config --global https.proxy socks5://127.0.0.1:1080 git config Config --global https.proxy http://127.0.0.1:1080 git config --global https.proxy localgit config --global --unset http.proxy git config --global --unset https.proxy

Switch/switch agent

NPM query current mirror NPM get registry Settings for taobao mirror NPM config set registry Settings https://registry.npm.taobao.org/ is the official image NPM config set Registry https://registry.npmjs.org/ YARN query current mirror YARN config get registry Settings for taobao mirror YARN config set registry https://registry.npm.taobao.org/ is set to the official image yarn config set registry at https://registry.yarnpkg.com

Ali and the official keep switching

Brew Upgrade Installation Error Replace Homebrew-bottles

$brew upgrade or $any command that needs to be updated

= = > Installing libtool dependency: m4 = = > Pouring m4-1.4.18. Mojave. Bottle. 1. Tar. Gz tar: Error opening archive: Failed to open ‘/Users/gaoxiaoqing/Library/Caches/Homebrew/downloads/f25291efa07f91502eda2b4c0bd6fa41fae3c19661fa239d3855027f9c0a36d1– M4-1.4.18. Mojave. Bottle. 1. The tar. Gz ‘Error: a Failure while executing. tar –extract –no-same-owner –file /Users/gaoxiaoqing/Library/Caches/Homebrew/downloads/f25291efa07f91502eda2b4c0bd6fa41fae3c19661fa239d3855027f9c0a36d1–m 4-1.4.18. Mojave. Bottle. 1. The tar. Gz – directory/private/TMP/d20210628-40770 – hpzxk9 exited with 1. Here ‘s the output: the tar: Error opening archive: Failed to open ‘/Users/gaoxiaoqing/Library/Caches/Homebrew/downloads/f25291efa07f91502eda2b4c0bd6fa41fae3c19661fa239d3855027f9c0a36d1– M4-1.4.18. Mojave. Bottle. 1. The tar. Gz ‘

Solution a: Replace the file Find/Users/gaoxiaoqing/Library/Caches/Homebrew/downloads/found 66 ff350c21fce7c264e33e3cff6f4995978ac401d5e5047c0ee8dd17e3493a 53 – m4-1.4.18. Mojave. Bottle. 1. Tar. Gz, had its name changed. OK, I guess there are two or two versions of this, the last one is not generated cache, but after busy still can’t sleep, there is a second solution.

Scheme B: Replace Homebrew-bottles

echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
 
source ~/.bash_profile

BREW consists of four pieces

Homebrew Source code repository
homebrew-core Homebrew core source
homebrew-cask Provide MacOS applications and large binaries installation
homebrew-bottles Precompiled binary software packages

You can also change the image if you use it


$ git -C "$(brew --repo)" remote set-url origin https://mirrors.ustc.edu.cn/brew.git
$ git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
$ git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git

Configuration file scripts automatically replace pits

Inaccurate data source acquisition

Graph – node_1 | Jun 24 01:34:13. 558 WARN Trying again after net_version RPC call failed (attempt # 18) with the result Err(Transport error: Error(Connect, Os { code: 111, kind: ConnectionRefused, message: “Connection refused” })), provider: Mainnet xml-rpc – 0 graph – node_1 | Jun 24 01:34:14. 517 ERRO Connection to the provider failed. Not using this provider, the error: deadline has elapsed, provider: mainnet-rpc-0

Failed to deploy to Graph node http://127.0.0.1:8020/: Ethereum network not supported by registrar: mainnet. DOCKER-COMPOSE.YML-E: docker/docker-compose. YML-E: docker/docker-compose. YML-E: docker/docker-compose. ‘mainnet: http://host.docker.internal:8545’ is modified to the local: ethereum: ‘mainnet: http://192.168.0.136:8545’

Caused by changes to multiple replacement sources of data

Contract Debugging Tool

  • Truffle Console: A basic interactive console connecting to any Ethereum client
  • Truffle Develop: An interactive console that also spawns a development blockchain

    https://www.trufflesuite.com/…

The Graph Online Server & Certos8 installation

Install online server docker & start

# sudo yum install -y yum-utils device-mapper-persistent-data lvm2 # sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo # sudo yum install docker-ce docker-ce-cli containerd.io  # yum list docker-ce --showduplicates | sort -r

Docker-ce.x86_64 3:20.10.7-3. El8 @docker-ce-stable docker-ce.x86_64 3:20.10.7-3. El8 @docker-ce-stable docker-ce.x86_64 El8 Docker-Ce-Stable El8 Docker-Ce-Stable El8 Docker-Ce-Stable El8 Docker-Ce-Stable El8 Docker-Ce-Stable El8 Docker-Ce-Stable El8 Docker-Ce-Stable

# sudo yum install docker-ce-20.10.7-3. El8 docker-ce-20.10.7-3. El8 containerd. IO # sudo systemctl start docker

Pull down the node graph-node & configure to start

# git clone https://github.com/graphprotocol/graph-node/

Install the docker – compose

# yum install python3-pip # yum install python3-pip

Yum install python-pip (certos7)

# pip3 install --upgrade pip
# pip install docker-compose

Pip3 install –upgrade PIP (certos7) If the installation using PIP install docker-compose fails, Try # PIP –default-timeout=200 install -u docker-compose using the following command

Install the install ‘jq’

# yum install jq

Run environment Settings, focusing on IP address copy

# cd graph-node/docker
./setup.sh 

write the host IP address into docker-compose.yml. If the IP is not your host IP, change it manually

Docker: read TCP 192.168.7.235:36512->54.230.212.9:443: read: connection reset by peer

Use the next section AliCloud Image to accelerate the solution

Ali cloud mirror acceleration

https://help.aliyun.com/docum…

To use Docker, you need to first download an official image, such as MySQL and WordPress. However, due to network reasons, it may take a long time to download a Docker official image, or even the download fails. To this end, ACR, AliCloud container mirroring service, provides an official mirroring site to accelerate the download of official images. Mirror Accelerator is a service for individual developers. It is limited to individual development scenarios and does not allow re-packaging or commercial use.

# sudo mkdir -p /etc/docker
# sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://de43k63h.mirror.aliyuncs.com"]
}
EOF
# sudo systemctl daemon-reload
# sudo systemctl restart docker

https://de43k63h.mirror.aliyu… Replace it with your mirror: For the address of the accelerator, after you log in to the container mirror service console, select the mirror tool > mirror accelerator in the left navigation bar. The mirror accelerator page will display the address assigned to you independently.

Continue with the./setup.sh setting to track the IP address

Starting graph-node … doneHost IP: 172.18.0.1

# ifconfig

br-c3a270be10f6: Flags =4099

MTU 1500 inet 172.18.0.1 netmask 255.255.0.0 BROADCAST 172.18.255.255 inet6 fe80::42:b1ff:fea4:30eb prefixlen 64 scopeid 0x20 ether 02:42:b1:a4:30:eb txqueuelen 0 (Ethernet) RX packets 0 Bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 Tx Packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 docker0: Flags =4099

MTU 1500 INET 172.17.0.1 Netmask 255.255.0.0 Broadcast 172.17.255.255 Ether 02:42:76:73:7f:6c TxQueuelen 0 (Ethernet) Rx Packets 0 bytes 0 (0.0 B) Rx errors 0 dropped 0 overruns 0 frame 0 Tx Packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 Collisions 0 eth0: Flags = 4163 < UP, BROADCAST, RUNNING, MULTICAST > mtu 1500 inet 172.31. XXX. XXX netmask 255.255.240.0 BROADCAST 172.31.191.255 inet6 fe80::216:3eff:fe02:a9a7 prefixlen 64 scopeid 0x20 ether 00:16:3e:02:a9:a7 txqueuelen 1000 (Ethernet)
,>
,broadcast,multicast>

Here we manually modified 172.18.0.1 to the remote Ethereum container IP (docker/docker-compose.yml).

Start the Graph

Launch # docker-compose up

Stop # docker-compose down-v

Ok, you can use the http://47.100.XXX.XXX:8000 http://47.100.XXX.XXX:8001 http://47.100.XXX.XXX:8020 http://47.100.XXX.XXX:8040

Enter the Docker log

The remote connection is checked again in the log

# docker ps

CONTAINER ID IMAGE COMMAND PORTS NAMESf8dea825ae05 graphprotocol/graph-node “/bin/sh -c start” 8040->8040/tcp Docker_graph-node_1 890420a4b747 ipfs/go-ipfs:v0.4.23 “/sbin/tini — /usr/…” 5001->5001/ TCP docker_ipfs_1 1e477194e786 postgres “docker-entryPoint.s…” 5432->5432/tcp

# docker logs --tail 10 f8dea825ae05
# docker logs --follow f8dea825ae05

Author: Mark


We welcome like-minded partners in the blockchain industry to join WeChat and BlockGeek blockchain technology exchange group to jointly promote the popularization and development of blockchain technology