-
My deploy.js code: const ethers = require("ethers");
const fs = require("fs-extra");
async function main() {
const provider = new ethers.providers.JsonRpcProvider(
"http://127.0.0.1:7545"
);
const wallet = new ethers.Wallet(
"0x557d7734c132de88e8c07f8b9d41d1affd5089c50f5c59c16ff788683c9123bf",
provider
);
const abi = fs.readFileSync("./SimpleStorage_sol_SimpleStorage.abi", "utf8");
const bytecode = fs.readFileSync(
"./SimpleStorage_sol_SimpleStorage.bin",
"utf8"
);
const contractFactory = new ethers.ContractFactory(abi, bytecode, wallet);
console.log("Deploying...");
//The error appears to happen at this line
const contract = await contractFactory.deploy({
/* Ethers.js forced me to set gasLimit */
gasLimit: 1e5,
});
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
}); And the error I received: error: Error: VM Exception while processing transaction: invalid opcode
at getResult (/Users/maximburin/Documents/blockhain_learning/ethers-simple-storage/node_modules/@ethersproject/providers/lib/json-rpc-provider.js:191:21)
at processJsonFunc (/Users/maximburin/Documents/blockhain_learning/ethers-simple-storage/node_modules/@ethersproject/web/lib/index.js:356:22)
at /Users/maximburin/Documents/blockhain_learning/ethers-simple-storage/node_modules/@ethersproject/web/lib/index.js:288:46
at step (/Users/maximburin/Documents/blockhain_learning/ethers-simple-storage/node_modules/@ethersproject/web/lib/index.js:33:23)
at Object.next (/Users/maximburin/Documents/blockhain_learning/ethers-simple-storage/node_modules/@ethersproject/web/lib/index.js:14:53)
at fulfilled (/Users/maximburin/Documents/blockhain_learning/ethers-simple-storage/node_modules/@ethersproject/web/lib/index.js:5:58)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: -32000,
data: {
hash: '0xcf2af5569adc054ba0a8f8e2a13621197d0e7155875eb7f6e6df86445b947d9c',
programCounter: 24,
result: '0xcf2af5569adc054ba0a8f8e2a13621197d0e7155875eb7f6e6df86445b947d9c',
reason: null,
message: 'invalid opcode'
}
}, Dependencies:
Ganache server settings (in case needed):
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Could you upload your whole repo please? Also, try messing with the gasLimit you have set in the contractFactory.deploy method, that's weird that it's having you set that manually as it usually shouldn't matter... If you could it might also help to post the error code you get when you don't manually set it. |
Beta Was this translation helpful? Give feedback.
-
@TheUnknownCodr Please check this here link |
Beta Was this translation helpful? Give feedback.
Seems like for some reason the version of solidity you're using is causing issues... change the solidity version in your SimpleStorage.sol to
and then go ahead and upgrade the solidity compiler in your terminal by running
and then finally you want to go ahead delete both the SimpleStorage abi and bin files, making sure to recompile with
Should be good after that! Let me know if that works for you...