I have a contract that I can deposit ethers by using a fallback
function. The question is, I want to send the ethers INSIDE THIS smart contract to another random address.
I am not asking to send ethers from one address to another. I am asking to send ethers in this contract to another address. Or the same question in other words: How can i send the ethers inside this smart contract to any address I want(without using selfdestruct
).
function foo is sending ether from function caller address to the target address (_to
). That is not what I want. I want send ethers inside this contract to the target address(_to
). Do you have any idea how to do this?
//SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.7;
contract TestCall {
fallback() external payable{}
function foo(address payable _to) external payable{
(bool success, ) = _to.call{value: msg.value}("");
require(success, "transaction failed");
}
function getBalance() external view returns(uint){
return address(this).balance;
}
}