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.To access network features from your application, use our official libraries:
Node
Browser
React Native
Requires Node >= 8.11.3 < 13.0.0
npm install @omisego/omg-js web3 bn.js
You can add
omg-js
to a website using a script tag:<script src="https://unpkg.com/@omisego/browser-omg-js"></script>
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
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).
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.async function makeEthDeposit () {
const deposit = await rootChain.deposit({
amount: ethDeposit.amount,
currency: OmgUtil.transaction.ETH_CURRENCY,
txOptions: {
from: ethDeposit.address,
privateKey: ethDeposit.privateKey,
gas: gasLimit
}
});
return deposit;
}
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 theamount
value.
A deposit generates a transaction receipt verifiable on Ethereum Network. A typical receipt has the following structure:
{
"blockHash": "0x41455ed19db8e5a495233e54c1813962edaf8a5fb87f847a704c72efa90e2c71",
"blockNumber": 7779244,
"contractAddress": null,
"cumulativeGasUsed": 391297,
"from": "0x0dc8e240d90f3b0d511b6447543b28ea2471401a",
"gasUsed": 130821,
"logs": [
{
"address": "0x895Cc6F20D386f5C0deae08B08cCFeC9f821E7D9",
"topics": [
"0x18569122d84f30025bb8dffb33563f1bdbfb9637f21552b11b8305686e9cb307",
"0x0000000000000000000000000dc8e240d90f3b0d511b6447543b28ea2471401a",
"0x0000000000000000000000000000000000000000000000000000000000023e42",
"0x0000000000000000000000000000000000000000000000000000000000000000"
],
"data": "0x000000000000000000000000000000000000000000000000006a94d74f430000",
"blockNumber": 7779244,
"transactionHash": "0x0e7d060a63cb65f629cc6d053e71397c7fa3250b41e36cb2cae40b2acb4350a2",
"transactionIndex": 12,
"blockHash": "0x41455ed19db8e5a495233e54c1813962edaf8a5fb87f847a704c72efa90e2c71",
"logIndex": 1,
"removed": false,
"id": "log_8b0a6416"
}
],
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000001000000000024000000000000000000800000000000000000000010080000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000004000000010000000000000000000020000000000000000000000000000000000000080000022000000000000000000000",
"status": true,
"to": "0x895cc6f20d386f5c0deae08b08ccfec9f821e7d9",
"transactionHash": "0x0e7d060a63cb65f629cc6d053e71397c7fa3250b41e36cb2cae40b2acb4350a2",
"transactionIndex": 12
}
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.
Depositing ERC20 tokens requires approval of the corresponding
Vault
contract. You can deposit tokens only after this process is finished.async function makeErc20Deposit () {
const approval = await rootChain.approveToken({
erc20Address: erc20Deposit.currency,
amount: erc20Deposit.amount,
txOptions: {
from: erc20Deposit.address,
privateKey: erc20Deposit.privateKey
}
});
const receipt = await rootChain.deposit({
amount: erc20Deposit.amount,
currency: erc20Deposit.currency,
txOptions: {
from: erc20Deposit.address,
privateKey: erc20Deposit.privateKey,
gas: gasLimit
}
});
}
gasLimit
- gas limit for your transaction. Please check the current data on Gas Station or similar resources.
Last modified 2yr ago