Working cosmos example!

You'll need to install Squid via npm first, then put in your cosmos wallet mnemonic and you're good!

SDK <=v1.12.0

import { RouteResponse, Squid } from "@0xsquid/sdk";
import { SigningStargateClient, DeliverTxResponse } from "@cosmjs/stargate";
import {
  DirectSecp256k1HdWallet,
  OfflineDirectSigner,
} from "@cosmjs/proto-signing";

(async () => {
  const baseUrl = "https://testnet.api.0xsquid.com";

  // instantiate the SDK
  const squid = new Squid({
    baseUrl: baseUrl,
  });

  // init the SDK
  await squid.init();
  console.log("Squid inited");

  const mnemonic = "<your_mnemonic>";
  const osmosisRpc = "https://rpc.osmotest5.osmosis.zone"; // osmosis testnet rpc endpoint

  const getSignerFromMnemonic = async (): Promise<OfflineDirectSigner> => {
    return DirectSecp256k1HdWallet.fromMnemonic(mnemonic, {
      prefix: "osmo",
    });
  };
  const offlineSigner: OfflineDirectSigner = await getSignerFromMnemonic();

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

  const signer = await SigningStargateClient.connectWithSigner(
    osmosisRpc,
    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
  };

  let { route }: RouteResponse = await squid.getRoute(params);

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

  const txHash = cosmosTx.transactionHash;

  const status = await squid.getStatus({
    transactionId: txHash,
    fromChainId: "osmo-test-5",
    toChainId: 43113,
  });

  console.log(status);
})();

SDK >=v1.12.1

```package.json dependancies 
 // "dependencies": {
  //   "@0xsquid/sdk": "1.14.8",
  //   "@cosmjs/crypto": "0.31.0",
  //   "@cosmjs/stargate": "0.31.3",
  //   "@cosmjs/cosmwasm-stargate": "0.31.3",
  //   "@cosmjs/utils": "0.31.0",
  //   "@types/node": "18.11.10",
  //   "@types/typescript": "2.0.0",
  //   "ts-node": "10.9.1",
  //   "typescript": "4.9.3"
  // }
```

import { RouteResponse, Squid } from "@0xsquid/sdk";
import {
  DirectSecp256k1HdWallet,
  OfflineDirectSigner,
} from "@cosmjs/proto-signing";
import { SigningCosmWasmClient } from "@cosmjs/cosmwasm-stargate";
import { TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";


(async () => {
  const baseUrl = "https://testnet.api.0xsquid.com";

  // instantiate the SDK
  const squid = new Squid({
    baseUrl: baseUrl,
  });

  // init the SDK
  await squid.init();
  console.log("Squid inited");

  const mnemonic = "<your_mnemonic>";
  const osmosisRpc = "https://rpc.osmotest5.osmosis.zone"; // osmosis testnet rpc endpoint

  const getSignerFromMnemonic = async (): Promise<OfflineDirectSigner> => {
    return DirectSecp256k1HdWallet.fromMnemonic(mnemonic, {
      prefix: "osmo",
    });
  };
  const offlineSigner: OfflineDirectSigner = await getSignerFromMnemonic();

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

  const signer = await SigningCosmWasmClient.connectWithSigner(
    osmosisRpc,
    
  );

  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
  };

  let { route }: RouteResponse = await squid.getRoute(params);

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

  const txHash = cosmosTx.transactionHash;

  const status = await squid.getStatus({
    transactionId: txHash,
    fromChainId: "osmo-test-5",
    toChainId: 43113,
  });

  console.log(status);
})();

Last updated