Solidity Pragma Error – Troubleshooting Not Working Issues

blockchainbrowserserrorremixsolidity

enter image description here

Dear all, I am very new to Ethereum, noob-new. This might anger many but, i have to ask, why is pragma solidity not functioning correctly. I have seem countless examples where pragma solidity ^0.4.0; works, but why doesn't it work for me? I tried this out on remix.ethereum.org, the ethereum browser based compiler.

I receive this error, help please, anyone!

browser/Untitled.sol:1:1: ParserError: Expected pragma, import directive or contract/interface/library definition.
pragma solidity ^0.4.0;

Here is the code:

pragma solidity ^0.4.0;
contract MyfirstContract{
    string private name;
    uint private age;

    function setName(string newName){
        name=newName;
    }
    fucntion getName() returns (string){
        return;

    }

}

Best Answer

This occurs when compiler has not loaded yet. You should wait for some time

For statement like pragma solidity ^0.4.11, waiting for some time will make that error go away. In this statement, by using ^ we are saying to use any compiler above 0.4.11 so if 0.4.21 is loaded, then also it will work.

But sometimes this error can stay. This happens if you are using specific compiler version, as in the line below:

pragma solidity 0.4.3;

In that case, go to the settings section given on right handside, and select the compiler version which you are using.

Related Topic