@lumera/sdk-js
    Preparing search index...

    Class CosmjsTxClient

    CosmJS-based transaction client for Lumera blockchain.

    Wraps CosmJS's SigningStargateClient to provide transaction simulation, signing, and broadcasting capabilities. Handles gas estimation and transaction lifecycle management.

    const client = new CosmjsTxClient(signingClient, {
    gasMultiplier: 1.5
    });

    // Simulate to estimate gas
    const gasEstimate = await client.simulate(address, msgs, "memo");

    // Sign and broadcast
    const result = await client.signAndBroadcast(
    address,
    msgs,
    { amount: [{ denom: "ulume", amount: "5000" }], gas: "200000" },
    "Transaction memo"
    );
    console.log("TX Hash:", result.txHash);

    Implements

    Index

    Constructors

    • Create a new CosmJS transaction client

      Parameters

      • sg: SigningStargateClient

        CosmJS SigningStargateClient instance

      • Optionaloptions: CosmjsTxClientOptions

        Optional configuration

      Returns CosmjsTxClient

    Methods

    • Broadcast a pre-signed transaction.

      Sends a signed transaction to the blockchain. This is a low-level method; prefer using signAndBroadcast for most use cases.

      Parameters

      • signedTx: Uint8Array

        Signed transaction bytes

      • mode: "sync" | "async" | "block" = "sync"

        Broadcast mode ("sync", "async", or "block")

      Returns Promise<{ height?: bigint; txHash: string }>

      Broadcast result with transaction hash and height

      If broadcast fails

      const result = await client.broadcast(signedTxBytes, "sync");
      console.log("TX:", result.txHash);
    • Disconnect and clean up resources.

      Should be called when the client is no longer needed to properly close connections.

      Returns Promise<void>

    • Get the underlying SigningStargateClient.

      Provides access to the raw CosmJS client for advanced use cases not covered by this wrapper.

      Returns SigningStargateClient

      The underlying SigningStargateClient instance

    • Query a transaction by hash.

      Retrieves the full transaction details including events from the blockchain. This is useful for extracting information from transaction events after broadcasting.

      Parameters

      • txHash: string

        Transaction hash (hex string)

      Returns Promise<DeliverTxResponse>

      Transaction response with full details including events

      If the query fails or transaction is not found

      const txDetails = await client.getTx("ABC123...");
      console.log("Events:", txDetails.events);
    • Sign and broadcast a transaction in one step.

      This is the recommended method for sending transactions. It handles the entire transaction lifecycle: signing with the wallet, broadcasting to the chain, and waiting for confirmation (in "block" mode).

      Parameters

      • signerAddress: string

        Address of the transaction signer

      • messages: readonly EncodeObject[]

        Array of Cosmos messages to include in the transaction

      • fee: StdFee

        Transaction fee (gas amount and denomination)

      • Optionalmemo: string

        Optional transaction memo

      • OptionaltimeoutHeight: bigint

        Optional transaction timeout height

      Returns Promise<BroadcastResult>

      Broadcast result with full delivery response

      If signing or broadcasting fails

      const result = await client.signAndBroadcast(
      myAddress,
      [msgRegisterAction],
      { amount: [{ denom: "ulume", amount: "10000" }], gas: "300000" },
      "Register cascade action"
      );

      if (result.response.code === 0) {
      console.log("Success! TX:", result.txHash);
      } else {
      console.error("Failed:", result.response.rawLog);
      }
    • Simulate a transaction to estimate gas usage.

      Performs a dry-run of the transaction to estimate the gas required. The returned gas amount should typically be multiplied by a safety factor (e.g., 1.3-1.5) to account for state changes between simulation and execution.

      Returns null if simulation fails due to type resolution errors (indicating that the gRPC reflection service is unavailable). In this case, the caller should use a fallback gas estimate.

      Parameters

      • address: string

        Signer's address

      • msgs: readonly EncodeObject[]

        Transaction messages to simulate

      • memo: string = ""

        Transaction memo (optional)

      Returns Promise<bigint | null>

      Estimated gas amount, or null if simulation is unavailable

      If simulation fails for reasons other than type resolution

      const estimatedGas = await client.simulate(myAddress, [msgSend], "test");
      if (estimatedGas !== null) {
      const gasWithBuffer = estimatedGas * 13n / 10n; // 30% buffer
      }