Im trying to run the following solidity-by-example on remix:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
contract Payable {
// Payable address can receive Ether
address payable public owner;
// Payable constructor can receive Ether
constructor() payable {
owner = payable(msg.sender);
}
// Function to deposit Ether into this contract.
// Call this function along with some Ether.
// The balance of this contract will be automatically updated.
function deposit() public payable {}
// Call this function along with some Ether.
// The function will throw an error since this function is not payable.
function notPayable() public {}
// Function to withdraw all Ether from this contract.
function withdraw() public {
// get the amount of Ether stored in this contract
uint amount = address(this).balance;
// send all Ether to owner
// Owner can receive Ether since the address of owner is payable
(bool success, ) = owner.call{value: amount}("");
require(success, "Failed to send Ether");
}
// Function to transfer Ether from this contract to address from input
function transfer(address payable _to, uint _amount) public {
// Note that "to" is declared as payable
(bool success, ) = _to.call{value: _amount}("");
require(success, "Failed to send Ether");
}
}
Once deployed, when I call the "transfer" function using any of the remix' javascript VM addresses as the _to and the number 1
as _amount its reverting with the following:
revert The transaction has been reverted to the initial state. Reason provided by the contract: "Failed to send Ether".
I don't think it has to do with access but with how I am introducing the attributes. Can anyone point me the right way to do it? Thank you in advance!