1
votes

I want to create a smart contract which people can transfer tokens without ether in their wallet.

Suppose A want to transfer ERC20 tokens to B, but he does not have ether in his wallet.

Does third party C can send the transaction for A and therefore pay the gas? Is it possible to create a function in the contract for this usgae?

I have searched online for a soloution and could not find one.

3

3 Answers

1
votes

This is a key issue of Ethereum dApp development, but also of tokens. Here is a very old thread on Ethereum Stack Exchange, and also this one.

There are 2 options with their pros and cons:

  1. Use signatures

    • Every function in your smart contract must have signature parameter.
    • People who want to interact with the smart contract must sign the function parameters with their account's private key and send it to the smart contract owner (via any communication channel).
    • The owner then submits the parameters along with the signature to the blockchain, paying for gas. The signature guarantees that the message was approved by the user.
  2. Refund used gas at the end of the transaction. A modifier refundGasCost can be used for this (see below).

But (1) is really hard to apply to token transfers where you just don't know who uses the token and (2) does not really address the issue.

There is a lot happening recently, there is this blog post about How to save your Ethereum Dapp users from paying gas for transactions, and since you ask about tokens, there is an ERC that suggests to Pay transfers in tokens instead of gas, in one transaction which would be nice if you have tokens but no ETH.

I hope this helps.

0
votes

Exactly this case is already defined in the ERC20 standard. Its this function:

function transferFrom(address from, address to, uint tokens) public returns (bool success);

But before party C could use it and send tokens from A to B, A would have to approve C to do this via the following function, which is also defined in the ERC20 standard:

function approve(address spender, uint tokens) public returns (bool success);
-1
votes

No, in a standard ERC20 token contract, the token holder must initiate at least one transaction (to call transfer() or approve()), and a transaction must always be paid for by its initiator.