Crosschain Txs
The core flow for sending a transaction through Connext consists of:
- Getting a transfer quote: returns an estimated price and commitment for the transfer.
- Starting the transfer: sends the user's transaction on chain A and waits for the network to provide liquidity.
- Finishing the transfer: completes the user's transaction on chain B.
#
GetTransferQuoteThe getTransferQuote
function accepts the following arguments:
sendingAssetId
: Required. Address of token on the initiating chain. UseAddress(0)
for native assets like $ETH.sendingChainId
: Required. ChainId of the initiating chain.receivingAssetId
: Required. Address of token on the receiving chain. UseAddress(0)
for native assets like $ETH.receivingChainId
: Required. ChainId of the receiving chain.receivingAddress
: Required. Address that the token will be sent to on receiving chain. IfcallData
andcallTo
is provided, thenreceivingAddress
acts as a fallback in case of a contract revert on the receiving chain.amount
: Required. Amount of funds (as BigNumber) to be sent either as a transaction or along with a calldata payload.expiry
: Optional. Fallback duration after which a tx is forcibly reverted if there is no response from the network. Recommended: 72 hours.callTo
: Optional. Destination contract address if doing a crosschain contract call.callData
: Optional. Calldata for crosschain contract call.
It returns an AuctionResponse object.
Example:
const quote = await sdk.getTransferQuote({ sendingAssetId: "0x9aC2c46d7AcC21c881154D57c0Dc1c55a3139198", sendingChainId: 4, receivingAssetId: "0x8a1Cad3703E0beAe0e0237369B4fcD04228d1682", receivingChainId: 5, receivingAddress: "0x5A9e792143bf2708b4765C144451dCa54f559a11", amount: utils.parseEther("1"),});
// You can validate price paid by user with data from quoteconst feeEstimate = amount.sub(quote.bid.amountReceived);
#
Executing the TransactionFirst, prepareTransfer
to initiate the transaction to our contracts. Then, wait for the transaction to be prepared on the receiving chain and call fulfillTransfer
.
// start transfer, will either prompt user for sigs/transactions or sign with unlocked accountconst transfer = await sdk.prepareTransfer(quote);
// wait for receiver prepared eventconst prepared = await sdk.waitFor( NxtpSdkEvents.ReceiverTransactionPrepared, 100_000, (data) => data.txData.transactionId === transfer.transactionId // filter function);
await sdk.fulfillTransfer(prepared);// done!
#
Next StepsSee the other sections in this folder for information on events, API, etc.
#
Full ExampleSee the test-ui
for a full working example of a React integration of the SDK.