Welcome to the series on Celo Spark! In this mini-series, we will explore The Graph and its usefulness in addressing common pain points. We will also have a coding session with a special guest to integrate it into our NFT project. In this first part, we will set up our project and deploy a smart contract using Celo Composer and Hardhat.
Setting Up the Project
- Open your console and navigate to the desired directory.
- Use Celo Composer to create a new project by running the following command:
shellCopy code
celocli node:composer create celo-subgraph-box
For a detailed walkthrough, refer to the Celo Composer video in this series.
Installing Dependencies
- Open the project folder and install the dependencies by executing:
shellCopy code
cd celo-subgraph-box
npm install
Working with the Hardhat Repo
- Remove the example smart contracts provided with the project.
- Install the OpenZeppelin library by running:
shellCopy code
npm install @openzeppelin/contracts
- Create a new contract named
CeloBox
. This contract will be an ERC721 token that extendsEnumerable
andOwnable
. The maximum supply of tokens is set to 15, and only the owner can mint them one by one. - Set the base URI for the token metadata by specifying the IPFS URL.
- Prepare the deployment script by creating a new environment file (e.g.,
.env
) and filling it with the required data. - Update the deployment script to verify the network in which you will deploy the smart contract.
- Check the script defined in the
package.json
file that will be used for deployment. - Deploy the smart contract on the Alfajores network by running the following command:
shellCopy code
yarn deploy
If your contract is not verified, you can use the following commands for verification:
- CeloScan:
shellCopy code
npx hardhat verify 'address' 'args' --network alfajores
- Explorer:
shellCopy code
npx hardhat --network alfajores sourcify
Minting the First NFT
- Use CeloScan to mint the first NFT directly.
- Verify that the NFT minting event has been emitted, as this will be used by the subgraph.
Setting Up a Subgraph on Graph Studio
- Access Graph Studio and use the Valora app for connection.
- Scan the QR code and sign the transaction to establish the connection.
- Create a new subgraph by setting the name and the chain.
- Create the subgraph.
Conclusion
Congratulations! You have successfully set up your project, deployed a smart contract on the Alfajores network, and minted your first NFT. In the next part of this mini-series, we will dive into the coding session with our special guest. Stay tuned for more exciting content!