Error: Compiler version ^0.8.0 does not satisfy the r semver requirement - solidity

I am new to solidity and I am running code on Remix.
It doesn't matter what version of compiler I specify, I keep on getting the same error.
Can someone help me out? What does "Compiler version ^0.8.0 does not satisfy the r semver requirement" exactly mean?
Here is my code:
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^ 0.8.0;
contract Storage {
struct People {
uint256 favoriteNumber;
string name;
}
mapping(string => uint256) public nameToFavoriteNumber;
People[] public people;
function addPerson(uint _personFavoriteNumber, string memory _personName ) public {
people.push(People({favoriteNumber: _personFavoriteNumber, name: _personName}));
nameToFavoriteNumber[_personName] = _personFavoriteNumber;
}
}

I had the same issue a couple of times. In Remix, I added a ".0" to the compiler version like so:
pragma solidity ^0.8.4.0;
I ran into this in Virtual Studio code also but I just ignored it and everything worked fine. I hope this helps!

It works in Remix as well, but I have worked on contracts that work without adding that ".0" at last, now even they show this error.
pragma solidity ^0.8.8.0;

Related

How to check values of a variables and functions in solidity like javascript via console.log

How to check values of a variables and functions in solidity like javascript via console.log? Because i need visibility of results for deep understanding.
I am newbie...
i tried hardhat but need more understand.
I'm a newbie too, but I know this (I think)!
There is no console in solidity, you need to write a function for this, or just put it public in the variable itself!
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
contract Value {
uint public num; //add "public" to see the value
function add(uint _num) external{
num += _num;
}
//this function is for returning value
function viewNum() public view returns(uint){
return(num);
}
}
Also use the Remix editor, it's in the browser. There are plenty of videos on the internet!
If you are using hardhat, then you can use console.sol.
You need to import it into your contract.
import "hardhat/console.sol";
Now, you are able to log your variable while you are working.
console.log(__your_variable__);
If you are still looking to log your variables once you deploy your contract, then you need to use event functionality.
Import hardhat console:
import "hardhat/console.sol";
Use console log in your contract
console.log(variable); //Variable value
console.log(1234); //direct value

Created custom ERC20 contract, balanceOf msg.sender is zero

I've created a ERC20 contract in Remix:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "#openzeppelin/contracts/token/ERC20/ERC20.sol";
contract MyToken is ERC20 {
constructor(string memory name, string memory symbol) ERC20(name, symbol) {
_mint(msg.sender, 1002000);
}
}
Then I deployed it:
But the balance of msg.sender is zero:
Does anyone know what's wrong?
I just tried your code and it works perfectly like intended.
It is important, that you compile the correct contract using Remix, see my attached picture. You need to choose the contract "MyToken". I guess you could have deployed the contract "ERC20 - #openzeppelin/contracts/token/ERC20/ERC20.sol" which would lead to the behaviour you mentioned.
compile "MyToken" in Remix

Execution is reverted in Solidity and Remix

I've wrote a simple code for fetching ETH price by using Chainlink interfaces as below:
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
import "#chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";
contract ABI {
AggregatorV3Interface internal priceFeed;
constructor() public {
priceFeed = AggregatorV3Interface(0xF4030086522a5bEEa4988F8cA5B36dbC97BeE88c);
}
function latestPrice() public view returns (int256) {
(, int256 answer,,,) = priceFeed.latestRoundData();
return answer;
}
}
The problem is when is being compiled by Remix, it has no problem but after execution it throws the error below:
call to ContractName.FunctionName errored: execution reverted
Do you think what the problem is?
Because your question didn't specify on which network you're running the script, I'm assuming that you're using the Remix VM emulator.
The specified Chainlink contract is available on Ethereum mainnet only. Any other network (including the emulator) does not have this contract deployed on this address.
To use the data feed contract in Remix, you can create a local fork of the mainnet, and then connect to the local network in the IDE.
Change ENVIRONMENT to Injected Web3 in Remix IDE and connect to metamask. For example, if you are using Kovan network use address as mentioned in the docs.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
import "#chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
contract PriceConsumerV3 {
AggregatorV3Interface internal priceFeed;
/**
* Network: Kovan
* Aggregator: ETH/USD
* Address: 0x9326BFA02ADD2366b30bacB125260Af641031331
*/
constructor() {
priceFeed = AggregatorV3Interface(0x9326BFA02ADD2366b30bacB125260Af641031331);
}
/**
* Returns the latest price
*/
function getLatestPrice() public view returns (int) {
(
/*uint80 roundID*/,
int price,
/*uint startedAt*/,
/*uint timeStamp*/,
/*uint80 answeredInRound*/
) = priceFeed.latestRoundData();
return price;
}
}

Cannot Compile StorageFactory.sol because "not found contracts/SimpleStorage.sol

I am doing the Solidity, Blockchain, and Smart Contract Course – Beginner to Expert Python Tutorial from freeCodeCamp and Patrick AlphaC
https://github.com/PatrickAlphaC/storage_factory
Below is my code image from my IDE too here
// SPDX-License_Identifier: MIT
pragma solidity ^0.8.0;
import "./SimpleStorage.sol";
contract StorageFactory {
SimpleStorage[] public simpleStorageArray;
function createSimpleStorageContact() public {
SimpleStorage simpleStorage = new SimpleStorage();
simpleStorageArray.push(simpleStorage);
}
}
and I am getting the error:
not found contracts/SimpleStorage.sol
even though all the files are spelt correctly and in the same folder.
Please help as I am trying to follow along with the tutorial and don't want to get left behind.
In your picture your filename is wrong. You write SimpleSorage but it must be SimpleStorage. (Note the missing t in Storage.)

Is this a remix,compiler or an openzeplin bug?

I just wrote a simple code to test openzeplin Safemath library. I am using the latest version of remix ide and compiling for ^0.5.0.
Remix is using 0.5.0_commit.1d4f565a compiler
The environment is JavaScript VM
EVM Version is the compiler default
The add function does not seem to be working in the code given below
I have tried x.sub(1) it throws an exception as expected, i have also tried initializing x to different values but still does not work.
pragma solidity ^0.5.0;
import "./SafeMath.sol";
contract SimpleStorage {
using SafeMath for uint;
uint x;
event incremented(uint x);
constructor() public{
x=0;
}
function increment() public {
x.add(1);
emit incremented(x);
}
function get() external view returns (uint) {
return x;
}
}
Expected output is an increment by one on every call to the function but getting the same value every time. Emit also shows the same value.
Well, it's your bug :)
Instead of x.add(1) try x = x.add(1). Add function is not inplace, new value is returned and you need to assign the new value to x.