Deposit Funds
A deposit involves sending ETH or ERC20 tokens to the Vault smart contract on the root chain for subsequent use on the OMG network.

Implementation

1. Install omg-js, web3, bn.js

To access network features from your application, use our official libraries:
Node
Browser
React Native
Requires Node >= 8.11.3 < 13.0.0
1
npm install @omisego/omg-js web3 bn.js
Copied!
You can add omg-js to a website using a script tag:
1
<script src="https://unpkg.com/@omisego/browser-omg-js"></script>
Copied!
You can easily integrate omg-js with React Native projects. First, add this postinstall script to your project's package.json:
1
"scripts": {
2
"postinstall": "omgjs-nodeify"
3
}
Copied!
Then install the react native compatible library:
1
npm install @omisego/react-native-omg-js
Copied!

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:
1
import Web3 from "web3";
2
import { RootChain, OmgUtil } from "@omisego/omg-js";
3
const web3 = new Web3(new Web3.providers.HttpProvider(web3_provider_url));
4
const rootChain = new RootChain({ web3, plasmaContractAddress });
5
6
const ethDeposit = {
7
amount: new BigNumber("100000000000000000"),
8
address: "0x8CB0DE6206f459812525F2BA043b14155C2230C0",
9
privateKey: OmgUtil.hexPrefix("CD55F2A7C476306B27315C7986BC50BD81DB4130D4B5CFD49E3EAF9ED1EDE4F7")
10
}
11
const erc20Deposit = {
12
amount: new BigNumber("50000000"),
13
currency: OmgUtil.hexPrefix("0xd92e713d051c37ebb2561803a3b5fbabc4962431"),
14
address: "0x8CB0DE6206f459812525F2BA043b14155C2230C0",
15
privateKey: OmgUtil.hexPrefix("CD55F2A7C476306B27315C7986BC50BD81DB4130D4B5CFD49E3EAF9ED1EDE4F7")
16
}
Copied!
    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.
1
async function makeEthDeposit () {
2
const deposit = await rootChain.deposit({
3
amount: ethDeposit.amount,
4
currency: OmgUtil.transaction.ETH_CURRENCY,
5
txOptions: {
6
from: ethDeposit.address,
7
privateKey: ethDeposit.privateKey,
8
gas: gasLimit
9
}
10
});
11
return deposit;
12
}
Copied!
    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:
1
{
2
"blockHash": "0x41455ed19db8e5a495233e54c1813962edaf8a5fb87f847a704c72efa90e2c71",
3
"blockNumber": 7779244,
4
"contractAddress": null,
5
"cumulativeGasUsed": 391297,
6
"from": "0x0dc8e240d90f3b0d511b6447543b28ea2471401a",
7
"gasUsed": 130821,
8
"logs": [
9
{
10
"address": "0x895Cc6F20D386f5C0deae08B08cCFeC9f821E7D9",
11
"topics": [
12
"0x18569122d84f30025bb8dffb33563f1bdbfb9637f21552b11b8305686e9cb307",
13
"0x0000000000000000000000000dc8e240d90f3b0d511b6447543b28ea2471401a",
14
"0x0000000000000000000000000000000000000000000000000000000000023e42",
15
"0x0000000000000000000000000000000000000000000000000000000000000000"
16
],
17
"data": "0x000000000000000000000000000000000000000000000000006a94d74f430000",
18
"blockNumber": 7779244,
19
"transactionHash": "0x0e7d060a63cb65f629cc6d053e71397c7fa3250b41e36cb2cae40b2acb4350a2",
20
"transactionIndex": 12,
21
"blockHash": "0x41455ed19db8e5a495233e54c1813962edaf8a5fb87f847a704c72efa90e2c71",
22
"logIndex": 1,
23
"removed": false,
24
"id": "log_8b0a6416"
25
}
26
],
27
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000001000000000024000000000000000000800000000000000000000010080000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000004000000010000000000000000000020000000000000000000000000000000000000080000022000000000000000000000",
28
"status": true,
29
"to": "0x895cc6f20d386f5c0deae08b08ccfec9f821e7d9",
30
"transactionHash": "0x0e7d060a63cb65f629cc6d053e71397c7fa3250b41e36cb2cae40b2acb4350a2",
31
"transactionIndex": 12
32
}
Copied!
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.
1
async function makeErc20Deposit () {
2
3
const approval = await rootChain.approveToken({
4
erc20Address: erc20Deposit.currency,
5
amount: erc20Deposit.amount,
6
txOptions: {
7
from: erc20Deposit.address,
8
privateKey: erc20Deposit.privateKey
9
}
10
});
11
const receipt = await rootChain.deposit({
12
amount: erc20Deposit.amount,
13
currency: erc20Deposit.currency,
14
txOptions: {
15
from: erc20Deposit.address,
16
privateKey: erc20Deposit.privateKey,
17
gas: gasLimit
18
}
19
});
20
}
Copied!
    gasLimit - gas limit for your transaction. Please check the current data on Gas Station or similar resources.
Last modified 8mo ago