Cruzsanta
3 min readOct 31, 2020

Subgraph in The Graph for KEEP NETWORK

Use docs https://thegraph.com/docs

The first step is to access Graph Explorer https://thegraph.com/explorer/. If you still don’t have an account you can signup with Github. After that, you go to your Dashboard and you will see a nice page with four clear steps: a. Create; b. Install; c. Init; and d. Deploy.

  1. Register an account on github.
  2. Create a repository.

a. Create undeployed subgraph

Next, you need to perform 3 parameters: Installation, initialization, and deployment.

npm install -g @graphprotocol/graph-cliyarn global add @graphprotocol/graph-cli

We will do this using the terminal on MAC OS

GUIDE to install yarn, nvm (node) on macOS
1. Install Homebrew

/bin/bash -c “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
2. Prepare before setup (cleanup)
brew uninstall — force yarn node npm # remove previously installed node, npm, yarn
brew cleanup # clean all broken symlinks and “waste” (not really required as of homebrew 2019)
brew update # always good to have the latest
3.Install yarn via homebrew
brew install yarn
4.Install nvm
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.35.3/install.sh | bash
Help error setup nvm for macOSX:
create .bash_profile file
cd ~
touch .bash_profile
#open the file you just created
open .bash_profile
#paste the following code inside the file
export NVM_DIR=~/.nvm
source ~/.nvm/nvm.sh
#run the source command after saving
source .bash_profile
#then enter the command
nvm — version
5.Install node latest lts
nvm install lts/erbium
6.Set nvm to use latest LTS as default for new bash sessions
echo “lts/erbium” > .nvmrc # default to the latest LTS version
nvm alias default lts/erbium

RESTART all terminals => you’re done ;-)

The terminal log:

yarn global add @graphprotocol/graph-cliyarn global v1.22.10
[1/4] 🔍 Resolving packages…
warning @graphprotocol/graph-cli > request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
warning @graphprotocol/graph-cli > request > har-validator@5.1.5: this library is no longer supported
warning @graphprotocol/graph-cli > ipfs-http-client > multicodec@0.5.7: stable api reached
warning @graphprotocol/graph-cli > ipfs-http-client > ipld-dag-pb > multicodec@0.5.7: stable api reached
warning @graphprotocol/graph-cli > ipfs-http-client > peer-info@0.15.1: No longer supported for js-libp2p0.28.0 or later
warning @graphprotocol/graph-cli > ipfs-http-client > promisify-es6@1.0.3: Unmaintained
warning @graphprotocol/graph-cli > ipfs-http-client > peer-id > libp2p-crypto > libp2p-crypto-secp256k1@0.3.1: Included in libp2p-crypto, use it instead. https://github.com/libp2p/js-libp2p-crypto
[2/4] 🚚 Fetching packages…
[3/4] 🔗 Linking dependencies…
[4/4] 🔨 Building fresh packages…
success Installed “@graphprotocol/graph-cli@0.19.0” with binaries:
— graph
✨ Done in 87.35s.
graph init — from-example honeynastu/keepsubgraphs keep-subgraph-master/
✔️ Subgraph name · honeynastu/keep
✔️ Directory to create the subgraph in · keepsubgraphs
✔️ Ethereum network · mainnet
✔️ Contract address · 0x10B66Bd1e3b5a936B7f8Dbc5976004311037Cdf0
✔️ Fetching ABI from Etherscan
✔️ Contract Name · TBTCDepositToken
— — —
Generate subgraph from ABI
Write subgraph to directory
✔️ Create subgraph scaffold
✔️ Initialize subgraph repository
✔️ Install dependencies with yarn
✔️ Generate ABI and schema types with yarn codegen
Subgraph honeynastu/keep created in keepsubgraphs

Next steps:

1. Run graph auth https://api.thegraph.com/deploy/ <access-token>
to authenticate with the hosted service. You can get the access token from
https://thegraph.com/explorer/dashboard/.

2. Type cd keepsubgraphs to enter the subgraph.

3. Run yarn deploy to deploy the subgraph to
https://thegraph.com/explorer/subgraph/honeynastu/keep.

graph auth https://api.thegraph.com/deploy/ 1149d7fc653847f3b3f1a61459e92aef

Access token set for https://api.thegraph.com/deploy/

yarn deploy
yarn run v1.22.10
graph deploy \
— debug \
— node https://api.thegraph.com/deploy/ \
— ipfs https://api.thegraph.com/ipfs/ \
honeynastu/keep
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 apiVersion from 0.0.3 to 0.0.4
Skip migration: Bump mapping specVersion from 0.0.1 to 0.0.2
✔️ Apply migrations
✔️ Load subgraph from subgraph.yaml
Compile data source: TBTCDepositToken => build/TBTCDepositToken/TBTCDepositToken.wasm
✔️ Compile subgraph
Copy schema file build/schema.graphql
Write subgraph file build/TBTCDepositToken/abis/TBTCDepositToken.json
Write subgraph manifest build/subgraph.yaml
✔️ Write compiled subgraph to build/
Add file to IPFS build/schema.graphql
.. QmVuutLtham2T58RkxeaooeF1TFmBJcbHrbNh26Ga6cUnu
Add file to IPFS build/TBTCDepositToken/abis/TBTCDepositToken.json
.. QmQdQSxPh44N5wbbMwKpGD7CuAiH18ykgRxoLvm1fA5tS1
Add file to IPFS build/TBTCDepositToken/TBTCDepositToken.wasm
.. QmRCQPbXDXp44CbAU4exMmhXkLTVyj4YEzvUvVqY9vtr5i
✔️ Upload subgraph to IPFS
Build completed: QmUdQoLCcZp2kvH76Ej1EcU1gCdYKD8SLMDMo69CcHh2Zi
Deployed to https://thegraph.com/explorer/subgraph/honeynastu/keep
Subgraph endpoints:
Queries (HTTP): https://api.thegraph.com/subgraphs/name/honeynastu/keep
Subscriptions (WS): wss://api.thegraph.com/subgraphs/name/honeynastu/keep