Environment
Truffle, OpenZepelin 2.5.1
Details
I want to add a function that sends tokens to multiple accounts in one transaction to reduce gas costs. But it is giving me this error:
Thrown: Error: Returned error: VM Exception while processing transaction: revert
So I wrote a test function that simply returns the input. It gives the same error when I call it in truffle.
Could someone help me out pls
Code to reproduce
Here’s my code:
pragma solidity >= 0.5.5;
//SPDX-License-Identifier: MIT
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20Detailed.sol";
contract BPTToken is Context, ERC20, ERC20Detailed {
constructor(
string memory name,
string memory symbol,
uint256 initialSupply
) public ERC20Detailed(name, symbol, 18) {
_mint(_msgSender(), initialSupply);
}
event DoneStuff(uint input);
function test(uint input) external returns(uint){
return input;
}
function multipleTransfer(address[] memory recipients, uint256[] memory amounts, uint256 totalAmount) external returns (uint256) {
return totalAmount;
uint recipientsLen = recipients.length;
uint amountsLen = amounts.length;
require(recipientsLen == amountsLen, "Recipients and amounts must have the same length.");
require(balanceOf(_msgSender()) >= totalAmount, "Not enough fund.");
for (uint index = 0; index < recipientsLen; index++) {
address recipient = recipients[index];
uint256 amount = amounts[index];
bool result = transferFrom(_msgSender(), recipient, amount);
if (!result) {
return false;
}
}
return true;
}
}