Created
April 23, 2024 13:13
-
-
Save refex/43414b7b9fb599c46675fd437aea4a9d to your computer and use it in GitHub Desktop.
bash script to refresh NFT collection on Opensea
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
1. create executable .sh file | |
2. paste code below | |
3. run like this `./script.sh 1 100 0x66466c5d3823ca01eaf0e88719ecd499cd6bcee8 matic` | |
``` | |
#!/bin/bash | |
# Check if all required arguments are provided | |
if [ "$#" -ne 4 ]; then | |
echo "Usage: $0 <start> <end> <address> <chain>" | |
exit 1 | |
fi | |
# Assign command-line arguments to variables | |
START=$1 | |
END=$2 | |
ADDRESS=$3 | |
CHAIN=$4 | |
# Define your API key | |
API_KEY="2e52947bf393445f871d62d23a03126a" | |
# Define the base URL based on the provided chain | |
if [ "$CHAIN" == "matic" ]; then | |
BASE_URL="https://api.opensea.io/api/v2/chain/matic/contract/$ADDRESS/nfts/" | |
elif [ "$CHAIN" == "ethereum" ]; then | |
BASE_URL="https://api.opensea.io/api/v2/chain/ethereum/contract/$ADDRESS/nfts/" | |
else | |
echo "Unsupported chain. Please provide either 'matic' or 'ethereum' as the chain parameter." | |
exit 1 | |
fi | |
# Define the path segment for the refresh endpoint | |
REFRESH_PATH="/refresh" | |
for ((i = $START; i <= $END; i++)); do | |
# Construct the complete URL | |
URL="$BASE_URL$i$REFRESH_PATH" | |
# Send the HTTP request | |
echo "Sending request for n=$i on chain=$CHAIN..." | |
curl --request POST --url "$URL" --header "x-api-key: $API_KEY" | |
echo "Request for n=$i on chain=$CHAIN completed." | |
echo | |
# Wait for 3 seconds before next iteration | |
sleep 3 | |
done | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment