Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@maticnetwork/fx-portal

Package Overview
Dependencies
Maintainers
6
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@maticnetwork/fx-portal - npm Package Compare versions

Comparing version 1.0.0-beta.1 to 1.0.4

config/config.json

61

package.json
{
"name": "@maticnetwork/fx-portal",
"version": "1.0.0-beta.1",
"description": "",
"main": "dist/npm.export.js",
"types": "dist/ts/index.d.ts",
"version": "1.0.4",
"description": "FxPortal for Polygon chain. No mapping. Seamless.",
"main": "index.js",
"scripts": {
"un:matic": "npm un @maticnetwork/maticjs",
"install:matic": "npm i ../matic.js/maticnetwork-maticjs-2.0.45.tgz -D",
"link:maticjs": "npm link @maticnetwork/maticjs",
"build": "npm run build:dev",
"build:link": "npm run build && npm link",
"build:webpack": "npm run lint && webpack --config webpack/webpack.node.config.js",
"build:pack": "npm run build:dev && npm pack",
"build:dev": "cross-env NODE_ENV=development npm run build:webpack",
"build:prod": "cross-env NODE_ENV=production npm run build:webpack",
"deploy": "npm run build:dev && npm run build:prod",
"prepublishOnly": "npm run deploy",
"lint": "tslint src/**/*.ts",
"lint:fix": "tslint src/**/*.ts --fix",
"test": "npm run build:pack && cd test && npm run install:lib:test",
"debug": "npm run build:pack && cd test && npm run install:lib:debug"
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/maticnetwork/fx-portal.js.git"
"url": "git+https://github.com/fx-portal/contracts.git"
},
"author": "",
"license": "ISC",
"keywords": [
"ethereum",
"matic"
],
"author": "Jaynti Kanani <jdkanani@gmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/maticnetwork/fx-portal.js/issues"
"url": "https://github.com/fx-portal/contracts/issues"
},
"homepage": "https://github.com/maticnetwork/fx-portal.js#readme",
"homepage": "https://github.com/fx-portal/contracts#readme",
"devDependencies": {
"@nomiclabs/hardhat-ethers": "^2.0.1",
"@nomiclabs/hardhat-etherscan": "^2.1.6",
"@nomiclabs/hardhat-waffle": "^2.0.1",
"chai": "^4.2.0",
"dotenv": "^8.2.0",
"ethereum-waffle": "^3.2.1",
"ethers": "^5.0.24",
"hardhat": "^2.0.7"
},
"dependencies": {
"@maticnetwork/maticjs": "^3.0.0-beta.2"
},
"devDependencies": {
"copy-webpack-plugin": "^6.1.1",
"cross-env": "^7.0.3",
"dotenv": "^10.0.0",
"ts-loader": "^7.0.1",
"tslint": "^6.1.3",
"typescript": "^3.8.3",
"web3": "^1.5.0",
"webpack": "^4.43.0",
"webpack-cli": "^4.2.0",
"webpack-merge": "^4.2.2"
"@openzeppelin/contracts": "^4.2.0"
}
}

@@ -1,150 +0,56 @@

