[SOLVED] Retrieve eth contract balance

hi there,

i am trying to retrieve contract balance by the owner, just in case i wrongly transferred eth into smart contract.

here is my code:

function WDETH() public payable {
uint256 amount = address(this).balance;
if(amount > 0) {
msg.sender.transfer(amount);
}
}

and i got the following error. been work around but still stuck.

any advice? thank you!

you could hardcode that address where to transfer the funds and use address payable public for it

cool, thanks! it works now. and here’s my code in case someone need the info:

address payable public _ownerAddress =
    payable(address(0xyourwalllet));

function WDETH() public payable {
uint256 amount = address(this).balance;
if(amount > 0) {
_ownerAddress.transfer(amount);
}
}

1 Like