Bridge SDK
The quickest & simplest way to access cross-chain liquidity
The Synapse SDK is the easiest way for any developer to integrate cross-chain token & liquidity transfers into their application. The SDK is built to support full-fledged frontend applications, but is fully isomorphic, able to be used both client & server-side.

Quick Start

Installation

Pre-reqs: Node v16+. The SDK is only fully tested on Node 16+ or greater. Earlier versions may have errors.
Depending on the package manager of your choice, install the SDK using one of the following:
NPM
Yarn
1
npm install @synapseprotocol/sdk --save
Copied!
1
yarn add @synapseprotocol/sdk
Copied!
The SDK package relies on the following dependencies installed from NPM.
1
@ethersproject
2
ethers
Copied!

Initialization & Bridge Quote

To get started, here's a basic example of initialization of the SDK and a cross-chain swap quote being loaded:
1
import {
2
Bridge,
3
Tokens,
4
ChainId,
5
Networks,
6
swappableTokens,
7
NetworkSwappableTokensMap
8
} from "@synapseprotocol/sdk";
9
10
import {JsonRpcProvider} from "@ethersproject/providers";
11
import {ContractTransaction, PopulatedTransaction} from "@ethersproject/contracts";
12
import {parseUnits, formatUnits} from "@ethersproject/units";
13
import {BigNumber} from "@ethersproject/bignumber";
14
15
// Initialize dummy Ethers Provider
16
const AVAX_PROVIDER = new JsonRpcProvider("https://api.avax.network/ext/bc/C/rpc");
17
// Use SDK Data about different chains
18
const AVAX_NETWORK = Networks.AVALANCHE;
19
20
// Initialize Bridge
21
const SYNAPSE_BRIDGE = new Bridge.SynapseBridge({
22
network: AVAX_NETWORK,
23
provider: AVAX_PROVIDER
24
});
25
26
// Set up some variables to prepare a Avalanche USDC -> BSC USDT quote
27
const
28
TOKEN_IN = Tokens.USDC,
29
TOKEN_OUT = Tokens.USDT,
30
CHAIN_OUT = ChainId.BSC,
31
INPUT_AMOUNT: BigNumber = parseUnits("1000", tokenIn.decimals(NETWORK.chainId));
32
33
34
SYNAPSE_BRIDGE.estimateBridgeTokenOutput({
35
tokenFrom: TOKEN_IN, // token to send from the source chain, in this case USDT on Avalanche
36
chainIdTo: CHAIN_OUT, // Chain ID of the destination chain, in this case BSC
37
tokenTo: TOKEN_OUT, // Token to be received on the destination chain, in this case USDC
38
amountFrom: INPUT_AMOUNT,
39
}).then(({ amountToReceive, bridgeFee }) => {
40
let amountOutFormatted = formatUnits(
41
amountToReceive,
42
TOKEN_OUT.decimals(chainOut)
43
);
44
console.log(`${amountOutFormatted} USDT will be received on the output chain`)
45
})
46
.catch((err) => throw new Error(err.toString()))
Copied!
From here, this quote can be used to execute cross-chain transactions seamlessly.

Additional Examples & Transaction Submission

SDK API Reference

Now that you've seen what basic integration looks like, dive into the specifics of the SDK in our complete documentation