I'm developing an ERC721 contract. Whenever i call my mint function, i get this error :
Error encountered during contract execution [stack underflow (0 <=> 2)]
My function contains nothing but a simple require and return statement.
Any Help would be very much appriciated
I then downgraded to Sol 0.6.6 But i keep getting the same issue. Even meta mask shows this message when im about to confirm the transaction :
This is my Mint function :
function Mint() notBroke external payable returns (uint256) {
require(msg.value >= 0.05 ether, 'You didnt pay enough Eth Buddy :/');
return 1;
}
This is My notBroke Modifier :
modifier notBroke() {
require(address(this).balance > 0 ether,"You Broke");
_;
}
And this is how I am committing the transaction from the Front end (using meta mask) :
const transactionParameters = {
to: Contract.address,
from: props.account, // must match user's active address.
value: parseInt(Web3.utils.toWei("0.05", 'ether')).toString(16),
data: web3.eth.abi.encodeFunctionCall(
{
"inputs": [],
"name": "Mint",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "payable",
"type": "function"
},[]
),
chainId: `0x${parseInt(props.network)}`, // Used to prevent transaction reuse across blockchains. Auto-filled by MetaMask.
};
await window.ethereum.request({
method: 'eth_sendTransaction',
params: [transactionParameters],
}).then( (result) => {
resolve(result)
}).catch((error)=> resolve(error))
And this is whats shown on Etherscan :
Here you have added modifier Which means your contract should have balance greater then 0, so at first time your contract will have 0 ether so it will revert transaction, please try to check balance of your contract and I think so you should check balance user who want to mint token
The modifier throws an exception (effectively reverting the transaction) with message "You Broke" if the contract address (not the sender address) has 0 balance.
If you want to update the modifier to revert only if the sender address has 0 balance, you need to use msg.sender instead of address(this):
require(msg.sender.balance > 0 ether,"You Broke");