Lesson 5 - Deploying contract on Ganache: Runtime Error, invalid opcode #5706
-
Hello everyone, Here is my const ethers = require("ethers");
const fs = require("fs-extra");
async function main() {
// compile them in our code
// http://127.0.0.1:7545
const provider = new ethers.JsonRpcProvider("HTTP://127.0.0.1:7545");
const wallet = new ethers.Wallet(
"privateKey",
provider
);
const abi = fs.readFileSync("./SimpleStorage_sol_SimpleStorage.abi", "utf8");
const binary = fs.readFileSync(
"./SimpleStorage_sol_SimpleStorage.bin",
"utf8"
);
const contractFactory = new ethers.ContractFactory(abi, binary, wallet);
console.log("Deploying, please wait...");
const deploymentOptions = {
gasLimit: 2000000,
};
const contract = await contractFactory.deploy(deploymentOptions);
console.log(contract);
}
main()
.then(() => {
setTimeout(() => console.log("A"), 3000);
console.log("B");
process.exit(0);
})
.catch((error) => {
console.log("C");
console.error(error);
process.exit(1);
}); When I use the command But I get an error right away and can't see the Here is the error:
And here is the smart contract code: // SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
contract SimpleStorage {
uint256 favoriteNumber;
struct People {
uint256 favoriteNumber;
string name;
}
People[] public people;
mapping(string => uint256) public nameToFavoriteNumber;
function store(uint256 _favoriteNumber) public {
favoriteNumber = _favoriteNumber;
}
function retrieve() public view returns (uint256) {
return favoriteNumber;
}
function addPerson(string memory _name, uint256 _favoriteNumber) public {
people.push(People(_favoriteNumber, _name));
nameToFavoriteNumber[_name] = _favoriteNumber;
}
} Any ideas of what I am doing wrong? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Okay, before I used solidity version |
Beta Was this translation helpful? Give feedback.
-
@LouisHatte Thanks for your suggestion but if anyone still getting the error then set solc to 0.8.7-fixed version and solidity to ^0.8.7 version |
Beta Was this translation helpful? Give feedback.
Okay, before I used solidity version
^0.8.18
and solc version in my package.json was^0.8.20
.Downgrading my solidity version to
^0.8.7
and solc version to^0.8.8
solved my issue.