Skip to main content

Class: SdkBase

Classdesc

SDK class encapsulating bridge functions.

Hierarchy

Methods

approveIfNeeded

approveIfNeeded(domainId, assetId, amount, infiniteApprove?): Promise<undefined | TransactionRequest>

Returns the transaction request for an allowance approval.

Parameters

NameTypeDefault valueDescription
domainIdstringundefinedThe domain ID.
assetIdstringundefinedThe address of the token.
amountstringundefinedThe amount of the token.
infiniteApprovebooleantrue(optional) Whether to approve an infinite amount.

Returns

Promise<undefined | TransactionRequest>

providers.TransactionRequest object.

Inherited from

SdkShared.approveIfNeeded


bumpTransfer

bumpTransfer(params): Promise<TransactionRequest>

Increases the relayer fee for a specific transfer on origin; anyone is allowed to bump for any transfer.

Example

// call SdkBase.create(), instantiate a signer

const params = {
domainId: "6648936",
transferId: "0xdd252f58a45dc78fee1ac12a628782bda6a98315b286aadf76e4d7322bf135ca",
relayerFee: "10000",
};

const txRequest = sdkBase.bumpTransfer(params);
signer.sendTransaction(txRequest);

Parameters

NameTypeDescription
paramsObjectSdkBumpTransferParams object.
params.domainIdstringThe origin domain ID of the transfer.
params.relayerFeestringThe additional relayer fee to increase the transfer by, in native gas token.
params.transferIdstringThe transfer ID.

Returns

Promise<TransactionRequest>

providers.TransactionRequest object.


calculateAmountReceived

calculateAmountReceived(originDomain, destinationDomain, originTokenAddress, amount, receiveLocal?): Promise<{ amountReceived: BigNumberish ; destinationSlippage: BigNumberish ; originSlippage: BigNumberish ; routerFee: BigNumberish }>

Calculates the estimated amount received on the destination domain for a bridge transaction.

Parameters

NameTypeDefault valueDescription
originDomainstringundefinedThe domain ID of the origin chain.
destinationDomainstringundefinedThe domain ID of the destination chain.
originTokenAddressstringundefinedThe address of the token to be bridged from origin.
amountBigNumberishundefinedThe amount of the origin token to bridge, in the origin token's native decimal precision.
receiveLocalbooleanfalse(optional) Whether the desired destination token is the local asset ("nextAsset").

Returns

Promise<{ amountReceived: BigNumberish ; destinationSlippage: BigNumberish ; originSlippage: BigNumberish ; routerFee: BigNumberish }>

Estimated amount received for local/adopted assets, if applicable, in their native decimal precisions.


calculateCanonicalKey

calculateCanonicalKey(domainId, canonicalId): string

Returns the hash of the canonical ID + canonical domain.

Remarks

This key is used as the unique identifier for a canonical token, across all domains.

Parameters

NameTypeDescription
domainIdstringThe canonical domain ID of the token.
canonicalIdstringThe canonical ID of the token.

Returns

string

Inherited from

SdkShared.calculateCanonicalKey


changeSignerAddress

changeSignerAddress(signerAddress): Promise<void>

Switches the signer address in the SDK config.

Parameters

NameTypeDescription
signerAddressstringThe new signer address.

Returns

Promise<void>

Inherited from

SdkShared.changeSignerAddress


estimateRelayerFee

estimateRelayerFee(params): Promise<BigNumber>

Calculates an estimated relayer fee in the native asset of the origin domain to be used in xcall.

Example

// call SdkBase.create(), instantiate a signer

const params = {
originDomain: "6648936",
destinationDomain: "1869640809",
};

const txRequest = sdkBase.estimateRelayerFee(params);
signer.sendTransaction(txRequest);

Parameters

