Squid Dev Documentation
  • Getting Started
    • Overview
    • Get an Integrator ID
    • Integrator Quickstart
  • Widget Integration
    • Add A Widget
      • Swap widget
        • Getting Started
        • Installing the Widget
        • React Installation
        • NextJS Installation
        • Vite Installation
        • Iframe Installation
        • Customization Guide
          • Default User Settings
          • Configuring Content
          • Default Chains and Tokens
          • Configuration Types
          • Collect Fees
        • Information for Integrators
        • Set default chains and tokens via URL
        • Errors
    • Upgrade Your Widget
  • API & SDK Integration
    • API
      • Swap & Bridge Example
      • Staking Example
      • Cross-chain NFT Purchase Example
      • Get Route Status
    • SDK
      • Cross-chain Swap Example
      • Staking Example
      • Cross-chain NFT Purchase Example
      • Get Route Status
    • Key Concepts
      • Route Request Parameters
      • Get a route
      • Execute the route
      • 🪝Hooks
        • How do hooks work
        • Build a preHook
        • Build a postHook
        • Using the full ERC20 or Native balance in a call
        • ❗Transfer the remainder to the user
        • Get a route and execute as normal
      • Express
      • Track status
      • Types
      • Collect Fees
      • Get supported tokens and chains
    • Coral: Intent Swaps
      • Integrating Coral
    • NEW: Bitcoin and Solana
  • Adding Tokens
    • Whitelist a Token
    • Interchain Token(ITS) Listings
      • How To List
    • Circle's EURC Integration Guide
  • Migration
    • Squid v2 vs Squid v1
    • v1 -> v2 Migration
  • Additional Resources
    • Contracts
    • Squid v1 Docs
      • SDK
        • Installing our SDK
        • Get supported tokens and chains
          • Example chains response
          • Example tokens response
        • Set your transfer parameters
        • Get a route
          • Understanding the route response
        • Execute your swap or call
        • Get Route Status
        • Contract calls
          • Code example
          • Creating a ContractCall object
          • Contract call types
          • Approving ERC20s in our multicall
          • Transferring the remainder to a user
        • Collect Fees
          • Fee collector contract addresses
        • Working example!
      • API
        • integratorId
        • API playground
        • Base URLs
        • Get supported tokens and chains
        • Get a route
        • Checking the status of a transaction
        • Error codes
          • V2 API
      • Cosmos
        • Installing our SDK
        • Get supported tokens and chains
          • Example chains response
          • Example tokens response
        • Set your transfer parameters
        • Get a route
          • Cosmos route response
        • Execute your swap or call on Cosmos
        • Get Route Status
        • Cosmos custom calls
        • Working cosmos example!
        • Fallback Addresses
    • Additional Dev Resources
      • Choose How To Integrate Squid
      • Squid x Tenderly
      • Testnet or Mainnet?
      • Understanding Gas Payments
      • Supported Chains and Tokens
      • Request a new supported token
      • Liquidity Sources
        • axlASSET Liquidity
      • Integrator type specific docs
        • DEXs
        • Aggregators
        • NFTs
      • Setting up an EVM signer
      • Setting up Cosmos signer
      • Contract addresses
      • SDK easter eggs
        • Setting toAmount
        • getAllBalances
        • Advanced set up
        • Manually approve a route
        • Manually approve an ERC20
      • Whitelist a token
      • Security & Audits
        • Security
        • Audits
        • Axelar
      • Get an integrator-id
    • Architecture
      • FAQ
      • Liquidity model
      • Architecture
      • General message passing (GMP)
      • Transaction times and fees
      • Fallback behaviour on failed transactions
      • Axelar
    • Brand Assets
      • "Powered by Squid" Policy
    • Audits & Security
    • Contact
  • Changelog
    • SDK
      • v1.3
      • v1.2
    • API
      • v1.9
      • v1.8
      • v1.7
      • v1.6
  • Old v2 Documentation (Deprecated)
    • Whitelist a Token
    • Interchain Token(ITS) Listings
      • How To List
    • Add A Widget
      • Swap widget
        • Getting Started
        • Installing the Widget
        • React Installation
        • NextJS Installation
        • Iframe Installation
        • Customization Guide
          • Default User Settings
          • Theme Customization
          • Configuring Content
          • Default Chains and Tokens
          • Configuration Types
          • Collect fees
        • Information for Integrators
        • Set default chains and tokens via URL
        • Errors
      • Stake widget
        • Installing the Widget
        • Configuration
        • Importing The widget
    • Quick Start
    • API
      • Swap & Bridge Example
      • Staking Example
      • Cross-chain NFT Purchase Example
    • SDK
      • Cross-chain Swap Example
      • Staking Example
      • Cross-chain NFT Purchase Example
    • Key Concepts
      • Route Request Parameters
      • Get a route
      • Execute the route
      • 🪝Hooks
        • How do hooks work
        • Build a preHook
        • Build a postHook
        • Using the full ERC20 or Native balance in a call
        • ❗Transfer the remainder to the user
        • Add your hooks to a route request, or widget
        • Get a route and execute as normal
      • Boost
      • Track status
      • Types
      • Collect Fees
      • Get supported tokens and chains
