Getting started with the Matic SDK

Installation

The easiest way to consume the SDK is via NPM. To install it in your project run

npm install @maticnetwork/maticjs

Usage

To access the SDK, import it in your application using

const MaticPOSClient = require('@maticnetwork/maticjs').MaticPOSClient
// or
import { MaticPOSClient } from '@maticnetwork/maticjs'

The providers can be RPC urls or web3 based providers like Metamask provider, HDWalletProvider etc. based on requirement.

const parentProvider = 'https://mainnet.infura.io/v3/<infura-key>'
const maticProvider = '<Sign up for a free RPC link at https://rpc.maticvigil.com/>'

Instantiate the client by passing network details and providers based on the network you are integrating.

// for mumbai testnet
const maticPOSClient = new MaticPOSClient({
network: "testnet",
version: "mumbai",
parentProvider: <goerli-provider>,
maticProvider: <mumbai-provider>
});
// for Matic mainnet
const maticPOSClient = new MaticPOSClient({
network: "mainnet",
version: "v1",
parentProvider: <ethereun-provider>,
maticProvider: <matic-provider>
});

More details can be provided if you want to override the default values.

const maticPOSClient = new MaticPOSClient({
network: "testnet",
version: "mumbai",
parentProvider: <goerli-provider>,
maticProvider: <mumbai-provider>,
rootChain: <plasma-root-chain-address>,
posRootChainManager: <pos-root-chain-manager-address>,
posERC20Predicate: <pos-erc20-predicate-address>,
posERC721Predicate: <pos-erc721-predicate-address>,
posERC1155Predicate: <pos-erc1155-predicate-address>,
parentDefaultOptions: { from: <user-address> },
maticDefaultOptions: { from: <user-address> },
});