Step 4: Initiate transfer transaction

Initiate transaction given the prior quote.

The full API reference for our /send endpoint can be found in the API reference section.

Similar to our quoting system, to initiate a transaction it requires all the following required information:

  • Bridge
  • Source chain
  • Destination chain
  • Source Token on the Source chain
  • Destination Token on the Destination chain
  • The amount you want to send
  • Source Wallet Address to pull funds from
  • Contract Call Information

Since initiating a transaction requires invoking a contract-level function on your supplied wallet address, Swing only returns the necessary call-data that will need to be signed and executed by the local wallet (i.e. Metamask, WalletConnect, Coinbase Wallet).

const sendTransaction = async (params) => {
  const result = await axios.post(
    'https://swap.prod.swing.xyz/v0/transfer/send',
    {
      fromChain: params.fromChain.slug,
      fromChainId: params.fromChain.chainId,
      tokenSymbol: params.fromToken.symbol,
      fromTokenAddress: params.fromToken.address,
 
      toChain: params.toChain.slug,
      toChainId: params.toChain.chainId,
      toTokenSymbol: params.toToken.symbol,
      toTokenAddress: params.toToken.address,
 
      fromUserAddress: params.userAddress,
      tokenAmount: params.tokenAmount,
      projectId: params.projectid, // create your project here: https://platform.swing.xyz/
 
      route: [
        {
          bridge: params.route.bridge,
          bridgeTokenAddress: params.route.tokenAddress,
          name: params.route.tokenName,
          part: 100,
        },
      ],
 
      contractCallInfo: [
        {
          toContractAddress: params.toContractAddress,
          toContractCallData: params.toContractCallData,
          outputTokenAddress: params.outputTokenAddress,
        },
      ],
    },
  );
  return result.data;
};