The graph application development Mac10 / certos 8 environment configuration

Time:2021-7-28

This paper introduces the construction of the environment based on the scene of the team developing the graph application Subgraph: the offline development machines are complex. Take the MAC machine as an example to explain the configuration step by step. The online environment is relatively clean, but there is a lack of auxiliary software. It needs to be deployed from scratch. Readers can read it as needed.

Construction of the graph development environment

Ganache deployment

exceptLocal deployment officialDocumentation, and this introductionLocal deploymentDocument for

NPM / Yan global install truss Ganache cli

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

Ganache cli startup

$ ganache-cli -h 0.0.0.0

Ganache CLI v6.12.2 (ganache-core: 2.13.2)
Available Accounts
=
(0) 0x373548217c1C6d3F896833418cCDc14426BE91cd (100 ETH)
(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
For example: Ganache cli – H 0.0.0.0 – V / DB – B 6 – a 8 – e 1000 – d expect chair to trade spider wedding say item scale fog shrimp Gallic
Open the presence library, set the automatic mining time 6, set 8 1000gas accounts, and import the existing private key (- D, can be external or – M)

Pull graph node (complex environment process at this level)

downloadhttps://download.docker.com/m…, put the installation into the app, run and enter the password, and the command line is available.

Everything looks very normal, but various problems may occur in subsequent installation. It varies depending on your local software and hardware environment, but you need to be calm about it.

$ brew install jq
$ docker -v

Brew install installation and update started badly. For pit filling, see brew upgrade installation and error reporting to solve the remaining problems of brew upgrade MAC update components.
Docker version 20.10.5, build 55c4c88 OK.
Pull graph node

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

The common resource pits in areas inaccessible to human resources, such as git, can be seen in the agent and mirror pits. Sometimes it’s time to try again and again. In the past, cherish the labor achievements and back up some resources. In case of force majeure in the future, you can copy / paste these files (or directly use your colleagues’ clean environment to obtain local files and solve your environmental problems later)

Configure to start 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-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

The graph application development Mac10 / certos 8 environment configuration

Start docker compose up

This error is caused by accessing the host IP address

Close the docker compose down – V node;

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>]

