Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/0xpolygon/maticjs-fxportal
Library for interacting with fx-portal bridge.
https://github.com/0xpolygon/maticjs-fxportal
fxportal matic polygon
Last synced: about 2 months ago
JSON representation
Library for interacting with fx-portal bridge.
- Host: GitHub
- URL: https://github.com/0xpolygon/maticjs-fxportal
- Owner: 0xPolygon
- Created: 2021-08-24T05:59:25.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-12-11T01:20:41.000Z (about 2 years ago)
- Last Synced: 2024-11-01T12:05:43.842Z (2 months ago)
- Topics: fxportal, matic, polygon
- Language: TypeScript
- Homepage:
- Size: 1.09 MB
- Stars: 23
- Watchers: 7
- Forks: 8
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[![TEST](https://github.com/fx-portal/maticjs-fxportal/actions/workflows/test.yml/badge.svg)](https://github.com/fx-portal/maticjs-fxportal/actions/workflows/test.yml)
[![npm version](https://badge.fury.io/js/@fxportal%2Fmaticjs-fxportal.svg)](https://badge.fury.io/js/@fxportal%2Fmaticjs-fxportal)
# maticjs-fxportalFxPortal bridge plugin for maticjs. It provides FxPortalClient to interact with fxportal bridge.
# Installation
```
npm i @fxportal/maticjs-fxportal
```## Install ethers library
Currently `matic.js` support two ethers library -
### 1. web3.js
```
npm i @maticnetwork/maticjs-web3
```### 2. Ethers
```
npm i @maticnetwork/maticjs-ethers
```# DOCS
## Initiate client
```
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
}
}
});```
## ERC20
Method `erc20` allows you to interact with erc20 token.
```
const erc20 = fxPortalClient.erc20(, );
```### getBalance
Get balance of a user by supplying user address
```
const balance = await erc20.getBalance();
```
### getNameGet name of token
```
const name = await erc20.getName();
```
### getDecimalsGet decimals of token
```
const decimals = await erc20.getDecimals();
```
### getSymbolGet symbol of token
```
const decimals = await erc20.getSymbol();
```### approve
Approve required amount for depositing to polygon chain
```
const approveResult = await erc20.approve();
const txHash = await approveResult.getTransactionHash();
const receipt = await approveResult.getReceipt();
```### approveMax
Approve max amount for depositing to polygon chain
```
const approveResult = await erc20.approveMax();
const txHash = await approveResult.getTransactionHash();
const receipt = await approveResult.getReceipt();
```### getAllowance
Get approve amount of a user by supplying user address
```
const balance = await erc20.getAllowance();
```### deposit
Deposit required amount from ethereum to polygon
```
const result = await erc20.deposit(, );
const txHash = await result.getTransactionHash();
const receipt = await result.getReceipt();
```### withdrawStart
Initiate withdraw process by burning the required amount.
```
const result = await erc20.withdrawStart();
const txHash = await result.getTransactionHash();
const receipt = await result.getReceipt();
```
### withdrawToStartInitiate withdrawTo process by burning the required amount.
```
const result = await erc20.withdrawToStart(, );
const txHash = await result.getTransactionHash();
const receipt = await result.getReceipt();
```
### withdrawExitExit 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();
const txHash = await result.getTransactionHash();
const receipt = await result.getReceipt();
```
### withdrawExitFasterFaster 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();
const txHash = await result.getTransactionHash();
const receipt = await result.getReceipt();
```## isCheckPointed
Check if transaction has been checkpointed or not.
```
await fxPortalClient.isCheckPointed();
```## isWithdrawExited
Check if withdraw process has been completed by supplying burn transaction hash.
```
const balance = await erc20.isExited();
```## isDeposited
Check if deposit is completed.
```
const balance = await erc20.isDeposited();
```