FxPortal bridge plugin for maticjs. It provides FxPortalClient to interact with fxportal bridge.
npm i @fxportal/maticjs-fxportal
Currently matic.js
support two ethers library -
npm i @maticnetwork/maticjs-web3
npm i @maticnetwork/maticjs-ethers
const { use } = require("@maticnetwork/maticjs");
const { Web3ClientPlugin } = require("@maticnetwork/maticjs-web3");
const { FxPortalClient } = require("@fxportal/maticjs-fxportal");
const HDWalletProvider = require("@truffle/hdwallet-provider");
// add Web3Plugin
use(Web3ClientPlugin);
const fxPortalClient = new FxPortalClient();
await fxPortalClient.init({
network: 'testnet',
version: 'mumbai',
parent: {
provider: new HDWalletProvider(privateKey, rootRPC),
defaultConfig: {
from
}
},
child: {
provider: new HDWalletProvider(privateKey, childRPC),
defaultConfig: {
from
}
}
});
Method erc20
allows you to interact with erc20 token.
const erc20 = fxPortalClient.erc20(<tokenAddress>, <isRoot>);
Get balance of a user by supplying user address
const balance = await erc20.getBalance(<user address>);
Get name of token
const name = await erc20.getName();
Get decimals of token
const decimals = await erc20.getDecimals();
Get symbol of token
const decimals = await erc20.getSymbol();
Approve required amount for depositing to polygon chain
const approveResult = await erc20.approve(<amount>);
const txHash = await approveResult.getTransactionHash();
const receipt = await approveResult.getReceipt();
Approve max amount for depositing to polygon chain
const approveResult = await erc20.approveMax();
const txHash = await approveResult.getTransactionHash();
const receipt = await approveResult.getReceipt();
Get approve amount of a user by supplying user address
const balance = await erc20.getAllowance(<user address>);
Deposit required amount from ethereum to polygon
const result = await erc20.deposit(<amount>, <user address>);
const txHash = await result.getTransactionHash();
const receipt = await result.getReceipt();
Initiate withdraw process by burning the required amount.
const result = await erc20.withdrawStart(<amount>);
const txHash = await result.getTransactionHash();
const receipt = await result.getReceipt();
Initiate withdrawTo process by burning the required amount.
const result = await erc20.withdrawToStart(<amount>, <to address>);
const txHash = await result.getTransactionHash();
const receipt = await result.getReceipt();
Exit withdraw process by providng txHash received in withdrawStart
process.
Note:- withdrawExit
can be called after checkpoint has been submitted for withdrawStart
.
const result = await erc20.withdrawExit(<burn tx hash>);
const txHash = await result.getTransactionHash();
const receipt = await result.getReceipt();
Faster exit withdraw process by providng txHash received in withdrawStart
process.
It is faster because it uses api to create the proof.
const result = await erc20.withdrawExitFaster(<burn tx hash>);
const txHash = await result.getTransactionHash();
const receipt = await result.getReceipt();
Check if transaction has been checkpointed or not.
await fxPortalClient.isCheckPointed(<tx hash>);
Check if withdraw process has been completed by supplying burn transaction hash.
const balance = await erc20.isExited(<burn tx hash>);
Check if deposit is completed.
const balance = await erc20.isDeposited(<tx hash>);