The generated yarn function lock file locks the version of the dependent package and the source URL. It cannot be mirrored
Solution: back up lock, use NPM to pull down all packages (Taobao image is incomplete, use officialhttp://registry.npmjs.org/
(compare version dependency) see proxy and mirror pits for resource pits

The above is through the example production contract and subgraph

You can also generate a subgraph project directly from the contract wizard in the container:

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

Compile & deploy contract

Compilation and new compilation

$ truffle compile

(truss compile — all new compilation)
https://www.trufflesuite.com/…)Compiling your contracts…
✔ Fetching solc version list from solc-bin. Attempt #1
✔ Downloading 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.59dbf8f1.Emscripten.clang

Publish and redeploy

$ truffle migrate

(truss migrate — reset) redeployhttps://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

Listen to the contract. Configure through the contract ID

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

If you make a low-level mistake here, the second contract is really effective, but the second instruction is to achieve the effect
sed -i -e ‘s/0x2E645469f354BB4F5c8a05B3b30A929361cf77eC/0x0A994866b43562c083C81E1B4AD6145214f56c56/g’ subgraph.yaml
Should read
sed -i -e ‘s/0x71e11bC372507d508E05f65c096d32F1eF62Cdf7/0x0A994866b43562c083C81E1B4AD6145214f56c56/g’ subgraph.yaml

Because the first command has replaced the text

Compile and create subgraph and publish the graph app

Download dependent packages and compile

$ yarn && yarn codegen

Change to $NPM install
$yarn codegen
The scheme temporarily obtains the dependence to complete the follow-up work, and then solves the environmental problems after OK. See the agent and image pit
✔ Load subgraph from subgraph.yaml
Load contract ABI from abis/Gravity.json
✔ Load contract ABIs
Generate types for contract ABI: Gravity (abis/Gravity.json)
Write types to generated/Gravity/Gravity.ts
✔ Generate types for contract ABIs
✔ Generate types for data source templates
✔ Load data source template ABIs
✔ Generate types for data source template ABIs
✔ Load GraphQL schema from schema.graphql
Write types to generated/schema.ts
✔ Generate types for GraphQL schema
Types generated successfully

Create a subgraph and publish it

$ yarn create-local
$ yarn deploy-local

$ yarn create-local
graph create moluoping/markg –node http://127.0.0.1:8020
Created subgraph: moluoping/markg
$ yarn deploy-local
✔ Write 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 Ethereum of docker / docker-compose.yml-e: ‘mainnet:http://host.docker.internal:8545
Modify 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.16s.

Port 8001 conflicts with the Vray HTTP proxy port. Modify the Vray HTTP proxy port to 8701. By the way, solve the proxy problem downloaded by git clone and yarn

Proxy and mirror pits

Pay special attention to the conflict between port 8001 and Vray HTTP proxy port

Modify the Vray HTTP proxy port to 8701, and solve the proxy problem downloaded by git clone and yarn

Pay special attention to agent, agent, agent

When we are not in the proxy, we are on the way to the image. Sometimes GIT and yarn still report synchronization errors. At this time, we can repeat the following operations

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 http://127.0.0.1:1080 
git config --global https.proxy https://127.0.0.1:1080

git config --global --unset http.proxy 
git config --global --unset https.proxy

Switch / switch agent

NPM
Query current image
npm get registry
Set as Taobao image
npm config set registry https://registry.npm.taobao.org/
Set as official image
npm config set registry https://registry.npmjs.org/

YARN
Query current image
yarn config get registry
Set as Taobao image
yarn config set registry https://registry.npm.taobao.org/
Set as official image
yarn config set registry https://registry.yarnpkg.com

Ali and the official kept switching

Brew upgrade installation error problem solving replace homebrew bottles

$ brew upgrade
 perhaps
$any commands that need to be updated
So it must be solved

==>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.tar.gz’
Error: Failure while executing; tar --extract --no-same-owner --file /Users/gaoxiaoqing/Library/Caches/Homebrew/downloads/f25291efa07f91502eda2b4c0bd6fa41fae3c19661fa239d3855027f9c0a36d1--m4-1.4.18.mojave.bottle.1.tar.gz --directory /private/tmp/d20210628-40770-hpzxk9 exited with 1. Here’s the output:
tar: Error opening archive: Failed to open ‘/Users/gaoxiaoqing/Library/Caches/Homebrew/downloads/f25291efa07f91502eda2b4c0bd6fa41fae3c19661fa239d3855027f9c0a36d1–m4-1.4.18.mojave.bottle.1.tar.gz’

Scheme 1: replace files
Find / users / gaoxiaoqing / library / caches / homebrew / downloads / 66ff350c21fce7c264e33e3cf6f4995978ac401d5e5047c0ee8dd17e3493a53–m4-1.4.18.mojave.bottle.1.tar.gz and change the name. OK, I guess there are two or two versions of this. The later one will not be generated, but I still can’t sleep after I’m busy. There is the second solution.

Scheme 2: replace homebrew pots

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

Brew includes four pieces

Homebrew Source code warehouse
homebrew-core Homebrew core source
homebrew-cask Provides installation of MacOS applications and large binary files
homebrew-bottles Precompiled binary package

If used, you can also change the image


$ 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

Profile script auto replace

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 result Err(Transport error: Error(Connect, Os { code: 111, kind: ConnectionRefused, message: “Connection refused” })), provider: mainnet-rpc-0
graph-node_1 | Jun 24 01:34:14.517 ERRO Connection to provider failed. Not using this provider, error: deadline has elapsed, provider: mainnet-rpc-0

This error will cause subsequent (associated application) error reports:
Failed to deploy to Graph node http://127.0.0.1:8020/: Ethereum network not supported by registrar: mainnet.
Solution: connectionrefused usually means that the other server cannot reach
Find Ethereum of docker / docker-compose.yml-e: ‘mainnet:http://host.docker.internal:8545
Modify to local: Ethereum: ‘mainnet:http://192.168.0.136:8545

Caused by multiple data replacement and source change

Contract commissioning tools

  • 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 & certos 8 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 3:20.10.6-3.el8 docker-ce-stable
docker-ce.x86_64 3:20.10.5-3.el8 docker-ce-stable

# sudo yum install docker-ce-20.10.7-3.el8 docker-ce-cli-20.10.7-3.el8 containerd.io
# sudo systemctl start docker

Pull down the node graph node & configure startup

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

Install docker compose

# yum -y install epel-release
# yum install python3-pip )

yum install python-pip(certos7)

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

pip3 install –upgrade pip (certos7)
If PIP install docker compose installation fails, try #pip — default timeout = 200 install – U docker compose with the following command

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, modify it manually

docker: read tcp 192.168.7.235:36512->54.230.212.9:443: read: connection reset by peer.

Use the Alibaba cloud image acceleration solution in the next section

Alibaba cloud image acceleration

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

When using docker, you need to first download an official image, such asmysqlwordpress。 However, due to network reasons, downloading an official docker image may take a long time, or even fail to download. To this end, Alibaba cloud container mirroring service ACR provides an official mirroring site to speed up the download of official images. Image accelerator is a service for individual developers. It only supports individual development scenarios and is not allowed to be re encapsulated or used for commercial purposes.

# 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 with your image: about the address of the accelerator, you can log inContainer mirroring service consoleWhen finished, select on the left navigation barMirror Tools > mirror accelerator, inMirror acceleratorThe page displays the accelerator address assigned to you independently.

Continue. / setup.sh setup to track IP addresses

Starting graph-node … doneHost IP: 172.18.0.1

# ifconfig

br-c3a270be10f6: flags=4099<UP,BROADCAST,MULTICAST> 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<link>
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<UP,BROADCAST,MULTICAST> 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<link>
ether 00:16:3e:02:a9:a7 txqueuelen 1000 (Ethernet)

Here we modify it manually172.18.0.1To remoteEthereum container IP(docker/docker-compose.yml)

Start the graph

start-up
# docker-compose up

stop it
# docker-compose down -v

OK, you can use it
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 docker log

Remote connection enters log view again

# 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


Small partners with similar interests in the blockchain industry are welcome to add Xiaoji wechat and join blockgeek blockchain technology exchange group to jointly promote the popularization and development of blockchain technology~

The graph application development Mac10 / certos 8 environment configuration

Recommended Today

Implementation example of go operation etcd

etcdIt is an open-source, distributed key value pair data storage system, which provides shared configuration, service registration and discovery. This paper mainly introduces the installation and use of etcd. Etcdetcd introduction etcdIt is an open source and highly available distributed key value storage system developed with go language, which can be used to configure sharing […]