Last active
July 29, 2022 19:19
-
-
Save opub/13be3cd6bed6c0229b19013df949f797 to your computer and use it in GitHub Desktop.
Download all NFT images in a Solana wallet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# This script downloads all of the NFT images in a Solana wallet to your local machine. | |
# It should work on Windows, macOS and Linux. Windows would require WSL, Git Bash or similar. | |
# Pass the Solana wallet address and optionally an offset if there are more than 500. | |
# | |
# For example to get the first 500 NFT images: | |
# ./download.sh FoRen4D8jyU1RX9jY7pneaNg3E6CopUEV8cvP1o5vnRm | |
# Then to get 501-1000: | |
# ./download.sh FoRen4D8jyU1RX9jY7pneaNg3E6CopUEV8cvP1o5vnRm 500 | |
# | |
# check input params | |
if [ -z "$1" ]; then | |
echo "Usage: $0 <wallet> [offset]" | |
exit 1 | |
fi | |
wallet=$1 | |
if [ -z "$2" ]; then | |
offset=0 | |
else | |
offset=$2 | |
fi | |
# get token names and images from MagicEden API | |
tokens=$(curl --silent --request GET "https://api-mainnet.magiceden.dev/v2/wallets/$wallet/tokens?offset=$offset&limit=500" | jq -r '.[] | (.name + "\t" + .image)') | |
echo "$tokens" | while read pair; | |
do | |
# determine filename based on NFT name and image extension | |
name=$(echo "$pair" | cut -d$'\t' -f1) | |
image=$(echo "$pair" | cut -d$'\t' -f2) | |
if [[ $image == *"ext="* ]]; then | |
filename="$name.${image##*ext=}" | |
else | |
filename="$name.${image##*.}" | |
fi | |
# download image to file | |
echo "downloading \"$filename\" from $image" | |
curl -C - --silent --location "$image" --output "$filename" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment