直接贴代码:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract BatchTransfer {
event Transfer(address indexed from, address indexed to, uint256 value);
constructor() payable {
}
function batchTransfer(address payable[] memory _recipients, uint256 _amount) public payable {
for(uint256 i = 0; i < _recipients.length; i++) {
_transfer(msg.sender, _recipients[i], _amount);
}
}
function _transfer(address _from, address payable _to, uint256 _amount) internal {
(bool success, ) = _to.call{value: _amount}("");
require(success, "Transfer failed");
emit Transfer(_from, _to, _amount);
}
}
实现原理:先往合约中转账指定的金额,然后通过合约转账给接收者
合约部署:
转账支持:
如果转账失败,可以直接debug:
标签:转账,批量,uint256,Transfer,solidity,payable,amount,address From: https://www.cnblogs.com/zhanchenjin/p/18023621