Powered by GitBook
On this page
  • Sending transaction from EVM works by using the same flow described here. Below is a guide for sending transactions from Cosmos chains.
  • [SDK <=v1.12.0] executeRoute
  • [SDK >=v1.12.1] executeRoute
  • signerAddress
  • [SDK <=v1.12.0] Example code snippet
  • [SDK >=v1.12.1] Example code snippet
  1. Additional Resources
  2. Squid v1 Docs
  3. Cosmos

Execute your swap or call on Cosmos

PreviousCosmos route responseNextGet Route Status

Last updated 1 year ago

Executing a route requires a signer to be set up. .

Sending transaction from EVM works by using the same flow described . Below is a guide for sending transactions from Cosmos chains.

[SDK <=v1.12.0] executeRoute

// package.json cosmjs dependencies required
"@cosmjs/stargate": "^0.31.0"

Type:

const tx = await squid.executeRoute({ signer, signerAddress, route });

const cosmosTx = tx as DeliverTxResponse;

const txHash = cosmosTx.transactionHash;

[SDK >=v1.12.1] executeRoute

// package.json cosmjs dependencies required
"@cosmjs/stargate": "^0.31.3",
"@cosmjs/cosmwasm-stargate": "^0.31.3",

Type:

import { TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";

// optional, but preffered to use instead of SigningStargateClient
const signingClient = await SigningCosmWasmClient.connectWithSigner(
    rpc,
    cosmosSigner
);

const txRaw = (await squid.executeRoute({ 
    signer: signingClient as any,
    signerAddress,
    route 
})) as TxRaw;

const cosmosTx = await signingClient.broadcastTx(
    TxRaw.encode(txRaw).finish()
); // DeliverTxResponse

const txHash = cosmosTx.transactionHash;

signerAddress

Signer Address is a cosmos address of the transaction sender. Example code snippet below shows how to retrieve it.

[SDK <=v1.12.0] Example code snippet

const mnemonic ="<your_mnemonic>";
const chainRpc = "<chain_rpc>";

const offlineSigner: OfflineDirectSigner = await DirectSecp256k1HdWallet.fromMnemonic(
    mnemonic, 
    {
      prefix: "<sending_cosmos_chain_prefix>",
    }
);

const signerAddress = (await offlineSigner.getAccounts())[0].address;

const signer = await SigningStargateClient.connectWithSigner(
    chainRpc,
    offlineSigner
);

const params = {
    fromChain: "osmo-test-5", // Osmosis Testnet
    fromToken: "ibc/DE6792CF9E521F6AD6E9A4BDF6225C9571A3B74ACC0A529F92BC5122A39D2E58", // nUSDC on Osmosis
    fromAmount: "1000000", // 1 nUSDC
    toChain: 43113, // Avalanche Fuji Tesntet
    toToken: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE", // AVAX on Avalanche
    fromAddress: "osmo1eaztm3pqrkw2xgt0lxppahtx5v5pndmjg6yfrh", // Cosmos Sender address
    toAddress: "0x747A6e3824FAB0d1266306C3b492fcB941C5dd93", // the recipient of the trade
    slippage: 1.00, // 1.00 = 1% max slippage across the entire route
    enableForecall: true, // instant execution service, defaults to true
    quoteOnly: false // optional, defaults to false
};

const { route } = await squid.getRoute(params)

const cosmosTx = (await squid.executeRoute({
    signer,
    signerAddress,
    route,
})) as DeliverTxResponse;

console.log(cosmosTx.transactionHash)

[SDK >=v1.12.1] Example code snippet

const mnemonic ="<your_mnemonic>";
const chainRpc = "<chain_rpc>";

const offlineSigner: OfflineDirectSigner = await DirectSecp256k1HdWallet.fromMnemonic(
    mnemonic, 
    {
      prefix: "<sending_cosmos_chain_prefix>",
    }
);

const signerAddress = (await offlineSigner.getAccounts())[0].address;

const signer = await SigningCosmWasmClient.connectWithSigner(
    chainRpc,
    offlineSigner
);

const params = {
    fromChain: "osmo-test-5", // Osmosis Testnet
    fromToken: "ibc/DE6792CF9E521F6AD6E9A4BDF6225C9571A3B74ACC0A529F92BC5122A39D2E58", // nUSDC on Osmosis
    fromAmount: "1000000", // 1 nUSDC
    toChain: 43113, // Avalanche Fuji Tesntet
    toToken: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE", // AVAX on Avalanche
    fromAddress: "osmo1eaztm3pqrkw2xgt0lxppahtx5v5pndmjg6yfrh", // Cosmos Sender address
    toAddress: "0x747A6e3824FAB0d1266306C3b492fcB941C5dd93", // the recipient of the trade
    slippage: 1.00, // 1.00 = 1% max slippage across the entire route
    enableForecall: true, // instant execution service, defaults to true
    quoteOnly: false // optional, defaults to false
};

const { route } = await squid.getRoute(params)

const txRaw = (await squid.executeRoute({ signer, signerAddress, route })) as TxRaw;

const cosmosTx = await signingClient.broadcastTx(
    TxRaw.encode(txRaw).finish()
); // DeliverTxResponse

console.log(cosmosTx.transactionHash);
How to set up a cosmos signer
here
#executeroute
#executeroute