> For the complete documentation index, see [llms.txt](https://docs.kiiglobal.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.kiiglobal.io/docs/build-on-kiichain/developer-tools/js-ts-sdk/kiijs-utils.md).

# Kiijs-utils

## @kiichain/kiijs-utils

Typescript library containing general utility functions for interacting with Kiichain.

### Installation

```bash
yarn add @kiichain/kiijs-utils @kiichain/kiijs-proto
```

### Bech32 conversion

The package has utils to easen up conversion between hex and bech32 addresses. They can be used like this:

```tsx
import { HexToBech32, Bech32ToHex } from '@kiichain/kiijs-utils'

const kiiAddress = HexToBech32("0xyourhex")

const evmAddress = Bech32ToHex("kiiYouraddress)
```

### ETHSECP signer

Some wallets do not recognize the ETHSECP256-1 PubKey signatures. We made a couple helpers to utilize it without problems.

#### Signing a transaction

1. Create the `SigningStargateClient` with the correct type

```typescript
import { ethsecpAccountParser, signWithEthsecpSigner } from '@kiichain/kiijs-utils';

// Start the client connection
// The stargate client must use the custom account parser
// This is necessary to handle the ethsecp256k1 PubKey format in queries
const client = await SigningStargateClient.connectWithSigner(
  RPC_ENDPOINT,
  offlineSigner,
  {
    accountParser: ethsecpAccountParser,
  }
);
```

The signing client must use a custom account parser to handle the `ethsecp256k1` public key format. This is crucial for correctly signing transactions.

2. Sign the transaction with a custom pubkey

```typescript
// This is the important bit
// This signs the transaction using the ethsecp256k1 signer
// It basically rewrite the Pubkey to the ethsecp256k1 format
const txRaw = await signWithEthsecpSigner(
  client,
  offlineSigner,
  CHAIN_ID,
  address,
  [msgSend],
  "This is a sample transaction memo",
  KEPLR_CHAIN_INFO.feeCurrencies[0].gasPriceStep.high,
  1.5
);
```

3. Broadcast the signed transaction

```typescript
const receipt = await client.broadcastTx(txRaw);

A full example can be found [here](https://github.com/KiiChain/keplr-tx-template/blob/main/src/App.tsx)
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.kiiglobal.io/docs/build-on-kiichain/developer-tools/js-ts-sdk/kiijs-utils.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
