This application scrapes NFT metadata from IPFS using a CSV list of IPFS CIDs and stores the results in a PostgreSQL database. It also hosts an API that allows users to retrieve all stored metadata or a specific row based on a CID.
- Read a list of IPFS CIDs from a CSV file
- Fetch metadata for each CID from IPFS
- Store the
name
andimage
fields in a PostgreSQL database - Provide an API to retrieve all data or a specific row based on a CID
- Go 1.19 or higher
- PostgreSQL
- Docker (for running PostgreSQL in a container, if desired)
git clone https://github.com/shawnwollenberg/ipfs-metadata.git
cd nft_scraper
You can either set up PostgreSQL locally or use Docker to run it in a container.
Using Docker:
docker run --name postgres -e POSTGRES_USER=youruser -e POSTGRES_PASSWORD=yourpassword -e POSTGRES_DB=yourdb -p 5432:5432 -d postgres
Create a .env file in the root directory of the project with the following content:
env
POSTGRES_USER=youruser
POSTGRES_PASSWORD=yourpassword
POSTGRES_DB=yourdb
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
go mod tidy
A CSV file has been saved in the data
directory, but if you would like to add additional CIDs feel free to adjust. Each row should contain one CID.
go run .
This will:
- Read the CSV file.
- Fetch metadata for each CID from IPFS.
- Store the name and image fields in the PostgreSQL database.
- Start the API server.
GET /metadata
[
{
"cid": "Qm...",
"name": "Example Name",
"image": "Example Image URL"
},
...
]
GET /metadata/:cid
{
"cid": "Qm...",
"name": "Example Name",
"image": "Example Image URL"
}
- Gin Gonic for the web framework.
- sqlx for SQL database interactions.
- godotenv for loading environment variables from a .env file.
For any questions or suggestions, please open an issue or contact the repository owner.