This is a Javascript library that allows you to interact with OmiseGo's MoreVP implementation of Plasma. It provides functions to:
- Deposit (Eth/Token) from the Root chain into the Child chain.
- Transact on the Child chain.
- Exit from the Child chain back to the Root chain.
- Challenge an invalid exit.
This library is currently compatible with version 0.2 of the OMG Network
The project is organized into 3 submodules:
- @omisego/omg-js-rootchain
- @omisego/omg-js-childchain
- @omisego/omg-js-util
You can use any of them separately, or all at once by importing the parent @omisego/omg-js
package
Requires Node >= 8.11.3
npm install @omisego/omg-js
Copy the dist/omg.js
file into your project and include it.
<script type="text/javascript" src="omg.js"></script>
Both Alice's and Bob's Ethereum accounts need to have some ETH in them. The ETH is used for gas costs on the rootchain, fees on the childchain and the actual ETH transferred from Alice to Bob.
You can find example code inside examples
folder. To run the examples, step inside the examples
directory. Run npm install
. Edit your config.js
file to have to correct settings for your environment.
Let's run through a story between Alice and Bob. In this story, Alice will first deposit some ETH from the root chain into the child chain. Then Alice will transfer some of that ETH to Bob on the child chain. Finally, Bob will exit his funds from the child chain back into the root chain. His root chain balance will be reflected with the extra ETH that Alice sent to him on the child chain.
From the examples
folder run the scripts below in order to follow the story.
-
Deposit some ETH from Alice's Rootchain to the Childchain
npm run childchain-deposit
-
Send some ETH from Alice's Childchain to Bob's Childchain
npm run childchain-transaction
Alice has now sent some ETH to Bob. You should see a UTXO for Alice and a UTXO for Bob as a result of this transaction.
-
Get Alice's and Bob's Childchain UTXOs
npm run childchain-utxos
-
Transfer (exit) all of Bob's Childchain funds to the Rootchain
npm run childchain-exit
Checking Bob's final rootchain balance you will notice it will be a little less than expected. This is because of rootchain gas costs Bob had to pay to exit the childchain.