A GraphQL subgraph that indexes and tracks TalentProtocol token transfers on the Base network, providing real-time data about token balances, transfer history, and user activity.
This subgraph monitors the TalentProtocol token contract deployed on Base network and indexes all transfer events, maintaining comprehensive records of:
- User token balances
- Historical balance changes with timestamps
- Complete transfer transaction details
- Node.js (v16 or higher)
- Yarn package manager
- The Graph CLI
- Clone the repository:
git clone <repository-url>
cd talent-token-transfers- Install dependencies:
yarn install- Generate types from the GraphQL schema and ABIs:
yarn codegen- Build the subgraph:
yarn buildyarn codegen- Generate TypeScript types from GraphQL schema and contract ABIsyarn build- Build the subgraph for deploymentyarn test- Run unit tests using Matchstickyarn deploy- Deploy to The Graph Studioyarn create-local- Create subgraph on local Graph Nodeyarn deploy-local- Deploy to local Graph Nodeyarn remove-local- Remove subgraph from local Graph Node
For local development, you can run a local Graph Node using Docker:
docker-compose upThen deploy to your local node:
yarn create-local
yarn deploy-localRun the test suite:
yarn testTests are located in the tests/ directory and use the Matchstick testing framework.
- Network: Base
- Contract Address:
0x9a33406165f562E16C3abD82fd1185482E01b49a - Start Block:
21118758 - ABI: Located in
abis/TalentProtocolToken.json
Represents a token holder with their current balance.
type User @entity {
id: ID! # User's address in hex format
address: Bytes! # User's Ethereum address
balance: BigInt! # Current token balance
}Tracks balance changes over time for historical analysis.
type UserDateBalance @entity {
id: ID! # User's address in hex format
user: User! # Reference to the User entity
date: BigInt! # Timestamp of the balance change
oldBalance: BigInt! # Balance before the change
currentBalance: BigInt! # Balance after the change
}Immutable record of all token transfer events.
type Transfer @entity(immutable: true) {
id: Bytes! # Unique ID (transaction hash + log index)
from: Bytes! # Sender address
to: Bytes! # Recipient address
value: BigInt! # Amount transferred
blockNumber: BigInt! # Block number
blockTimestamp: BigInt! # Block timestamp
transactionHash: Bytes! # Transaction hash
}{
users {
id
address
balance
}
}{
transfers(where: { from: "0x..." }) {
id
to
value
blockTimestamp
}
}{
userDateBalances(where: { user: "0x..." }) {
date
oldBalance
currentBalance
}
}The handleTransfer function in src/talent-protocol-token.ts processes transfer events and:
- Creates Transfer Records: Stores immutable transfer event data
- Updates User Balances: Maintains current token balances for all users
- Tracks Balance History: Records balance changes with timestamps
- Handles Edge Cases: Manages insufficient balance scenarios gracefully
- Automatic User Creation: New users are automatically created when they first receive tokens
- Balance Validation: Ensures users have sufficient balance before deducting tokens
- Historical Tracking: Maintains complete balance change history
- Transaction Metadata: Captures block numbers, timestamps, and transaction hashes
- Authenticate with The Graph CLI:
graph auth --studio YOUR_DEPLOY_KEY- Deploy the subgraph:
yarn deploy- Start the local Graph Node:
docker-compose up- Create and deploy:
yarn create-local
yarn deploy-localtalent-token-transfers/
├── abis/ # Contract ABIs
│ └── TalentProtocolToken.json
├── src/ # Subgraph handlers
│ └── talent-protocol-token.ts
├── tests/ # Unit tests
│ ├── talent-protocol-token.test.ts
│ └── talent-protocol-token-utils.ts
├── generated/ # Generated code (created after codegen)
├── docker-compose.yml # Local Graph Node setup
├── networks.json # Network configurations
├── package.json # Dependencies and scripts
├── schema.graphql # GraphQL schema definition
├── subgraph.yaml # Subgraph manifest
└── tsconfig.json # TypeScript configuration
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Run the test suite
- Submit a pull request
This project is UNLICENSED.
For questions, issues, or contributions, please refer to the project's issue tracker or contact the development team.