Execute your swap or call on Cosmos

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

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

executeRoute

Type: ExecuteRoute
const tx = await squid.executeRoute({ signer, signerAddress, route })
const cosmosTx = tx as 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.

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/40F1B2458AEDA66431F9D44F48413240B8D28C072463E2BF53655728683583E3", // 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)