can I use a Externally Owned Account to call contract account function to transfer ether to other Externally Owned Accounts, and the ether is from contract account.
1 Answer
Yes you can and it's very simple to do.
Something like this:
pragma solidity ^0.5.1;
contract MyContr {
function transfer(address payable receiver, uint amount) public {
require(address(this).balance >= amount);
receiver.transfer(amount);
}
}
Then you deploy the contract, get its ABI and address, input those into a wallet software of your choice and send a transaction to the transfer
function of the contract with the required parameters.
You should of course add all sort of security checks (not everyone should be allowed to do the transfer).
-
Am I right to think so: If one EOA(1) call smart contract transfer function to another EOA(2), it means that it will cost smart contract account's ether instead of EOA(1).– Lance liCommented Apr 11, 2019 at 6:40
-
The Ether can come from either EOA1 or from the smart contract - it's up to you to decide how it should work Commented Apr 11, 2019 at 6:43
-
yeah, but I don't know how to let the ether come from smart contract, I tried in remix, but I found I take the ether from the EOA1.– Lance liCommented Apr 11, 2019 at 6:59
-
Just use the code I gave you. Of course the contract has to have some Ether to be able to send it. Commented Apr 11, 2019 at 9:24
-