NameTypeDefault valueDescription
paramsObjectundefinedSdkEstimateRelayerFeeParams object.
params.originDomainstringundefinedThe origin domain ID of the transfer.
params.destinationDomainstringundefinedThe destination domain ID of the transfer.
params.callDataGasAmountstringundefinedThe gas amount needed for calldata.
params.originNativeTokenstring"0x0000000000000000000000000000000000000000"(optional) The native token of the origin domain.
params.destinationNativeTokenstring"0x0000000000000000000000000000000000000000"(optional) The native token of the destination domain.
params.originNativeTokenPricenumber(uses external estimate - increases response time)(optional) The USD price of the origin native token.
params.destinationNativeTokenPricenumber(uses external estimate - increases response time)(optional) The USD price of the destination native token.
params.destinationGasPricestring(uses external estimate - increases response time)(optional) The gas price of the destination chain, in gwei units.

Returns

Promise<BigNumber>

The relayer fee in native asset of the origin domain.


getAssetsData

getAssetsData(): Promise<AssetData[]>

Fetches the list of registered assets.

Returns

Promise<AssetData[]>

Array of objects containing assets registered to the network, in the form of:

{
"local": "0x2983bf5c334743aa6657ad70a55041d720d225db",
"adopted": "0x82af49447d8a07e3bd95bd0d56f35241523fbab1",
"canonical_id": "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"canonical_domain": "6648936",
"domain": "1634886255",
"key": "0x12acadfa38ab02479ae587196a9043ee4d8bf52fcb96b7f8d2ba240f03bcd08a",
"id": "0x2983bf5c334743aa6657ad70a55041d720d225db"
},

Inherited from

SdkShared.getAssetsData


getAssetsDataByDomainAndKey

getAssetsDataByDomainAndKey(domainId, key): Promise<undefined | AssetData>

Retrieve the asset data for a specific domain and key.

Parameters

NameTypeDescription
domainIdstringThe domain ID.
keystringThe canonical hash of the canonical token.

Returns

Promise<undefined | AssetData>

The object containing asset data.

Inherited from

SdkShared.getAssetsDataByDomainAndKey


isNextAsset

isNextAsset(tokenAddress): Promise<undefined | boolean>

Returns whether the specified token is a Connext-issued (local) token.

Parameters

NameTypeDescription
tokenAddressstringThe address of the token.

Returns

Promise<undefined | boolean>

Boolean or undefined if the specified token is not registered.

Inherited from

SdkShared.isNextAsset


parseConnextTransactionReceipt

parseConnextTransactionReceipt(transactionReceipt): any

Parses a providers.TransactionReceipt for the logs.

Parameters

NameTypeDescription
transactionReceiptTransactionReceiptproviders.TransactionReceipt object.

Returns

any

Array of providers.Log objects.

Inherited from

SdkShared.parseConnextTransactionReceipt


xcall

xcall(params): Promise<TransactionRequest>

Prepares xcall inputs and encodes the calldata. Returns an ethers TransactionRequest object, ready to be sent to an RPC provider.

Example

// call SdkBase.create(), instantiate a signer

const params = {
origin: "6648936"
destination: "1869640809"
to: "0x3cEe6c5c0fB713925BdA590829EA574b7b4f96b6"
asset: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
delegate: "0x3cEe6c5c0fB713925BdA590829EA574b7b4f96b6"
amount: "1000000"
slippage: "300"
callData: "0x",
relayerFee: "10000000000000"
};

const txRequest = sdkBase.xcall(params);
signer.sendTransaction(txRequest);

Parameters

