0

I'm trying to develop an Smart Contract function that accepts and ERC20 token, and send it to another address.

I know that I make the user to call approve and later execute the function:

//check SC's allowance for that token/sender
uint256 allowance = token.allowance(msg.sender, address(this));
//Transfer token from user's address to another address
token.transferFrom(msg.sender, one_address, amount);

I don't want the user to execute more than one transaction (first approve, and later the payment). I would like the user to call the Smart Contract's function while sending some ERC20 tokens to that function with web3, like this (not working).

paymentContract.methods.sendToken(token_value).send({
          "from": fromAddress
        })

I would like the Smart Contract's function to receive the tokens, and send them to another address in one transaction/Function call.

Is it possible, without approve/transferFrom() ?

Explanation I do not want to make approve & transferFrom in same transaction. I already know that is not possible.

My goal is to call an Smart Contract's function accepting ERC20 token and ETH, in order to send ERC20 token and ETH in one transaction, from my wallet, with web3.

0

1 Answer 1

0

I don't want the user to execute more than one transaction (first approve, and later the payment). I would like the user to call the Smart Contract's function while sending some ERC20 tokens to that function with web3, like this (not working).

ERC-20 does not support this. However there are multiple token standards that do. Fore example, ERC-777 is ERC-20 backwards compatible and supports single transaction token smart contract interactions.

More about the issue of well-known ERC-20 design limitations here.

Not the answer you're looking for? Browse other questions tagged or ask your own question.