How do I fix Error: Deployment Failed on ganache?
How do I fix Error: Deployment Failed on ganache?
Loading saved threads...
kaustubh sharma · External communityPost link
External question — Ethereum Stack Exchange
Author: kaustubh sharma
Original post: https://ethereum.stackexchange.com/questions/153484
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
I am encountering this error while deploying my smart contract on the Ganache blockchain, can anyone help me fix it?
Error: *** Deployment Failed ***
"Coffee" hit an invalid opcode while deploying. Try:
* Verifying that your constructor params satisfy all assert conditions.
* Verifying your constructor code doesn't access an array
* List item
I deployed it on the test net and it showed no error, but when I deployed it on Ganache, it returned this error.
this is my deployment script
var MyContract = artifacts.require("coffee");
module.exports = function (deployer) {
deployer.deploy(MyContract);
};
this is my contract
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract CoffeePurchase {
address public owner;
mapping(address => string) private messages;
struct purchase {
string from;
string to;
address addFrom;
address addTo;
}
purchase[] public purchases;
event PurchaseMade(address indexed buyer, uint256 amount, string message);
constructor() {
owner = msg.sender;
}
modifier onlyOwner() {
require(msg.sender == owner, "Only the owner can access this function");
_;
}
function purchaseCoffee(string calldata _from,string calldata _to,address _addTo,string memory message) public payable {
require(msg.value > 0, "Coffee price must be greater than 0 wei");
messages[_addTo] = message;
purchases.push(purchase(_from,_to,msg.sender,_addTo));
emit PurchaseMade(msg.sender, msg.value, message);
}
function showDetails() external view returns(purchase[] memory){
return purchases;
}
function getMessage() public view returns (string memory) {
return messages[msg.sender];
}
function withdrawFunds() public onlyOwner {
payable(owner).transfer(address(this).balance);
}
}
Quote
Report
Venkata Mahesh Polumuri · External communityPost link
External answer — Ethereum Stack Exchange
Author: Venkata Mahesh Polumuri
Original post: https://ethereum.stackexchange.com/a/159749
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
I had the same problem and it's solved by doing the following..!
Go to
truffle-config.js
and change the
solc version
to "0.8.0" or "0.8.2" (both worked fine for me)
Quote
Report
Post Reply
Quoted from Forex.com.bd-Editorial External answer — Ethereum Stack Exchange Author: Venkata Mahesh Polumuri Source score (net votes, not local likes): 0 Original post: https://ethereum.stackexchange.com/a/159749 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. I had the same problem and it's solved by doing the following..! Go to truffle-config.js and change the solc version to "0.8.0" or "0.8.2" (both worked fine for me)
Checking account access…