The withdrawal flow

withdrawal flow

In StarkEx Spot Trading v4.0 and later, registration of your user’s Ethereum address occurs offchain.

Before withdrawal can occur, StarkEx requires transferring the funds from your user’s vault to another offchain vault that is identified with the same user’s Ethereum address instead of their public Stark key.

The add_transaction API with the TransferRequest transaction type registers the Ethereum address.

You can enable registration in your offchain application’s logic in one of the following ways:

  • Your user enters a request to transfer the funds from the vault with their Stark key to a vault that they identify with their Ethereum address.

  • When your application prompts the user for the information required to send a WithdrawalRequest transaction to the StarkEx gateway, it also prompts them to enter the parameters necessary to execute a TransferRequest transaction, and your application executes the transfer as a seamless step in the withdrawal process.

The basic withdrawal flow takes place as detailed here, assuming that your application takes care of transferring the funds for the user.

1. Alice submits an offchain withdrawal request

Alice enters a request to withdraw funds using the offchain application.

2. The application sends a TransferRequest transaction to StarkEx.

The application sends a transfer request transaction to the StarkEx gateway, using the add_transaction API with the TransferRequest transaction type.

A transfer request, signed by Alice, moves the funds from her vault to another offchain vault that is identified with her Ethereum address instead of her Stark key.

3. The application sends a WithdrawalRequest transaction to StarkEx.

The application checks the validity of the withdrawal request according to its business logic and the state of Alice’s vault. If it is valid, it sends the offchain withdrawal request to the StarkEx gateway, using the add_transaction API with the WithdrawalRequest transaction type.

4. StarkEx validates the withdrawal request.

StarkEx checks that the vault is properly signed by the Stark key that owns the position.

5. StarkEx includes the withdrawal in a batch.

If the withdrawal is valid, it is included in a batch to be submitted onchain along with a validity proof.

6. StarkEx moves the funds to the withdrawal area.

Upon performing state update, the StarkEx smart contract moves the relevant funds to the withdrawal area, under the user identity that appears in the withdrawn L2 vault.

7. Alice withdraws the funds onchain

Once the funds are in the withdrawal area, Alice can make an onchain call to withdraw the funds to any recipient.

Implementing a withdrawal in your application.

To implement withdrawal functionality in your application, use the add_transaction API with the WithdrawalRequest transaction type.

The StarkEx REST API reference includes all necessary information.