Deposit tokens

The DutchX allows to exhange any ERC20 compatible tokens.

In order to post sell orders, buy orders or add token pairs, you first need to deposit the tokens in the DutchX, so it’s important you understand how to:

  • Wrap ether (into WETH - Wrapped Ether)
  • Set an allowance of any token for the DutchX
  • Deposit in the DutchX

WETH (Wrapped Ether)

Ether is not an ERC20 token, this is why we need to wrap it first.

Technically, this means that we need to send some ether to the deposit function in a token contract called WETH (Wrapped Ether):

Allowance (any ERC20 token)

Other important thing we should know, is that the deposit function in DutchX, will call the ERC20 token contract transferFrom function to withdraw the amount for the user:

  • This transferFrom will fail if the user don’t set an allowance of at least the deposited amount for the DutchX proxy address (entry point for DutchX)
  • So you first need to invoke the approve function
  • This step is mandatory for WETH and for any other ERC20 token.

Deposit

The DutchX deposit operation will allow you to add tokens to your balance.

When you have balance in the DutchX you’ll be able to:

  • Submit sell orders
  • Submit buy orders
  • Add token pairs

Sequence diagram

This sequence diagram will shows how the different contracts and the user interact in order to do a deposit:

  1. Wrap 0.1 WETH: Remember Ether is not ERC20 compatible, so we need to do this step (deposit function on WETH contract).
  2. Set allowance, so DutchX proxy can transfer 0.1 WETH: Otherwise the deposit will fail, because the DutchX wouln’t be entitled to do the operation.
  3. Deposit 0.1 ETH in DutchX proxy: If we did the two prior steps, the user will have 0.1 WETH more in it’s balance.

Sequence for depositSequence for deposit

How to do it?

In this guided example you will make a dApp that wraps ether, sets the allowance and deposit into the dutchx.

Also you can use the CLI