A Node.js script to fetch NFT token data and image URLs from Magic Eden's API for various EVM chains.
- Fetches token data for an entire NFT collection from Magic Eden
- Supports multiple EVM chains (ethereum, arbitrum, base, berachain, bsc, monad-testnet, polygon, sei)
- Uses cursor-based pagination for reliable data retrieval
- Saves token IDs and image URLs to chain-specific CSV files
- Handles rate limiting with automatic delays
- Tracks progress and provides detailed logging
- Avoids duplicate entries
- Node.js (v14 or higher)
- npm (Node Package Manager)
- Magic Eden API Key
- NFT Collection Contract Address
- Clone the repository:
git clone https://github.com/jim788e/MEimageDown.git
cd MEimageDown
- Install dependencies:
npm install
- Create a
.env
file based on.env.example
:
cp .env.example .env
- Add your Magic Eden API key, NFT contract address, and desired EVM chain to the
.env
file.
Edit the .env
file with your specific details:
NFT_CONTRACT=your_contract_address_here
MAGIC_EDEN_API_KEY=your_api_key_here
EVM_CHAIN=ethereum # Change this to your desired chain
Available EVM chains:
- ethereum
- arbitrum
- base
- berachain
- bsc
- monad-testnet
- polygon
- sei
You can also modify these constants in fetch_tokens.js
:
TOTAL_TOKENS
: Total number of tokens to fetchBATCH_SIZE
: Number of tokens to fetch per request (default: 20)
Run the script:
node fetch_tokens.js
The script will:
- Validate the specified EVM chain
- Fetch token data in batches
- Show progress and token ranges
- Create an
output
directory - Save results to
output/{chain}_token_images.csv
The script generates a CSV file (output/{chain}_token_images.csv
) with the following columns:
tokenId
: The token ID numberimageUrl
: The URL of the token's image
The output files are organized by chain name, making it easy to manage data from multiple collections across different chains.
The script includes:
- EVM chain validation
- Request error handling
- Rate limiting protection
- Progress tracking
- Duplicate entry prevention
- Maximum attempts limit
dotenv
: For environment variable managementnode-fetch
: For making HTTP requestsfs
: For file system operations
MIT License
Feel free to submit issues and pull requests.