Description:
Smart contract deployed on Ethereum with Factory features.
Blockchain: Ethereum
Source Code: View Code On The Blockchain
Solidity Source Code:
{{
"language": "Solidity",
"sources": {
"contracts/batch_transfer_v4/BatchTransfer.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
interface IERC20 {
function transfer(address recipient, uint256 amount) external;
function balanceOf(address owner) external view returns (uint256);
function transferFrom(address sender, address recipient, uint256 amount) external;
}
contract BatchTransfer {
address private _owner;
uint256 public fee;
uint256 public feePerAddress;
constructor() {
_owner = msg.sender;
fee = 20000000;
feePerAddress = 0;
}
modifier onlyOwner() {
require(msg.sender == _owner, 'Not owner');
_;
}
modifier collectFee(uint256 addressCount) {
uint256 totalFee = fee + (feePerAddress * addressCount);
require(msg.value >= totalFee, 'Insufficient fee');
_;
}
function owner() public view returns (address) {
return _owner;
}
function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0), 'Zero address');
_owner = newOwner;
}
function setFee(uint256 _fee) external onlyOwner {
fee = _fee;
}
function setFeePerAddress(uint256 _feePerAddress) external onlyOwner {
feePerAddress = _feePerAddress;
}
function batchTransferEther(
address payable[] calldata recipients,
uint256[] calldata amounts
) external payable collectFee(recipients.length) {
require(recipients.length == amounts.length, 'Array length mismatch');
uint256 totalAmount = 0;
uint256 length = recipients.length;
for (uint256 i = 0; i < length; i++) {
totalAmount += amounts[i];
}
uint256 totalFee = fee + (feePerAddress * recipients.length);
require(msg.value >= totalAmount + totalFee, 'Insufficient balance');
for (uint256 i = 0; i < length; i++) {
recipients[i].call{ value: amounts[i] }('');
}
}
function batchTransferToken(
IERC20 token,
address[] calldata recipients,
uint256[] calldata amounts
) external payable collectFee(recipients.length) {
require(recipients.length == amounts.length, 'Array length mismatch');
uint256 totalAmount = 0;
uint256 length = recipients.length;
for (uint256 i = 0; i < length; i++) {
totalAmount += amounts[i];
}
token.transferFrom(msg.sender, address(this), totalAmount);
for (uint256 i = 0; i < length; i++) {
token.transfer(recipients[i], amounts[i]);
}
}
function batchTransferTokenSimple(
IERC20 token,
address[] calldata recipients,
uint256[] calldata amounts
) external payable collectFee(recipients.length) {
require(recipients.length == amounts.length, 'Array length mismatch');
uint256 totalAmount = 0;
uint256 length = recipients.length;
for (uint256 i = 0; i < length; i++) {
token.transferFrom(msg.sender, recipients[i], amounts[i]);
totalAmount += amounts[i];
}
}
function withdrawNativeToken() external onlyOwner {
uint256 balance = address(this).balance;
require(balance > 0, 'No tokens to withdraw');
payable(msg.sender).call{ value: balance }('');
}
function withdrawERC20Token(IERC20 token) external onlyOwner {
uint256 balance = token.balanceOf(address(this));
require(balance > 0, 'No tokens to withdraw');
token.transfer(msg.sender, balance);
}
receive() external payable {}
}
"
}
},
"settings": {
"evmVersion": "paris",
"optimizer": {
"enabled": false,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"libraries": {}
}
}}
Submitted on: 2025-10-20 14:46:03
Comments
Log in to comment.
No comments yet.