@axelarjs/cosmos
TypeScript icon, indicating that this package has built-in type declarations

0.2.13 • Public • Published

@axelarjs/cosmos

type-safe clients for axelar's cosmos node

NPM Version Changelog Typedoc License

Install

pnpm add @axelarjs/cosmos

Usage

Simulate a link transaction

import { AXELAR_RPC_URLS } from "@axelarjs/core";
import { STANDARD_FEE } from "@axelarjs/cosmos/constants";
import { createAxelarSigningClient } from "@axelarjs/cosmos/constants/stargateClient";

import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
import { toAccAddress } from "@cosmjs/stargate/build/queryclient/utils";

const offlineSigner = await DirectSecp256k1HdWallet.fromMnemonic(
  process.env["COSMOS_WALLET_MNEMONIC"] as string,
  { prefix: "axelar" }
);

const client = await createAxelarSigningClient(
  AXELAR_RPC_URLS.testnet,
  offlineSigner
);

const [accData] = await offlineSigner.getAccounts();

if (!accData) {
  throw new Error("Invalid response from offlineSigner.getAccounts()");
}

const estimateGas = await client.tx.evm.link.simulate(accData.address, {
  sender: toAccAddress(String(accData.address)),
  recipientAddr: "0xB8Cd93C83A974649D76B1c19f311f639e62272BC",
  recipientChain: "avalanche",
  asset: "wavax-wei",
  chain: "fantom",
});

console.log({ estimateGas });

Broadcast a link transaction

import { AXELAR_RPC_URLS } from "@axelarjs/core";
import { STANDARD_FEE } from "@axelarjs/cosmos/constants";
import { createAxelarSigningClient } from "@axelarjs/cosmos/constants/stargateClient";

import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
import { toAccAddress } from "@cosmjs/stargate/build/queryclient/utils";

const offlineSigner = await DirectSecp256k1HdWallet.fromMnemonic(
  process.env["COSMOS_WALLET_MNEMONIC"] as string,
  { prefix: "axelar" }
);

const client = await createAxelarSigningClient(
  AXELAR_RPC_URLS.testnet,
  offlineSigner
);

const [accData] = await offlineSigner.getAccounts();

if (!accData) {
  throw new Error("Invalid response from offlineSigner.getAccounts()");
}

const txResponse = await client.tx.evm.link.signAndBroadcast(
  accData.address,
  {
    sender: toAccAddress(String(accData?.address)),
    recipientAddr: "0xB8Cd93C83A974649D76B1c19f311f639e62272BC",
    recipientChain: "avalanche",
    asset: "wavax-wei",
    chain: "fantom",
  },
  STANDARD_FEE
);

console.log({ txResponse });

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.2.132latest
0.0.0-snapshot.b521d080snapshot

Version History

VersionDownloads (Last 7 Days)Published
0.2.132
0.0.0-snapshot.b521d080
0.0.0-snapshot.553d9bc0
0.0.0-snapshot.2bd83141
0.0.0-snapshot.9c09e700
0.0.0-snapshot.99c2f0a0
0.2.12158
0.0.0-snapshot.0d85ef80
0.0.0-snapshot.2f6e7cb0
0.0.0-snapshot.023598c0
0.0.0-snapshot.8af9be90
0.0.0-snapshot.2897c970
0.2.110
0.2.100
0.2.90
0.2.80
0.2.70
0.2.60
0.2.50
0.2.41
0.2.30
0.2.20
0.2.10
0.2.00
0.1.60
0.1.50
0.0.0-snapshot.4d5c8551
0.1.40
0.0.0-snapshot.7aa35160
0.0.0-snapshot.188644f0
0.1.30
0.1.20

Package Sidebar

Install

npm i @axelarjs/cosmos

Weekly Downloads

163

Version

0.2.13

License

LicenseRef-LICENSE

Unpacked Size

292 kB

Total Files

87

Last publish

Collaborators

  • canhtrinh