0

Can I send ERC20 and ETH in the same transaction trough web3js ?

I want enable the user to send my token with ETH in a same transaction to my wallet. I know that there are 2 transactions (ETH transfer & token transfer). But could it be possible to approve both at the same time?

I do not want the user to accept 3 metamask popups (approve ETH spending, approve token spending, Smart Contract transfer ETH & ERC20 Token function).

0

Yes you need a custom transfer method in your token, default transfer method is not payable, so write another payableTransfer method to let user send ETH and in web3 set value field of transaction to ETH amount and data field of transaction to payableTransfer method data

2
  • But that custom method implies creating that it is not exactly an ERC20 and can lead to another issues.
    – AlexAcc
    Dec 1 '21 at 18:31
  • Exactly, the best way is to do as ERC20 standard Dec 2 '21 at 9:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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