Skip to content

script for batch attestation creation from CSV using EAS multiAttest()#133

Merged
joelamouche merged 4 commits intoTheSoftwareDevGuild:mainfrom
tusharshah21:feat-130-foundary-batch
Nov 29, 2025
Merged

script for batch attestation creation from CSV using EAS multiAttest()#133
joelamouche merged 4 commits intoTheSoftwareDevGuild:mainfrom
tusharshah21:feat-130-foundary-batch

Conversation

@tusharshah21
Copy link
Collaborator

Features

  • CSV parsing with validation (address, badge name, distribution ID)
  • Batch processing (50 attestations max) to prevent gas issues
  • Dry-run mode for safe validation
  • Comprehensive error handling and logging
  • Environment variable input for security

Closes #130

Copy link
Contributor

@joelamouche joelamouche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks like you could use "vm.readFile(path)" to load the csv directly into foundry, which is cleaner than loading the whole file in env.

That being said, it looks like it would be cleaner and simpler to load from a json.

Example:

{
  "recipients": [
    { "address": "0x1111111111111111111111111111111111111111", "amount": "1000000000000000000" },
    { "address": "0x2222222222222222222222222222222222222222", "amount": "2500000000000000000" }
  ]
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "forge-std/Script.sol";
import "forge-std/StdJson.sol";
import {TheGuildActivityToken} from "../src/TheGuildActivityToken.sol";

contract BatchMintJson is Script {
    using stdJson for string;

    // Set your token address (must be owned by PRIVATE_KEY)
    address public constant TOKEN = 0x0000000000000000000000000000000000000000;
    // Path relative to repo root
    string public constant JSON_PATH = "data/recipients.json";

    struct Recipient {
        address addr;
        uint256 amount;
    }

    function run() external {
        uint256 pk = vm.envUint("PRIVATE_KEY");
        vm.startBroadcast(pk);

        TheGuildActivityToken token = TheGuildActivityToken(TOKEN);

        // Read JSON file
        string memory json = vm.readFile(JSON_PATH);

        // Read array length first
        uint256 len = json.readUint(".recipients.length");

        for (uint256 i = 0; i < len; i++) {
            // Build JSON pointer per index
            string memory base = string.concat(".recipients[", vm.toString(i), "]");
            address to = json.readAddress(string.concat(base, ".address"));
            uint256 amt = json.readUint(string.concat(base, ".amount"));

            if (to != address(0) && amt > 0) {
                token.mint(to, amt);
            }
        }

        vm.stopBroadcast();
    }
}

I think it makes more sense to write the forge script for a json and add a shell utils to convert a csv into a json.

Copy link
Contributor

@joelamouche joelamouche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall great job!
Some fixes needed before we merge this though

Copy link
Contributor

@joelamouche joelamouche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Outstanding work 🎉

@joelamouche joelamouche merged commit 5a0a398 into TheSoftwareDevGuild:main Nov 29, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add foundry batch attestation distribution script

2 participants

Comments