$ npm install -g @graphprotocol/graph-clinpm iRun a Hardhat node:
npx hardhat nodeNOTE: Note: Use the first account to avoid errors.
Deploy the Swaplace contract
npx hardhat run --network localhost scripts/deploy.tscd /swaplace-subgraph/
npm iGo to the graph-node directory
cd swaplace-subgraph/graph-noderm -rf graph-node/data/docker-compose upYou 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-nodefolder running the docker, presscrtl + cand typedocker-compose down, then delete the data folderrm -rf /data - Update the smart contract and compile it
- Update the files
swaplace-subgraph/networks.jsonand theswaplace-subgraph/subgraph.yamlwith the new address - Copy and paste the new ABI on
swaplace-subgraph/abis/Swaplace.json - Update the file
swaplace-subgraph/schema.graphqlwith the new entities - Update the file
swaplace-subgraph/subgraph.ymalwith the new event handlers - Update the file
swaplace-subgraph/src/swaplace.tswith the new functions and imports - Run the commands
graph codegenandgraph build --network localhostin theswaplace-subgraphfolder. - 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 buildto generate the necessary files - Run the command
graph deploy --studio swaplace-subgraphto deploy the subgraph
Use The Graph Studio to play around with the queries. You can use the query mentioned earlier to start.