$ npm install -g @graphprotocol/graph-cli
npm i
Run a Hardhat node:
npx hardhat node
NOTE: Note: Use the first account to avoid errors.
Deploy the Swaplace contract
npx hardhat run --network localhost scripts/deploy.ts
cd /swaplace-subgraph/
npm i
Go to the graph-node directory
cd swaplace-subgraph/graph-node
rm -rf graph-node/data/
docker-compose up
You should see the log looking like this for the docker:
*graph-node-graph-node-1 |* Oct 15 04:44:57.420 INFO Downloading latest blocks from Ethereum, this may take a few minutes..., provider: localhost-rpc-0, component: EthereumPollingBlockIngestor
And looking something like this for hardhat:
eth_blockNumber (2)
eth_getBlockByNumber (19)
eth_blockNumber (2)
eth_getBlockByNumber (14)
cd swaplace-subgraph
graph create --node http://localhost:8020/ subgraph/swaplace
graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 subgraph/swaplace
Run the test scripts on the local network to generate events to check on The Graph Explorer with queries. Example of query:
query MyQuery {
swapCreateds(first: 2) { creator id Swaplace_id blockNumber } }
- Cancel and clean the docker.
In the
graph-node
folder running the docker, presscrtl + c
and typedocker-compose down
, then delete the data folderrm -rf /data
- Update the smart contract and compile it
- Update the files
swaplace-subgraph/networks.json
and theswaplace-subgraph/subgraph.yaml
with the new address - Copy and paste the new ABI on
swaplace-subgraph/abis/Swaplace.json
- Update the file
swaplace-subgraph/schema.graphql
with the new entities - Update the file
swaplace-subgraph/subgraph.ymal
with the new event handlers - Update the file
swaplace-subgraph/src/swaplace.ts
with the new functions and imports - Run the commands
graph codegen
andgraph build --network localhost
in theswaplace-subgraph
folder. - Deploy the new version of the subgraph
graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 subgraph/swaplace
- Access the studio https://thegraph.com/studio/, connect your wallet and create a subgraph
- Give a name and select a network
- Run the command line:
graph init --studio <your subgraph name>
- Choose the protocol you want to deploy the subgraph
- Create the slug which will be the unique identifier your subgraph will be identified by
- Create the name of the directory that will have the subgraph files
- Choose the network you want to deploy the subgraph
- Fill the address field with the smart contract deployed on the network
- Set the path to the ABI file
- Fill the block in which the contract was deployed to
- Give the name of the contract
- Press "Y" to index events as entities
- Press "n" if you don't want to add another contract.
- Run the command
graph auth --studio <your subgraph deploy key>
- Go to the subgraph's directory
cd swaplace-subgraph
- Run the commands
graph codegen && graph build
to generate the necessary files - Run the command
graph deploy --studio swaplace-subgraph
to deploy the subgraph
Use The Graph Studio to play around with the queries. You can use the query mentioned earlier to start.