0

I am having trouble with this parse error when I compile the abi. I want to be able to add the argument that gets passed into the function to the workdone. However when I try to do that I get a parse error. If I hardcode in a number then it compiles without issue. Any help?

doesn't compile

function test1(address addr1, uint8 num) nonReentrant external {
    for (uint8 i = 0; i < num; i++) {
       //do the thing
    }        
    workDone[msg.sender] = workDone[msg.sender].add(uint256(num ether));
}

compiles fine

function test1(address addr1) nonReentrant external {
    for (uint8 i = 0; i < 10; i++) {
       //do the thing
    }        
    workDone[msg.sender] = workDone[msg.sender].add(uint256(10 ether));
}

1 Answer 1

0

I believe that units like ether can only be used with integer literals at compile time. Just multiply by 10^18 instead:

workDone[msg.sender].add(num * 10**18);
0

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.