How to index token transfers with GhostGraph
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:
git clone https://github.com/chrischang/cat-token-tutorial.gitcd cat-token-tutorialCatToken Contract Implementation
The src/CatToken.sol contract implements a basic ERC20 token with a fixed supply. Here's the code:
CatToken.sol
12345678910111213141516
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:
CatToken.t.sol
123456789101112131415161718192021222324252627282930
Run the tests:
forge test -vvDeployment Setup
1. Create a .env file:
cp .env.example .env2. Add your credentials to .env file:
PRIVATE_KEY=your_private_key_hereMONAD_TESTNET_RPC=https://testnet-rpc.monad.xyz3. Create deployment script script/DeployCatToken.s.sol:
DeployCatToken.s.sol
12345678910111213141516171819
Deploying CatToken on Monad Testnet
1. Load environment variables:
source .env2. Deploy the contract:
forge script script/DeployCatToken.s.sol \--rpc-url $MONAD_TESTNET_RPC \--broadcastSave the deployed contract address for the next steps.
Remember to add TOKEN_ADDRESS into your .env file
You should now have
PRIVATE_KEY=your_private_key_hereMONAD_TESTNET_RPC=https://testnet-rpc.monad.xyzTOKEN_ADDRESS=0x...