Getting started with the Polygon SDK

Quick Summary

The matic.js SDK takes all the computing power of Polygon and places it right at your finger tip. With custom-made functions that allow for approval, deposit and withdrawals, all without doing too much footwork. Our reason for engineering this was to ensure you get instant value from our platform.

Installation

The first step to using the awesome power of Polygon via our SDK is by doing an NPM install of it. Find here.

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 Polygon mainnet
const maticPOSClient = new MaticPOSClient({
network: "mainnet",
version: "v1",
parentProvider: <ethereum-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> },
});
Last updated on