lessmore92 / php-erc20

The simple way to interact with Ethereum ERC20 token.
MIT License
26 stars 26 forks source link

Impossible to send approve without ETH for gas #10

Closed 99hops closed 2 years ago

99hops commented 2 years ago

@lessmore92 Hello mate, you state that by

//by this method we allow $myapp_address to send upto 99999 token behalf of $owner_address
$approve_tx    = $token->approve($owner_address, $myapp_address, 99999);
$approve_tx_id = $approve_tx->sign($owner_private)
                            ->send()

$owner_address allows $myapp_address to send some USDT amount to any address without $owner_address having anything but USDT in his wallet.

Well how is this possible to work while for approve() to work you have to send a transaction which needs gas (ETH)?

I tried with account only having token inside and got

message: "insufficient funds for transfer"
code: -32000

Here is a TX on etherscan showing the exact approve() method called that costs $31 :smiley:

lessmore92 commented 2 years ago

Hi, approve is a transaction that needs to be paid a fee. Yes, for the approve method you need to pay the fee from the owner's address. So for the first transaction that does the approve, address needs to have some ETH for gas.

99hops commented 2 years ago

I agree, just wanted to point this out, thanks :beers: !

lessmore92 commented 2 years ago

Thank you, I will update the doc.