In my Dapp, I have two different ERC20 tokens: say, ABCToken and XYZToken. A user could give 10 ABCTokens to an account and in return should get 5 XYZTokens.

Is it possible to do this directly without converting to ethers in between? If so, what is the best way to do it (i.e. at a high level, what kind of contracts and operations required to achieve this)?

1 Answer 1


ERC-20 defines the transferFrom and approve method. We can use them nicely in this case.

Create an escrow contract, which does the exchange for you. Your users can then allow it to take a certain amount of tokens from their balance using approve. When both users approved the correct amount, the escrow could then make the swap. This is done by calling transferFrom on both tokens, transferring the tokens to the escrow contract. Immediately after that, the escrow could forward the tokens to the receiving parties.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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