[Ethereum] Send tokens using approve and transferFrom vs only transfer

contract-developmenterc-20tokens

We can send tokens using below ERC20 contract methods

  1. approve() and transferFrom()
  2. transfer()

Here if i use 2nd option the tokens are directly transferred, while if i use 1st option its a two step process

I am new to this and i want to understand the difference between the two ways?

Best Answer

Transfer method

The transfer method is for a 2 party transfer, where a sender wishes to transfer some tokens to a receiver.

  • Sender ➜ transfer(receiver, amount)

Approve and transferFrom method

The approve + transferFrom is for a 3 party transfer, usually, but not necessarily that of an exchange, where the sender wishes to authorise a second party to transfer some tokens on their behalf.

  • Sender ➜ approve(exchange, amount)
  • Buyer ➜ executes trade on the Exchange
  • Exchange ➜ transferFrom(sender, buyer, amount)
Related Topic