I am trying to code in solidity a pay fee function like so:
contract GetFee {
address payable public feeCollector = 0x59c0f4Bea65c99C281A0107C86beE309b20b3B49;
function payFee() public payable {
feeCollector.transfer(100000000000000000);
}
}
However when I click it in solidity I get the following error:
Note: The called function should be payable if you send value and the value you send should be less than your current balance.
If I do however insert any amount in the deploy & run, like 1 ETH for example, it works, but I don't want to do that.
I want a function that when clicked it simply send that specific amount to that specific address, without the user having to insert anything else.
How to do that?
When the GetFee
is deployed, it holds 0 ETH.
feeCollector.transfer(100000000000000000);
This snippet sends 0.1 ETH (100000000000000000 wei specified in the code) to the feeCollector
from the contract address - not from the user.
So when the payFee()
is trying to submit the 0.1 ETH without anyone sending at least this amount to the contract beforehand, the transfer fails because the contract doesn't have sufficient balance.
Mind that the amount sent with the transaction invoking a contract function always need to originate from the user. It's not possible to invoke a function that would just pull a predefined amount from their wallet.