You can easily integrate omg-js with React Native projects. First, add this postinstall script to your project's package.json:
"scripts": {
"postinstall": "omgjs-nodeify"
}
Then install the react native compatible library:
npm install @omisego/react-native-omg-js
2. Import dependencies, define constants
Depositing funds to the OMG Network involves using 2 omg-js objects. Here's an example of how to instantiate them:
import Web3 from "web3";
import { RootChain, OmgUtil } from "@omisego/omg-js";
const web3 = new Web3(new Web3.providers.HttpProvider(web3_provider_url));
const rootChain = new RootChain({ web3, plasmaContractAddress });
const ethDeposit = {
amount: new BigNumber("100000000000000000"),
address: "0x8CB0DE6206f459812525F2BA043b14155C2230C0",
privateKey: OmgUtil.hexPrefix("CD55F2A7C476306B27315C7986BC50BD81DB4130D4B5CFD49E3EAF9ED1EDE4F7")
}
const erc20Deposit = {
amount: new BigNumber("50000000"),
currency: OmgUtil.hexPrefix("0xd92e713d051c37ebb2561803a3b5fbabc4962431"),
address: "0x8CB0DE6206f459812525F2BA043b14155C2230C0",
privateKey: OmgUtil.hexPrefix("CD55F2A7C476306B27315C7986BC50BD81DB4130D4B5CFD49E3EAF9ED1EDE4F7")
}
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.
3. Make an ETH deposit
Performing any operation on the OMG Network requires funds. Fund deposits happen when a user sends ETH or ERC20 tokens to the Vault smart contract on Ethereum Network. A vault holds custody of tokens transferred to the Plasma Framework. Deposits increase the pool of funds held by the contract and also signals to the Childchain server that the funds should be accessible on the Childchain.
gasLimit - gas limit for your transaction. Please check the current data on Gas Station or similar resources.
Deposit amount is defined in WEI, the smallest denomination of ether (ETH), the currency used on Ethereum. You can use an ETH converter or an alternative tool to know how much WEI you have to put as the amount value.
A deposit generates a transaction receipt verifiable on Ethereum Network. A typical receipt has the following structure:
After the funds are confirmed on the rootchain, the Childchain server generates a transaction in a form of UTXO corresponding to the deposited amount. UTXO (unspent transaction output) is a model used to keep a track of balances on the OMG Network.
If a transaction is successful, you will see a unique transactionHash that can be verified on Ethereum block explorer, such as Etherscan. Copy the hash and paste it in the search box for the transaction's details.
Depositing also involves forming a pseudo-block on the Childchain. The block contains a single transaction with the deposited funds as a new UTXO. You can check a new block on the OMG Block Explorer.
4. Make an ERC20 deposit
Depositing ERC20 tokens requires approval of the corresponding Vault contract. You can deposit tokens only after this process is finished.