Skip to main content

Introduction

In this guide, you will create an ERC20 token on Monad Testnet and index its transfers with GhostGraph. You’ll learn how to:
  • Deploy a basic ERC20 token contract
  • Test the contract locally
  • Deploy to Monad Testnet
  • Set up event tracking with GhostGraph

Prerequisites

Before starting, ensure you have:
  • Node.js installed (v16 or later)
  • Git installed
  • Foundry installed
  • Some MONAD testnet tokens (for gas fees)
  • Basic knowledge of Solidity and ERC20 tokens

Project Setup

First, clone the starter repository:

CatToken Contract Implementation

The src/CatToken.sol contract implements a basic ERC20 token with a fixed supply. Here’s the code:
src/CatToken.sol
This implementation:
  • Creates a token with name “CatToken” and symbol “CAT”
  • Mints 1 billion tokens to the deployer’s address
  • Uses OpenZeppelin’s battle-tested ERC20 implementation

Testing the Contract

Navigate to the test file test/CatToken.t.sol:
test/CatToken.t.sol
Run the tests:

Deployment Setup

1. Create a .env file:

2. Add your credentials to .env file:

3. Create deployment script script/DeployCatToken.s.sol:

script/DeployCatToken.s.sol

Deploying CatToken on Monad Testnet

1. Load environment variables:

2. Deploy the contract:

Save the deployed contract address for the next steps. Remember to add TOKEN_ADDRESS into your .env file You should now have

Verify Smart Contract

1. Load environment variables:

2. Verify the contract:

After verification, you should see the contract verified on the MonadVision. You should see a checkmark and the banner stating the contract source code verified. Verified Contract

Script for Token Transfers Transactions Onchain

We perform some token transfer transactions onchain to trigger the Transfer event that GhostGraph will index. View the transfer script script/TransferCatTokens.s.sol:
script/TransferCatTokens.s.sol
Run the below command to execute transfers:
You have now deployed your ERC-20 contract and submitted transactions on the Monad testnet. Let’s track these onchain events with GhostGraph.

Setting Up GhostGraph Indexing

  1. Visit GhostGraph and click sign up for an account
  2. Create a new GhostGraph
create_ghost_graph
  1. Copy and paste this into events.sol file. We are interested in tracking token flow. Let’s insert this event here. To learn more about events: https://docs.tryghost.xyz/ghostgraph/getting-started/define-events
events.sol
  1. Copy and paste this into schema.sol file. In this case, we are creating a few struct which we will use to save entity into the Ghost database. To learn more about schema: https://docs.tryghost.xyz/ghostgraph/getting-started/define-schema
schema.sol
  1. Click on generate code button to generate indexer.sol file along with some other readonly files. This file will be where the logic and transformations resides.
  2. Copy and paste this into indexer.sol be sure to insert your token address to the CAT_TESTNET_TOKEN_CONTRACT_ADDRESS variable.
indexer.sol
  1. Compile and deploy your GhostGraph. After a few seconds, you should see GhostGraph has successfully indexed your contract.
ghostgraph_playground
  1. Clicking on the playground will take you to the GraphQL playground, where you can ensure the data is indexed correctly. Let’s copy and paste this into our playground and click the play button to fetch the data from GhostGraph.
GraphQL Playground
graphql_playground
Try submitting additional transactions by running the transfer script again. You should see that GhostGraph automatically indexes the new transactions.

Conclusion

You have now successfully created a GhostGraph to track onchain data for your contract. The next step is to connect it to your frontend. The Ghost team has created end-to-end tutorials on how to do just that here