'How to debug a parsererror in solidity
I need assistance here. I don't know why I keep having this error. I have added the ";" but I keep seeing the parser error message. I am supposed to compile and deploy the contract.
pragma solidity ^0.5.7;
contract Coin {
address public minter;
mapping(address => uint) public balances;
event sent(address from, address to, uint amount);
constructor() {
minter = msg.sender;
}
function mint(address receiver, uint amount) public {
require(msg.sender == minter);
balances[require] += amount;
}
error InsufficientBalance(uint requested, uint available);
function send(address receiver, uint amount) public {
if(amount > balances[msg.sender])
revert InsufficientBalance({
requested: amount,
available: balances[msg.sender]
});
balances[msg.sender] -= amount;
balances[receiver] += amount;
emit sent(msg.sender, receiver, amount);
}
}
Solution 1:[1]
Change your compiler version in your smart contract from:
pragma solidity ^0.5.7;
to
pragma solidity ^0.8.4;
Another problem that I identified is the struct in this instruction:
balances[require] += amount;
you must to change the key value of balances mapping with the address parameter passed it into the mint() function, in this way:
balances[receiver] += amount;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Kerry99 |