NameTypeDescription
paramsObjectSdkXCallParams object.
params.amountundefined | string(optional) The amount of tokens (in specified asset) to send with the xcall. If wrapNativeOnOrigin is true, this will be used as the amount of native token to deposit into the wrapper contract and withdraw as wrapped native token for sending (e.g. deposit ETH to the WETH contract in exchange for the WETH ERC20).
params.assetundefined | string(optional) The target asset to send with the xcall. Can be set to address(0) if this is a 0-value transfer. If wrapNativeOnOrigin is true, this should be the target wrapper contract (e.g. WETH) address.
params.callDataundefined | string(optional) Calldata to execute (can be empty: "0x").
params.delegateundefined | string(optional) Address allowed to cancel an xcall on destination.
params.destinationstringThe destination domain ID.
params.originstringThe origin domain ID.
params.receiveLocalundefined | boolean(optional) Whether to receive the local asset ("nextAsset").
params.relayerFeeundefined | string(optional) Fee paid to relayers, in native asset on origin. Use calculateRelayerFee to estimate.
params.slippageundefined | string(optional) Maximum acceptable slippage in BPS. For example, a value of 30 means 0.3% slippage.
params.tostringAddress receiving funds or the target contract.
params.wrapNativeOnOriginundefined | boolean(optional) Whether we should wrap the native token before sending the xcall. This will use the Multisend utility contract to deposit ETH, approve Connext as a spender, and call xcall. If set true, asset should be the target wrapper contract (e.g. WETH) address.
params.unwrapNativeOnDestinationundefined | boolean(optional) Whether we should unwrap the wrapped native token when the transfer reaches its destination. By default, if sending a wrapped native token, the wrapped token is what gets delivered at the destination. Setting this to true means we should overwrite callData to target the Unwrapper utility contract, which will unwrap the wrapped native token and deliver it to the target recipient (the to address).

Returns

Promise<TransactionRequest>

providers.TransactionRequest object.


create

Static create(_config): Promise<SdkBase>

Create a singleton instance of the SdkBase class.

Parameters

NameTypeDefault valueDescription
_configObjectundefinedSdkConfig object.
_config.chainsRecord<string, { providers: string[] }>undefinedChain config, at minimum with providers for each chain.
_config.signerAddressstringundefinedSigner address for transactions.
_config.logLevel"fatal" | "error" | "warn" | "info" | "debug" | "trace" | "silent""info"(optional) Logging severity level.
_config.network"testnet" | "mainnet""mainnet"(optional) Blockchain environment to interact with.

Returns

Promise<SdkBase>

providers.TransactionRequest object.

@example:

import { SdkBase } from "@connext/sdk";

const config = {
signerAddress: "<wallet_address>",
network: "mainnet",
chains: {
6648936: { // the domain ID for Ethereum Mainnet
providers: ["https://rpc.ankr.com/eth"],
},
1869640809: { // the domain ID for Optimism
providers: ["https://mainnet.optimism.io"]
},
1886350457: { // the domain ID for Polygon
providers: ["https://polygon-rpc.com"]
},
},
}

const sdkBase = await SdkBase.create(config);
note

See the Supported Chains page for all domain IDs and the Deployments page for all asset addresses.


updateSlippage

updateSlippage(params): Promise<TransactionRequest>

Updates the slippage tolerance for a specific transfer on origin; only the origin sender is allowed to do so.

Example

// call SdkBase.create(), instantiate a signer

const params = {
domainId: "6648936",
transferId: "0xdd252f58a45dc78fee1ac12a628782bda6a98315b286aadf76e4d7322bf135ca",
relayerFee: "1000",
};

const txRequest = sdkBase.updateSlippage(params);
signer.sendTransaction(txRequest);

Parameters

NameTypeDescription
paramsObjectSdkUpdateSlippageParams object.
params.domainIdstringThe origin domain ID of the transfer.
params.slippagestringThe new relayer fee to use for this transfer, in BPS.
params.transferIdstringThe transfer ID.

Returns

Promise<TransactionRequest>

providers.TransactionRequest object.


domainToChainName

Static domainToChainName(domainId): string

Returns the chain name for a specified domain.

Parameters

NameTypeDescription
domainIdstringThe domain ID.

Returns

string

The chain name.

Inherited from

SdkShared.domainToChainName


getBlockNumberFromUnixTimestamp

Static getBlockNumberFromUnixTimestamp(domainId, unixTimestamp): Promise<number>

Parameters

NameTypeDescription
domainIdstringThe domain ID.
unixTimestampnumberThe unix timestamp.

Returns

Promise<number>

Inherited from

SdkShared.getBlockNumberFromUnixTimestamp