Installation & Setup
Connext consists of two integration touchpoints:
- The onchain connext contracts
- 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
- NPM
yarn install @connext/nxtp-sdknpm install @connext/nxtp-sdkInitializing the SDK#
The constructor accepts the following arguments, in order:
config: Required. Object with chainConfig, signer and other optional parameters.chainConfig: Required. Object withchainIdas 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.FallbackProvideris 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:
- Typescript
import { providers, Wallet, utils } from "ethers";import { NxtpSdkEvents, NxtpSdk } from "@connext/nxtp-sdk";
// Set up provider to chain mappingsconst chainConfig = { 4: { providers: new providers.FallbackProvider(["https://rinkeby.infura.io/..."]), }, 5: { providers: new providers.FallbackProvider(["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 = await NxtpSdk.create({chainConfig: chainProviders, signer: _signer});