github.com/iotexproject/iotex-core@v1.14.1-rc1/action/protocol/execution/testdata-london/multisend.sol (about)

     1  // SPDX-License-Identifier: GPL-3.0
     2  
     3  pragma solidity ^0.8.14;
     4  
     5  contract Multisend {
     6      event Transfer(address recipient, uint256 amount);
     7      event Refund(uint256 refund);
     8      event Payload(string payload);
     9  
    10      function multiSend(
    11          address[] memory recipients,
    12          uint256[] memory amounts,
    13          string memory payload
    14      ) public payable {
    15          require(
    16              recipients.length <= 300,
    17              "number of recipients is larger than 300"
    18          );
    19          require(recipients.length == amounts.length, "parameters not match");
    20          uint256 totalAmount = 0;
    21          for (uint256 i = 0; i < recipients.length; i++) {
    22              totalAmount += amounts[i];
    23          }
    24          require(msg.value >= totalAmount, "not enough token");
    25          uint256 refund = msg.value - totalAmount;
    26          for (uint256 i = 0; i < recipients.length; i++) {
    27              payable(recipients[i]).transfer(amounts[i]);
    28              emit Transfer(recipients[i], amounts[i]);
    29          }
    30          if (refund > 0) {
    31              payable(msg.sender).transfer(refund);
    32              emit Refund(refund);
    33          }
    34          emit Payload(payload);
    35      }
    36  }