🐍Airdrop Code

Code for generating a tap protocol airdrop from .csv

☆ PYTHON CODE ☆

import csv
import json

def generate_json_from_csv(csv_file_path, output_json_path):
    # List to store the addresses from the CSV
    addresses = []

    # Read the CSV and extract the addresses
    with open(csv_file_path, 'r') as csv_file:
        csv_reader = csv.reader(csv_file)
        next(csv_reader)  # Skip the header row
        for row in csv_reader:
            # Ensure the address is lowercase if it starts with bc1
            address = row[1].strip()
            if address.startswith("bc1"):
                address = address.lower()
            addresses.append(address)

    # Format the addresses into the JSON structure
    formatted_data = {
        "p": "tap",
        "op": "token-send",
        "items": []
    }

    for address in addresses:
        formatted_data["items"].append({
            "tick": "BUNNY",
            "amt": "10000",
            "address": address
        })

    # Save the formatted data to a JSON file
    with open(output_json_path, 'w') as json_file:
        json.dump(formatted_data, json_file, indent=4)

    print(f"JSON saved to {output_json_path}")

# Call the function to generate the JSON
generate_json_from_csv('drop.csv', 'output.json')

HOW TO MODIFY

Step 1. Change these values to your ticker and airdrop amount

"tick": "SYMBOL",
"amt": "10000",

Step 2. Change these values to match your .csv name and desired output

generate_json_from_csv('drop.csv', 'output.json')

Step 3. Save the python code. Make sure the .csv file is in same directory and properly formatted with the wallet address on the second column. Afterwards run the python code from the terminal.

python3 generate.py
or
python generate.py

☆ If all worked, it will generate a new file: output.json in the following format

    "p": "tap",
    "op": "token-send",
    "items": [
        {
            "tick": "BUNNY",
            "amt": "10000",
            "address": "bc1p8neq0hqmv0rcmqcvkqat74kdqh67w0xahrqp0ptgdd2gr6pr56uqdnf36h"
        },
        {
            "tick": "BUNNY",
            "amt": "10000",
            "address": "bc1pvzpnqtqpghqkc4lpez5837pq4qdh7t4cuwz5wvfm26smkfzdaeuqt5qqqq"
        },
        {
            "tick": "BUNNY",
            "amt": "10000",
            "address": "bc1pjavxekqd9r6rwvhp6zl2wtk3a57w8kq7yrr2vpcw8kcxnk2mq8rqn2fjww"
        },
        {
            "tick": "BUNNY",
            "amt": "10000",
            "address": "bc1p3df7t0zlrv2t6l4y70g8m9q0hwmqruccdzswmavyg22egmf39xfqv8qmur"
        }
    ]
}

Make sure to TAP! After inscribing the token-send JSON, you will have to send the inscription to yourself in order to complete the Airdrop!


Follow @ordinalOS for more information.

Last updated