@ripzery/omg-js-util v3.0.0-alpha.13
OMG-JS
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.
Compatibility
This library is currently compatible with version 0.3 of the OMG Network.
Below you can find a compatibility table of omg-js
with elixir-omg
and plasma-contracts
SHAs
Version | elixir-omg | plasma-contracts |
---|---|---|
3.0.0-alpha.13 (current) | 40f899b | 835d10c |
3.0.0-alpha.12 | 02e67bf | a7e8503 |
3.0.0-alpha.6 | 70e9a68 | 1608296 |
Getting Started
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
Installation
Node
Requires Node >= 8.11.3 < 13.0.0
npm install @omisego/omg-js
Browser
Copy the dist/omg.js
file into your project and include it.
<script type="text/javascript" src="omg.js"></script>
API Documentation
Design Documentation
Examples
Prerequisites
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. If you want to run the ERC20 examples, at least Alice's account will need an ERC20 balance to be able to deposit and transact on the childchain.
Running the Examples
You can find example code inside examples
folder.
To run the examples:
npm install
from root ofomg-js
.npm run lerna-reset
from root ofomg-js
.- Step inside the
/examples
directory. - Run
npm install
. Create
.env
file inside the root of the/examples
directory with the appropriate values (see/examples/env.example
for an example)Refer to below explanation of
.env
variables
GETH_URL= <entry point to an ethereum node>
WATCHER_URL= <url of an informational watcher>
WATCHER_PROXY_URL= <*optional* proxy server to catch all watcher requests>
PLASMA_FRAMEWORK= <address of the plasma_framework contract>
ERC20_CONTRACT= <*optional* address of the erc20 contract that Alice will deposit and transfer to Bob>
ALICE_ETH_ADDRESS= <address of Alice's account>
ALICE_ETH_ADDRESS_PRIVATE_KEY= <Alice's private key>
ALICE_ETH_DEPOSIT_AMOUNT= <ETH amount Alice will deposit into the childchain>
ALICE_ERC20_DEPOSIT_AMOUNT= <ERC20 amount Alice will deposit into the childchain>
ALICE_ETH_TRANSFER_AMOUNT= <ETH amount Alice will transfer to Bob>
ALICE_ERC20_TRANSFER_AMOUNT= <ERC20 amount Alice will transfer to Bob>
BOB_ETH_ADDRESS= <address of Bob's account>
BOB_ETH_ADDRESS_PRIVATE_KEY= <Bob's private key>
MILLIS_TO_WAIT_FOR_NEXT_BLOCK= <interval when checking for block confirmation>
BLOCKS_TO_WAIT_FOR_TXN= <amount of blocks to wait for confirmation>
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. Bob will then 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.
Helpful Scripts
From the /examples
folder run the following scripts:
Get Alice's and Bob's balances
npm run balances
Get Alice's and Bob's Childchain UTXOs
npm run childchain-utxos
ETH Examples
Deposit some ETH from Alice's Rootchain to the Childchain
npm run childchain-deposit-eth
Send some ETH from Alice's Childchain to Bob's Childchain
npm run childchain-transaction-eth
Alice has now sent some ETH to Bob. This should be reflected in Bob's childchain balance.
Exit one of Bob's Childchain UTXOs to the Rootchain
npm run childchain-exit-eth
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.
Bob starts and piggyback's an inflight exit for his ouput on a transaction sent by Alice
npm run childchain-inflight-exit-eth
ERC20 Examples
Now let's run through the same story above but for ERC20 deposit/transaction/exit.
Deposit some ERC20 from Alice's Rootchain to the Childchain
npm run childchain-deposit-erc20
Send some ERC20 from Alice's Childchain to Bob's Childchain
npm run childchain-transaction-erc20
Exit one of Bob's Childchain ERC20 UTXOs to the Rootchain
npm run childchain-exit-erc20
4 years ago