Refunder

Description:

Smart contract deployed on Ethereum.

Blockchain: Ethereum

Source Code: View Code On The Blockchain

Solidity Source Code:

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28;

contract Refunder {
    event Refund(address indexed sender, address indexed recipient, uint256 amount);
    event BatchRefund(address indexed sender, address[] recipients, uint256[] amounts, uint256 totalAmount);

    // Single refund function - send exact amount as msg.value
    function refund(address payable recipient) external payable {
        require(recipient != address(0), "Refunder: recipient cannot be zero address");
        require(msg.value > 0, "Refunder: refund amount must be greater than 0");

        recipient.transfer(msg.value);
        emit Refund(msg.sender, recipient, msg.value);
    }

    // Batch refund function - main functionality requested
    function batchRefund(address[] calldata recipients, uint256[] calldata amounts) external payable {
        require(recipients.length > 0, "Refunder: recipients array cannot be empty");
        require(recipients.length == amounts.length, "Refunder: recipients and amounts arrays must have the same length");

        uint256 totalAmount = 0;
        // First, calculate total amount and validate inputs
        for (uint256 i = 0; i < recipients.length; i++) {
            require(recipients[i] != address(0), "Refunder: recipient cannot be zero address");
            require(amounts[i] > 0, "Refunder: refund amount must be greater than 0");
            totalAmount += amounts[i];
        }

        require(msg.value == totalAmount, "Refunder: msg.value must equal sum of amounts");

        // Execute refunds
        for (uint256 i = 0; i < recipients.length; i++) {
            payable(recipients[i]).transfer(amounts[i]);
            emit Refund(msg.sender, recipients[i], amounts[i]);
        }

        emit BatchRefund(msg.sender, recipients, amounts, totalAmount);
    }

}

Tags:
addr:0x9a1dc92173b3b7d5eac23e0a0d99434981d5556c|verified:true|block:23465075|tx:0x3d55920fe1f621f25f571bce4a772eb7442f50c6f72c76b18c6af4ba2c5b73a7|first_check:1759136547

Submitted on: 2025-09-29 11:02:28

Comments

Log in to comment.

No comments yet.