1

I have the following code:

    function payout() public payable {    
        uint ordersLength = orders.length;    
        uint totalRaised = 0;    
        for (uint i = 0; i < ordersLength; i++) {    
            totalRaised += orders[i].amount;    
            emit Amount(orders[i].amount);    
        }    
        for (uint i = 0; i < ordersLength; i++) {    
            payable(orders[i].investor).transfer(msg.value * orders[i].amount / totalRaised);        
            emit onPayout(orders[i].investor, creator, orders[i].investorId, creationId, creatorId, block.timestamp,        
                         msg.value * orders[i].amount / totalRaised);    
        }    
    }    

But upon compiling the contract, I'm getting this error:

project:/contracts/Creation.sol:59:13: ParserError: Expected primary expression.
            payable(orders[i].investor).transfer(msg.value * orders[i].amount / totalRaised);
            ^-----^

How to fix this?

2
  • 1
    why do you have a contract named payable ? isn't that a special keyword in solidity?, change that name and see if the error eliviates. Jul 24, 2021 at 7:51
  • 1
    What Solidity version are you using ? The payable() function has been introduced in 0.6.0 Jul 24, 2021 at 13:32

1 Answer 1

2

The problem is because you are using a compiler version older than 0.6.

The solution is to use a compiler version more than or equals to 0.6 OR you can declare the investor field in your struct as address payable instead of address and you will not need to use the payable function because you will be able to transfer/send directly like this:

orders[i].investor.transfer(msg.value * orders[i].amount / totalRaised

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.