Deploy a simple smart contract on the Polygon Mumbai testnet and deploy a subgraph for it.
We can’t wait for you to complete this and claim, your PFP’s 🖼️ and $GRT.
-
#graphathon
-
#graphIndia
- Open Remix IDE. Create a Solidity file
Graphathon.sol
and paste the following code.
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
contract Graphathon {
event ChangeNameEvent (string name);
event ChangeTwitterNameEvent (string name);
event TransferEvent(address from, address to, uint amount);
string public name = "The Graph";
string public twitterName = "graphprotocol";
function changeName(string calldata _name) public {
name = _name;
emit ChangeNameEvent(_name);
}
function changeTwitterName(string calldata _twitterName) public {
twitterName = _twitterName;
emit ChangeTwitterNameEvent(_twitterName);
}
function transfer(address payable to) public payable {
to.transfer(msg.value);
emit TransferEvent(msg.sender, to, msg.value);
}
}
-
Compile the contract and deploy it to Mumbai testnet using
Injected Provider
as the environment. Note down the contract address. -
Verify and publish your smart contract (Don't know how? See this)
-
Go to the Subgraph studio and connect your wallet.
-
Click on
Create a Subgraph
. Name your subgraph and select 'Polygon Mumbai' as the blockchain network. Your subgraph is created 🤩. -
You need to install The Graph protocol CLI to work with the subgraph.
npm install -g @graphprotocol/graph-cli
OR
yarn global add @graphprotocol/graph-cli
- Create an empty folder and open it in your code editor (I love VSCode ❤️). Change the directory to that folder and fire up your terminal pointing to that folder.
- Now we will initialize the subgraph using the following command
graph init --studio SUBGRAPH_NAME
-
Select
ethereum
as Protocol -
Press Enter for
subgraph slug
andDirectory to create subgraph in
. -
Select
mumbai
as our network. -
Enter the contract address of your deployed contract from above. It will automatically fetch the ABI as we have verified our contract.
-
Enter the block number in which the contract is created.
-
Enter
Graphathon
as the contract name. -
Press Enter for
Index contract events as entities
. -
You have successfully created your first Subgraph. (YOU ARE AWESOMEEE! 🙇🏻♂️)
- You need to authenticate your subgraph. Refer dashboard for the key.
graph auth --studio 5a6288af6001705f65d514e5423b018d
- Change the directory to your deployed subgraph folder
cd graphathon
Make use of the dashboard to see the commands
- Now we build our subgraph using the following command
graph codegen && graph build
- Final Step - Deploy your subgraph. 🥳🥳🥳
graph deploy --studio graphathon
-
You can give the version as
v0.1
-
Play around with your contract. Transfer some ETH / MATIC or change your name or Twitter username using the Remix IDE.
-
Go to the
Playground
on the dashboard and query the data. -
Create a new file with title
solution-2.md
and add the contract address and the subgraph endpoint in the file. -
[VERY IMPORTANT STEP] Add the link of this
solution-2.md
file to this Graph-A-Thon challenge submission form.
-
Create a new branch
username_graphathon
, e.g.yash251_graphathon
-
Create a file named
solution-2.md
for this challenge. -
Add the contract address and the subgraph endpoint in the file.
-
Submit details on the Airtable form.
This is an important step, please don't skip it.