# fx-portal.js
# fx-portal(Flexible portal)
Library for interacting with fx-portal bridge.
FxPortal for Polygon(prev Matic)Chain. No mapping. Seamless communication with Ethereum Network.
> fx-portal is plugin for maticjs.
Audit - [Fx-Portal Contracts Audit by Halborn](https://github.com/fx-portal/contracts/blob/main/Polygon_FX_Portal_Smart_Contract_Security_Audit_Halborn_v1_0%20(1).pdf)
# Installation
### What is Fx bridge (fx-portal)?
```
npm i @maticnetwork/fx-portal
```
**It is a powerful yet simple implementation Polygon [state sync](https://docs.matic.network/docs/contribute/state-sync) mechanism. Polygon PoS bridge is based on it. The code in the `examples` folder are examples of the usage of this methodology. You can use these examples to build your own implementations or own custom bridge.**
# DOCS
In short, it's Meta bridge. This bridge allows any state-syncs without mapping.
## Initiate client
#### Some use-cases of Fx-portal
```
const { use } = require("@maticnetwork/maticjs");
const { FxPortalPlugin, FxPortalClient } = require("@maticnetwork/fx-portal");
* [ERC20 token tranfer from Ethereum to Matic-Chain without mapping request](https://github.com/jdkanani/fx-portal/tree/main/contracts/examples/erc20-transfer)
* [Lazy minting of ERC20 tokens on MaticChain](https://github.com/jdkanani/fx-portal/tree/main/contracts/examples/mintable-erc20-transfer)
* [State Transfer between Ethereum-Matic](https://github.com/jdkanani/fx-portal/tree/main/contracts/examples/state-transfer)
const HDWalletProvider = require("@truffle/hdwallet-provider");
**What about [PoS portal](https://docs.matic.network/docs/develop/ethereum-matic/pos/getting-started)?**
// add FxPortal Plugin into maticjs
use(FxPortalPlugin);
PoS Portal is another bridge, but it works only for few ERC standards and requires mappings. It is more developer-friendly, allows customization without much headache.
const fxPortalClient = new FxPortalClient({
network: 'testnet',
version: 'mumbai',
parent: {
provider: new HDWalletProvider(privateKey, rootRPC),
defaultConfig: {
from
}
},
child: {
provider: new HDWalletProvider(privateKey, childRPC),
defaultConfig: {
from
}
}
});
While Fx-portal focuses on permissionless-ness and flexibility, a developer might have to write more code but more customizable than PoS Portal. It requires no mapping.
await fxPortalClient.init();
**Can I build my bridge?**
```
Yes. You can check docs here: https://docs.matic.network/docs/develop/l1-l2-communication/ethereum-to-matic
https://docs.matic.network/docs/develop/l1-l2-communication/matic-to-ethereum
## ERC20
### What are FxChild and FxRoot?
Method `erc20` allows you to interact with erc20 token.
`FxChild` (FxChild.sol) and `FxRoot` (FxRoot.sol) are main contracts on which mapping-less bridge works. It calls and passes data to user-defined methods on another chain without mapping.
```
const erc20 = fxPortalClient.erc20(<tokenAddress>, <isRoot>);
```
**Mumbai**
### getBalance
| Contract | Deployed address |
| :----- | :- |
| [FxRoot (Goerli)](https://goerli.etherscan.io/address/0x3d1d3E34f7fB6D26245E6640E1c50710eFFf15bA#code) | `0x3d1d3E34f7fB6D26245E6640E1c50710eFFf15bA` |
| [FxChild (Mumbai)](https://explorer-mumbai.maticvigil.com/address/0xCf73231F28B7331BBe3124B907840A94851f9f11/contracts) | `0xCf73231F28B7331BBe3124B907840A94851f9f11`|
Get balance of a user by supplying user address
**Mainnet**
```
const balance = await erc20.getBalance(<user address>);
```
### approve
| Contract | Deployed address |
| :----- | :- |
| [FxRoot (Ethereum Mainnet)](https://etherscan.io/address/0xfe5e5d361b2ad62c541bab87c45a0b9b018389a2#code) | `0xfe5e5D361b2ad62c541bAb87C45a0B9B018389a2` |
| [FxChild (Matic Mainnnet)](https://explorer-mainnet.maticvigil.com/address/0x8397259c983751DAf40400790063935a11afa28a/contracts) | `0x8397259c983751DAf40400790063935a11afa28a`|
Approve required amount for depositing to polygon chain
```
const approveResult = await erc20.approve(<amount>);
const txHash = await approveResult.getTransactionHash();
const receipt = await approveResult.getReceipt();
```
You can deploy your own `FxChild` and `FxRoot`, but no need. Except you want to have some fun and have extra ETH to throw away.
## approveMax
### What can I build with it?
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(<user address>);
```
## deposit
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();
```
## withdrawStart
Initiate withdraw process by burning the required amount.
```
const result = await erc20.withdrawStart(<amount>);
const txHash = await result.getTransactionHash();
const receipt = await result.getReceipt();
```
## isCheckPointed
Check if transaction has been checkpointed or not.
```
await fxPortalClient.isCheckPointed(<tx hash>);
```
## withdrawExit
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();
```
## isWithdrawExited
Check if withdraw process has been completed by supplying burn transaction hash.
```
const balance = await erc20.isExited(<burn tx hash>);
```
## withdrawExitFaster
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();
```
* Arbitrary state bridge (examples/state-transfer)
* Normal ERC20 bridge (examples/erc2-transfer)
* ERC20 token generator bridge (example/mintable-erc20-transfer)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc