Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@hukamnonceblox
Created February 15, 2023 06:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hukamnonceblox/67566e9c0da8a12d9cef8911e1cc5024 to your computer and use it in GitHub Desktop.
Save hukamnonceblox/67566e9c0da8a12d9cef8911e1cc5024 to your computer and use it in GitHub Desktop.
matic bridge
const { use } = require("@maticnetwork/maticjs");
const { Web3ClientPlugin } = require("@maticnetwork/maticjs-web3");
const { FxPortalClient } = require("@fxportal/maticjs-fxportal");
async function main() {
use(Web3ClientPlugin);
const fxPortalClient = new FxPortalClient();
//fx client initiate
await fxPortalClient.init({
network: 'testnet',
version: 'mumbai',
parent: {
provider: new HDWalletProvider(privateKey, rootRPC),
defaultConfig: {
from
}
},
child: {
provider: new HDWalletProvider(privateKey, childRPC),
defaultConfig: {
from
}
}
});
let erc20 = fxPortalClient.erc20("<tokenAddress>", "<isRoot>");
//to approve
const approveResult = await erc20.approve("<amount>");
//to deposit
const result = await erc20.deposit("<amount>", "<user address>");
//to start withdraw
const result = await erc20.withdrawStart("<amount>");
const txHash = await result.getTransactionHash();
// withdraw exit
const result = await erc20.withdrawExit("<burn tx hash>");
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment