Start a Standard Exit
Exits allow a user to withdraw funds from the OMG Network back onto the root chain. There are two types of exits: standard exits and in-flight exits. This section will cover standard exits.
A standard exit can be initiated by a user for an output generated by a transaction that was included in a valid block.
Implementation
To access network features from your application, use our official libraries:
Requires Node >= 8.11.3 < 13.0.0
2. Import dependencies
Staring an exit on the OMG Network involves using 2 omg-js
objects. Here's an example of how to instantiate them:
web3_provider_url
- the URL to a full Ethereum RPC node (local or from infrastructure provider, e.g. Infura).
plasmaContractAddress
-CONTRACT_ADDRESS_PLASMA_FRAMEWORK
for defined environment.
watcherUrl
- the Watcher Info URL for defined environment (personal or from OMG Network).
3. Start a standard exit
Exits are processed in queues and contain tokens you can use to start an exit. Before you start an exit, the network has to verify that the exit queue for the token used in the UTXO exists.
You can exit only 1 UTXO at a time. Consider merging multiple UTXOs into 1 UTXO if you don't want to exit all of your funds at once. By default, priority is given to UTXOs that were created the earliest.
Every exit requires an extra fee called an exit bond as an incentive mechanism for users of the OMG Network to exit honestly and challenge dishonest exits. The bond is currently fixed at an amount estimated to cover the gas cost of submitting a challenge. You can check the current gas cost at ETH Gas Station.
The standard exit process is the same for both ETH and ERC20 UTXOs. The tutorial shows how to work with ERC20 tokens. For working with ETH, change
erc20Exit
intoethExit
.
gasLimit
- gas limit for your transaction. Please check the current data on Gas Station or similar resources.
A standard exit creates an exit receipt. The receipt has the following structure:
After a standard exit starts, you'll have to wait a certain amount of time before you can process that exit and receive your funds back on Ethereum Network. This time is called a challenge period and equals to two minExitPeriod
(2 weeks) on the mainnet and 1 day on the Ropsten testnet (see EXIT_PERIOD
in Environments for the latest info). A challenge period is an incentivized security measure that allows other users to challenge anybody's exits for validity and honesty.
Lifecycle
A user calls the
hasToken
function on thePlasmaFramework
contract to check if there's an exit queue for the token in question. If no exit queue is registered, a user needs to register it using theaddToken
function. The correspondingPlasmaFramework
contract functions used in this step arehasExitQueue
andaddExitQueue
.A user calls the
getExitData
function on the Watcher to get the necessary exit data to start a standard exit. A transaction is termed "exitable" if it is correctly formed and properly signed by the owner(s) of the transaction input(s).A user calls the
startStandardExit
function on thePaymentExitGame
contract and commits an exit bond to the exit.After a challenge period a user can process this exit.
You can only exit one UTXO at a time. It is therefore recommended to merge your UTXOs if you would like to exit multiple ones.
Demo Project
This section provides a demo project that contains a detailed implementation of the tutorial. If you consider integrating with the OMG Network, you can use this sample to significantly reduce the time of development. It also provides step-by-step instructions and sufficient code guidance that is not covered on this page.
JavaScript
To run a full omg-js
code sample for the tutorial, please use the following steps:
Clone omg-js-samples repository:
Create
.env
file and provide the required configuration values.Run these commands:
Open your browser at http://localhost:3000.
Select
Start a Standard ETH Exit
orStart a Standard ERC20 Exit
on the left side, observe the logs on the right.
Code samples for all tutorials use the same repository —
omg-js-samples
, thus you have to set up the project and install dependencies only one time.
Last updated on 12/4/2020 by Dmitry Baimuratov
Last updated