0

I've sent the transaction - https://ropsten.etherscan.io/tx/0xbecb36319d806edc3617abcbeb1f95e7215cb205dc180088f225c1addd82086f to the contract address and it got reverted.

Could someone explain me why?

Contract code:

pragma solidity ^0.6.8;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/contracts/math/SafeMath.sol";

contract Waterfall { using SafeMath for uint;

struct User {
    address payable addr;
    uint amount;
}

address payable public owner;
User[] public users;
uint public totalUsers = 0;
uint public feePercentage = 10;
uint public payoutPercentage = 10;

constructor() public {
    owner = msg.sender;
}

function join() external payable {
    require(msg.value >= 1 ether, "Investment must be at least 1 ether");
    users.push(User(msg.sender, msg.value));
    totalUsers += 1;

    uint fee = msg.value.mul(feePercentage).div(100);
    owner.transfer(fee);

    uint position = 0;
    while(position < totalUsers) {
        uint payout = users[position].amount.mul(payoutPercentage).div(100);
        if(payout > address(this).balance){
            break;
        }
        users[position].addr.transfer(payout);
        position += 1;
    }
}

}

1 Answer 1

0

You are sending an empty transaction with 1.1 Ethers without targeting any specific function.

As you are using Solidity version 0.6.8 you need to have either the receive function (https://solidity.readthedocs.io/en/v0.6.8/contracts.html#receive-ether-function) or fallback function (https://solidity.readthedocs.io/en/v0.6.8/contracts.html#fallback-function) in your contract to catch transactions which do not call any specific function. As you don't have those the transaction fails.

Either specify that you want to call the join function or add a receive/fallback function in your contract.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.