I am using Ubuntu 20.04.3 LTS.

Here is the piece of code given below:

pragma solidity ^0.8.0;

contract counterContract {
    uint256 public tokenCounter;

    function setCounter() public {
        unchecked {
            tokenCounter += 1;

When I try to compile this code using truffle compile it gives me the below error:

Error parsing /home/lenovo/deepak/solidity/contracts/counterContract.sol: ParsedContract.sol:8:19: ParserError: Expected ';' but got '{'
        unchecked {
Compilation failed. See above.

but the same code works perfectly in remixIDE.

How do I resolve this issue?


Your Answer

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

Browse other questions tagged or ask your own question.