Skip to content

POS client


Make sure you have followed the installation and get started documentation.

The POSClient interacts with the POS bridge.

import { POSClient,use } from "@maticnetwork/maticjs"
import { Web3ClientPlugin } from '@maticnetwork/maticjs-web3'
import HDWalletProvider from "@truffle/hdwallet-provider"

// install web3 plugin

const posClient = new POSClient();
await posClient.init({
    network: 'testnet',
    version: 'mumbai',
    parent: {
      provider: new HDWalletProvider(privateKey, mainRPC),
      defaultConfig: {
        from : fromAddress
    child: {
      provider: new HDWalletProvider(privateKey, childRPC),
      defaultConfig: {
        from : fromAddress

After the POSClient is initiated, we can work with token types, such as erc20, erc721 etc.


Create erc20 child token

const erc20ChildToken = posClient.erc20(<token address>);

Create erc20 parent token

const erc20ParentToken = posClient.erc20(<token address>, true);

Once erc20 is initaited, you can call various methods that are available, like - getBalance, approve, deposit , withdraw etc.


const balance = await erc20ChildToken.getBalance(<userAddress>)
console.log('balance', balance)


// approve amount 10 on parent token
const approveResult = await erc20ParentToken.approve(10);

// get transaction hash
const txHash = await approveResult.getTransactionHash();

// get transaction receipt
const txReceipt = await approveResult.getReceipt();

As you can see, with its simple APIs maticjs makes it very easy to interact with maticjs bridge.

Once the POSClient is initiated, you can interact with all available APIs.

Last update: December 19, 2023
Authors: kmurphypolygon