I Designed a quiz app which simply withdraws the amount earned by user after playing the game from the smart contract.But Each time i click on the withdraw button to call the withdraw function on my smart contract i always get the above error(Transaction Error: Error: non-payable method cannot override value ) here is the withdraw code for the frontend
const {ethereum} = window;
if (ethereum) {
console.log("withdrawing")
const provider = new ethers.providers.Web3Provider(ethereum, "any");
const signer = provider.getSigner();
const contract = new ethers.Contract(contractAddress, abi, signer);
try {
const tx = await contract.withdraw(userAddress, { value: earnedInWei });
await tx.wait();
console.log("Transaction Successful!");
} catch (error) {
console.error("Transaction Error: ", error);
}
} else {
console.error("No web3 provider found. Please install MetaMask or use another web3 provider");
}
}```
and below is my smart contract
```//SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.7;
contract ethQuiz {
//address of the owner of the smart contract
address payable public owner;
//Making sure that only the owner calls the smart contract
constructor(){
owner= payable(msg.sender);
}
//funding the smart contract
receive() external payable {
}
//for users to withdraw funds from the smart contract
function withdraw(uint256 amount) external {
require(amount <= address(this).balance, "too much!");
payable(msg.sender).transfer(amount);
}
//to check the available balance in the smart contract
function getBalance() external view returns (uint){
return address(this).balance;
}
}
//initial amount on smart contract:300000000000000000 wei```