I’m very new in development. I have a simple smart contract that has 2 functions. 1 is to receive payments from any address. 2 withdrawAll that works only for the owner of the contract.
The problem is that when the contract has some ETH on it’s balance and owner calls withdrawAll function, the ETH value in the transaction is 0. The balance of the contract also goes to 0.
Contract was deployed via remix in Sepolia testnet. When deploying in remix via RemixVM Cancun everything works perfect.
Where can be the problem?
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract MyShop {
address public owner;
mapping (address => uint) public payments;
constructor() {
owner = msg.sender;
}
function payForItem() public payable {
payments[msg.sender] = msg.value;
}
function withdrawAll() public {
address payable _to = payable(owner);
address _thisContract = address(this);
_to.transfer(_thisContract.balance);
}
}
Contract was deployed via remix in Sepolia testnet. When deploying in remix via RemixVM Cancun everything works perfect.
Also tried to to host locally a simple frontend page with withdraw button that calls Metamask to confirm the transaction. And Metamask showed ETH(balance of the contract to be transferred to the owner) with positive sign.
Игорь Любинецкий is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.