A comprehensive indexing solution for Solana and EVM blockchain data using the Moralis API. This project provides real-time indexing of transactions, token balances, NFTs, and native balances for multiple addresses across both Solana and EVM chains.
- π Dual Chain Support: Index data from both Solana and EVM chains simultaneously
- π Comprehensive Data: Index transactions, token balances, NFTs, and native balances
- βοΈ Configurable: Easy configuration via environment variables
- π Continuous Indexing: Run continuously with configurable intervals or one-time execution
- π‘οΈ Error Handling: Robust error handling and logging
- π TypeScript: Fully typed for better development experience
- Node.js (v18 or higher)
- npm or yarn
- Moralis API key (Get one here)
- Clone the repository:
git clone <repository-url>
cd solana-trading-platform-infrastructure- Install dependencies:
npm install- Create a
.envfile based onenv.example:
cp env.example .env- Configure your
.envfile:
MORALIS_API_KEY=your_moralis_api_key_here
SOLANA_NETWORK=mainnet
SOLANA_ADDRESSES=address1,address2,address3
EVM_CHAIN=eth
EVM_ADDRESSES=0xaddress1,0xaddress2,0xaddress3
INDEX_INTERVAL_MS=60000
ENABLE_SOLANA_INDEXING=true
ENABLE_EVM_INDEXING=true| Variable | Description | Default | Required |
|---|---|---|---|
MORALIS_API_KEY |
Your Moralis API key | - | Yes |
SOLANA_NETWORK |
Solana network (mainnet, devnet, testnet) | mainnet | No |
SOLANA_ADDRESSES |
Comma-separated list of Solana addresses | - | No |
EVM_CHAIN |
EVM chain (eth, bsc, polygon, avax, etc.) | eth | No |
EVM_ADDRESSES |
Comma-separated list of EVM addresses | - | No |
INDEX_INTERVAL_MS |
Indexing interval in milliseconds | 60000 | No |
ENABLE_SOLANA_INDEXING |
Enable/disable Solana indexing | true | No |
ENABLE_EVM_INDEXING |
Enable/disable EVM indexing | true | No |
eth- Ethereum Mainnetbsc- Binance Smart Chainpolygon- Polygonavax- Avalanchefantom- Fantomcronos- Cronos- And more (check Moralis documentation)
Run with TypeScript directly (requires ts-node):
npm run dev- Build the project:
npm run build- Run the compiled code:
npm startRun indexing once and exit:
npm run dev -- --once
# or
npm start -- --onceBy default, the indexer runs continuously at the configured interval. To stop it, press Ctrl+C.
solana-trading-platform-infrastructure/
βββ src/
β βββ config/
β β βββ index.ts # Configuration management
β βββ indexers/
β β βββ solanaIndexer.ts # Solana data indexer
β β βββ evmIndexer.ts # EVM data indexer
β βββ utils/
β β βββ moralisClient.ts # Moralis API client setup
β βββ index.ts # Main entry point
βββ dist/ # Compiled JavaScript (generated)
βββ .env # Environment variables (create from env.example)
βββ env.example # Environment variables template
βββ package.json # Dependencies and scripts
βββ tsconfig.json # TypeScript configuration
βββ README.md # This file
- Transactions: Transaction history with signatures, block times, amounts, and fees
- Token Balances: SPL token balances with USD values
- NFTs: NFT holdings with metadata
- Native Balance: SOL balance
- Transactions: Transaction history with hashes, block numbers, gas info
- Token Balances: ERC-20 token balances with USD values
- NFTs: ERC-721/ERC-1155 NFT holdings with metadata
- Native Balance: Native token balance (ETH, BNB, MATIC, etc.)
- Token Prices: Token price information
To persist indexed data, you can extend the indexers. Example:
// In solanaIndexer.ts or evmIndexer.ts
async saveToDatabase(address: string, data: any) {
// Implement your database save logic here
// Example: await db.transactions.insertMany(data.transactions);
}Add custom processing logic in the indexAll() methods of each indexer to:
- Filter transactions
- Calculate statistics
- Send notifications
- Update dashboards
- etc.
The indexer includes comprehensive error handling:
- API errors are caught and logged
- Individual address failures don't stop the entire process
- Graceful shutdown on SIGINT/SIGTERM
Be aware of Moralis API rate limits. Adjust INDEX_INTERVAL_MS accordingly to avoid hitting rate limits.
-
"MORALIS_API_KEY is required"
- Make sure you've created a
.envfile with your API key
- Make sure you've created a
-
API Errors
- Verify your API key is valid
- Check your Moralis account limits
- Ensure addresses are in the correct format
-
No data returned
- Verify addresses are correct
- Check network/chain configuration
- Some addresses may have no transactions or balances
MIT
Contributions are welcome! Please feel free to submit a Pull Request.