Boba Wallet Contracts
Learn how to interface with the Boba wallet contracts to retrieve on-chain data.
For the full documentation on how to interact with the Boba wallet contracts, visit our Github.

1. Get Balances

To retrieve L2 oETH balance:
1
this.provider.getBalance(address).
Copied!
To retrieve ERC20 tokens, use abi from the L2StandardERC20 contracts and run
1
ERC20Contract.balanceOf(address)
Copied!
Refer to the full getBalances documentation below:
1
async getBalances () {
2
3
try {
4
5
const rootChainBalance = await this.L1Provider.getBalance(this.account);
6
const ERC20L1Balance = await this.L1ERC20Contract.connect(this.L1Provider).balanceOf(this.account);
7
8
const childChainBalance = await this.L2Provider.getBalance(this.account);
9
const ERC20L2Balance = await this.L2ERC20Contract.connect(this.L2Provider).balanceOf(this.account);
10
11
// //how many NFTs do I own?
12
const ERC721L2Balance = await this.ERC721Contract.connect(this.L2Provider).balanceOf(this.account);
13
// console.log("ERC721L2Balance",ERC721L2Balance)
14
// console.log("this.account",this.account)
15
// console.log(this.ERC721Contract)
16
17
//let see if we already know about them
18
const myNFTS = getNFTs()
19
const numberOfNFTS = Object.keys(myNFTS).length;
20
21
if(Number(ERC721L2Balance.toString()) !== numberOfNFTS) {
22
23
//oh - something just changed - either got one, or sent one
24
console.log("NFT change detected!")
25
26
//we need to do something
27
//get the first one
28
29
let tokenID = null
30
let nftTokenIDs = null
31
let nftMeta = null
32
let meta = null
33
34
//always the same, no need to have in the loop
35
let nftName = await this.ERC721Contract.getName();
36
let nftSymbol = await this.ERC721Contract.getSymbol();
37
38
for (var i = 0; i < Number(ERC721L2Balance.toString()); i++) {
39
40
tokenID = BigNumber.from(i)
41
nftTokenIDs = await this.ERC721Contract.tokenOfOwnerByIndex(this.account, tokenID);
42
nftMeta = await this.ERC721Contract.getTokenURI(tokenID);
43
meta = nftMeta.split("#")
44
45
const time = new Date(parseInt(meta[1]));
46
47
addNFT({
48
UUID: this.ERC721Address.substring(1, 6) + "_" + nftTokenIDs.toString() + "_" + this.account.substring(1, 6),
49
owner: meta[0],
50
mintedTime: String(time.toLocaleString('en-US', { day: '2-digit', month: '2-digit', year: 'numeric', hour: 'numeric', minute: 'numeric', hour12: true })),
51
url: meta[2],
52
tokenID: tokenID,
53
name: nftName,
54
symbol: nftSymbol
55
})
56
}
57
58
} else {
59
// console.log("No NFT changes")
60
//all set - do nothing
61
}
Copied!

2. Deposit ETH from L1 to Boba L2

1
depositETHL2 = async (value='1') => {
2
3
try {
4
const depositTxStatus = await this.L1StandardBridgeContract.depositETH(
5
this.L2GasLimit,
6
utils.formatBytes32String((new Date().getTime()).toString()),
7
{value: parseEther(value)}
8
);
9
await depositTxStatus.wait();
10
11
const [l1ToL2msgHash] = await this.watcher.getMessageHashesFromL1Tx(depositTxStatus.hash);
12
console.log(' got L1->L2 message hash', l1ToL2msgHash);
13
14
const l2Receipt = await this.watcher.getL2TransactionReceipt(l1ToL2msgHash);
15
console.log(' completed Deposit! L2 tx hash:', l2Receipt.transactionHash);
16
17
this.getBalances();
18
19
return l2Receipt;
20
21
} catch {
22
return false;
23
}
24
}
Copied!

3. Standard exit from Boba L2

1
async exitOMGX(currency, value) {
2
const allowance = await this.checkAllowance(currency, this.L2StandardBridgeAddress);
3
// need the frontend updates
4
if (BigNumber.from(allowance).lt(parseEther(value))) {
5
const res = await this.approveErc20(parseEther(value), currency, this.L2StandardBridgeAddress)
6
if (!res) return false;
7
}
8
const tx = await this.L2StandardBridgeContract.withdraw(
9
currency,
10
parseEther(value),
11
this.L1GasLimit,
12
utils.formatBytes32String((new Date().getTime()).toString()),
13
{ gasPrice: 0 }
14
)
15
await tx.wait();
16
17
const [L2ToL1msgHash] = await this.watcher.getMessageHashesFromL2Tx(tx.hash)
18
console.log(' got L2->L1 message hash', L2ToL1msgHash)
19
20
return tx
21
}
Copied!
Last modified 1mo ago