Skip to main content

Installation & Setup

Connext consists of two integration touchpoints:

  1. The onchain connext contracts
  2. The offchain connext SDK

A contract integration is only needed if you want to initiate a transaction directly from another contract (guide coming soon!). For anything else, the Connext sdk neatly wraps all functionality for the developer.

Installing the SDK#

The SDK is distributed as a typescript package on npm. It is fully isomorphic (can be used the same way in client-side, server-side, and React Native environments).

yarn install @connext/nxtp-sdk

Initializing the SDK#

The constructor accepts the following arguments, in order:

  • config: Required. Object with chainConfig, signer and other optional parameters.
    • chainConfig: Required. Object with chainId as a key, and the following object keys/values. Provide all the chains you intend to support in this argument:
      • provider: Required. Ethers FallbackProvider. Providers are instantiated using Alchemy, Infura, or local nodes. FallbackProvider is used to provide redunancy from faulty providers.
      • subgraph: Optional. Override the subgraph for the specified chain. Most chains will have default subgraph endpoints, you will get an error on instantiation if not.
    • signer: Required. An Ethers-compatible Signer which is instantiated with a private key or injected provider (Metamask).
  • logger: Optional. An instance of a Pino logger. If not provided, one will be created.

A basic example:

import { providers, Wallet, utils } from "ethers";import { NxtpSdkEvents, NxtpSdk } from "@connext/nxtp-sdk";
// Set up provider to chain mappingsconst chainConfig = {  4: {    provider: new providers.FallbackProvider([      new providers.JsonRpcProvider("https://rinkeby.infura.io/..."),    ]),  },  5: {    provider: new providers.FallbackProvider([      new providers.JsonRpcProvider("https://goerli.infura.io/..."),    ]),  },};
// Get signer from metamaskawait ethereum.request({ method: "eth_requestAccounts" });const provider = new providers.Web3Provider(ethereum);const _signer = provider.getSigner();
// Instantiate SDKconst sdk = new NxtpSdk({chainConfig: chainProviders, signer: _signer});