Skip to content

Repository files navigation

@imua-xyz/imuajs

Imua Logo
TypeScript SDK for Imuachain

TypeScript SDK for interacting with Imuachain - a Cosmos SDK chain with EVM compatibility (Ethermint). This SDK provides utilities for account management, transaction building, signing, and querying Imuachain modules.

Table of Contents

Features

  • Custom Account Parser: Handles Imuachain's EthAccount type (Ethermint-based)
  • ethsecp256k1 Signer: Creates signers where Cosmos address matches EVM address
  • Transaction Building: Simplified transaction construction and signing
  • Query Client: Scalable module-based query clients for all Imuachain modules
  • Address Conversion: Utilities for converting between EVM hex and Cosmos bech32 addresses
  • Type Safety: Full TypeScript support with generated protobuf types

Installation

yarn add @imua-xyz/imuajs

Quick Start

import { ImuachainClient } from "@imua-xyz/imuajs";
import { MessageComposer } from "@imua-xyz/imuajs/imuachain/operator/v1/tx.registry";
import { RegisterOperatorReq } from "@imua-xyz/imuajs/imuachain/operator/v1/tx";
import { CommissionRates } from "@imua-xyz/imuajs/cosmos/staking/v1beta1/staking";

// Initialize client
const client = new ImuachainClient({
  rpcEndpoint: "http://localhost:26657",
  chainId: "imuachainlocalnet_232-1",
  prefix: "im",
});

// Initialize signer from private key
await client.initSigner("0x...");

// Get signer addresses
const cosmosAddress = client.getSignerAddress(); // e.g., "im1..."
const evmAddress = client.getSignerEvmAddress(); // e.g., "0x..."

// Build and send transaction
const registerOperatorReq: RegisterOperatorReq = RegisterOperatorReq.fromPartial({
  fromAddress: cosmosAddress,
  info: {
    earningsAddr: cosmosAddress,
    approveAddr: cosmosAddress,
    operatorMetaInfo: "my-operator",
    commission: {
      commissionRates: CommissionRates.fromPartial({
        rate: "0.1",
        maxRate: "0.2",
        maxChangeRate: "0.01",
      }),
      updateTime: new Date(),
    },
  },
});

const message = MessageComposer.encoded.registerOperator(registerOperatorReq);
const txHash = await client.sendTx([message], {
  gasLimit: "200000",
  gasPrice: "10",
  feeDenom: "hua",
});

console.log("Transaction hash:", txHash);

// Query operator info
const operatorInfo = await client.getOperatorInfo(cosmosAddress);
console.log("Operator:", operatorInfo.earnings_addr);

// Or use the scalable query client
const queries = client.queries;
const assetInfo = await queries.assets.queStakingAssetInfo({ assetId: "1" });
const stakerBalance = await queries.assets.queryStakerBalance({
  stakerId: "0x...",
  assetId: "1",
});

Documentation

Examples

See the packages/imuachain/examples/ directory for complete examples:

  • register-operator-sdk.ts - Register an operator using the SDK
  • query-examples.ts - Various query examples using the scalable query client
  • register-operator.ts - Low-level example using cosmjs directly

Package Structure

This is a monorepo containing:

  • packages/imuachain - Main SDK package (@imua-xyz/imuajs)
    • TypeScript client SDK
    • Generated protobuf types for all Imuachain modules
    • Query clients for all modules
    • Transaction building utilities

Development

Prerequisites

  • Node.js 18+
  • yarn

Setup

# Install dependencies
yarn install

# Build all packages
yarn build

# Run tests
yarn test

Code Generation

The SDK uses Telescope to generate TypeScript types from protobuf definitions.

cd packages/imuachain

# Download protobuf files
yarn download-protos

# Generate TypeScript types
yarn codegen

# Build
yarn build

Testing

# Unit tests (fast, no node required)
yarn test:unit

# Integration tests (requires local Imuachain node)
yarn test:integration

# All tests
yarn test

See packages/imuachain/TESTING.md for detailed testing instructions.

Publishing

See PUBLISHING.md for detailed publishing instructions.

Quick steps:

  1. Ensure GitHub repository exists: https://github.com/imua-xyz/imuajs
  2. Build the package: cd packages/imuachain && yarn build
  3. Publish: npm publish --access public

License

MIT - See LICENSE file for details.

Repository

Related Projects

  • Imuachain - The Imuachain blockchain node
  • Telescope - TypeScript transpiler for Cosmos SDK Protobufs

Credits

Built by the Imua team.

Disclaimer

AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.

No developer or entity involved in creating this software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the code, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.

About

TypeScript SDK for interacting with Imuachain in Cosmos way

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages