LxLy SDK
This repository contains the lxlyjs
client library. lxlyjs
makes it easy for developers, who may not be deeply familiar with smart contract development, to interact with the various components of Polygon LxLy Aggregator bridge.
This library will help developers to move assets between Ethereum chain and Polygon CDK chains.
Installation
You can install the package using NPM
Using NPM
npm install @maticnetwork/lxlyjs
Usage
Import lxly.js module
const { LxLyClient, use } = require("@maticnetwork/lxlyjs");
const { Web3ClientPlugin } = require("@maticnetwork/maticjs-web3");
use(Web3ClientPlugin);
const { LxLyClient, use } = require("@maticnetwork/lxlyjs");
const { Web3ClientPlugin } = require("@maticnetwork/maticjs-ethers");
use(Web3ClientPlugin);
Client Initialization
const client = new LxLyClient();
await client.init({
log: true,
network: "mainnet",
providers: {
0: {
provider:
configuration: {
bridgeAddress:
wrapperAddress:
isEIP1559Supported: true
},
defaultConfig: {
from
}
},
1: {
provider:
configuration: {
bridgeAddress:
wrapperAddress:
isEIP1559Supported: false
},
defaultConfig: {
from
}
}
}
});
Configuration details can be found here for Mainnet and Testnet
Custom Network
Custom networks can also be integrated into the client.
It's worth noting that the lxly.js library might not inherently support the merkle-proof API for custom networks. To address this, users can provide a custom Proof API by utilizing the setProofApi
function call. This allows for seamless integration and support of merkle-proof functionalities within the custom network setup. Further details on the format for Proof Generation API can be found here.
const { LxLyClient, use, setProofApi } = require("@maticnetwork/lxlyjs");
const client = new LxLyClient();
await client.init({
log: true,
network: "mainnet",
providers: {
<CustomNetworkId>: {
provider:
configuration: {
bridgeAddress:
wrapperAddress:
isEIP1559Supported:
},
defaultConfig: {
from
}
}
}
});
setProofApi(url)
ERC20 Token initialization
const erc20 = new client.erc20(tokenAddress, networkId);
const balance = erc20.getBalance(address);
Custom Contracts
const customContract = new client.contract(abi, tokenAddress, networkId);
await customContract.read(methodName, ...args);
await customContract.write(transactionOptions = {}, methodName, ...args);
For the complete function implementation, please refer to the example here or codebase available here.
Support
Our Discord is the best way to reach us ✨.
Contributors
You are very welcome to contribute, please see contributing guidelines - [Contribute].
Thank you to all the people who already contributed to lxly.js!
Made with contributors-img.
Development
Setup
npm ci
How to debug
Write your code inside file test/debug_web3.js
and run below code
npm run debug
Above command will build the source code & install the built version into test folder, which will be used by debug_web3.js
.
Lint
npm run lint
npm run lint:fix
Build code
npm run build
Generate distribution files
npm run deploy
NPM publish
Before running publish script, make sure you have updated version properly.
Note that prepublishOnly
script will be automatically called while publishing. It will check lint, clean dist/lib folders and build fresh distribution files before it executes npm publish
.
npm publish
License
MIT