I have a simple contract where I implemented a mechanism that sends ETH to contributors
. When I call contribute
function everything works great, but if I use something like that bulkSend(msg.value / 2)
I have an error:
revert The transaction has been reverted to the initial state. Note: The called function should be payable if you send value and the value you send should be less than your current balance. Debug the transaction to get more information.
What's wrong?
pragma solidity >=0.4.22 <0.7.0;
contract Test {
address payable[] public contributors;
constructor() public {}
function bulkSend(uint256 amount) public payable {
uint256 share = amount / contributors.length;
uint256 length = contributors.length;
uint256 currentSum = 0;
for (uint256 i = 0; i < length; i++) {
require(share > 0);
currentSum += share;
require(currentSum <= msg.value);
contributors[i].transfer(share);
}
require(currentSum == msg.value);
}
function contribute() public payable {
contributors.push(msg.sender);
bulkSend(msg.value);
}
}