Spark: The Graph Mini-Series (1/3) — NFT Smart Contract

Spark: The Graph Mini-Series (1/3) — NFT Smart Contract
none 0.0 0

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

  1. Open your console and navigate to the desired directory.
  2. 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

  1. Open the project folder and install the dependencies by executing:

shellCopy code

cd celo-subgraph-box
npm install

Working with the Hardhat Repo

  1. Remove the example smart contracts provided with the project.
  2. Install the OpenZeppelin library by running:

shellCopy code

npm install @openzeppelin/contracts
  1. Create a new contract named CeloBox. This contract will be an ERC721 token that extends Enumerable and Ownable. The maximum supply of tokens is set to 15, and only the owner can mint them one by one.
  2. Set the base URI for the token metadata by specifying the IPFS URL.
  3. Prepare the deployment script by creating a new environment file (e.g., .env) and filling it with the required data.
  4. Update the deployment script to verify the network in which you will deploy the smart contract.
  5. Check the script defined in the package.json file that will be used for deployment.
  6. 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

  1. Use CeloScan to mint the first NFT directly.
  2. Verify that the NFT minting event has been emitted, as this will be used by the subgraph.

Setting Up a Subgraph on Graph Studio

  1. Access Graph Studio and use the Valora app for connection.
  2. Scan the QR code and sign the transaction to establish the connection.
  3. Create a new subgraph by setting the name and the chain.
  4. Create the subgraph.


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!


Nice. Would try this out soon