> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hex-api.app/llms.txt
> Use this file to discover all available pages before exploring further.

# omni-sdk

> @hot-labs/omni-sdk: deposit to and withdraw from NEAR Intents over the HOT bridge from TypeScript, relayed by mpc.hex-api.app.

[`@hot-labs/omni-sdk`](https://github.com/hot-dao/omni-sdk) wraps the bridge for TypeScript apps: it builds the
source-chain transactions (EVM, TON, Stellar, Solana, Gonka), parses deposits, builds and publishes withdraw intents,
and finishes both sides. It talks to **`https://mpc.hex-api.app`** by default: the same [API](https://docs.hex-api.app/index.md) this tab documents, so
the relay credits deposits and clears withdrawals for you and pays their NEAR gas.

```bash theme={null}
yarn add @hot-labs/omni-sdk
```

## Setup

```ts theme={null}
import { HotBridge, Network } from "@hot-labs/omni-sdk";

const bridge = new HotBridge({
  logger: console, // optional
  evmRpc: { 56: ["https://bsc-rpc.example"] }, // only for the EVM chains you use
  tonRpc: "<tonapi key>", // only for TON
  // only for the fallbacks below: a deposit the relay cannot credit, a clear it cannot send
  executeNearTransaction: async ({ receiverId, actions }) => {
    const hash = await relayer.signAndSendTransaction({ receiverId, actions });
    return { sender: relayer.accountId, hash };
  },
});
```

`mpcApi` overrides the bridge API (default `["https://mpc.hex-api.app"]`). `api` is used only for swap quotes and
token lists.

## Deposit

```ts theme={null}
const intentAccount = "alice.near";
const hash = await bridge.ton.deposit({
  token: "native",
  amount: 100_000_000n,
  sender: "<payer address>",
  intentAccount,
  sendTransaction: async (tx) => "<tx hash>", // the payer sends it
});

// usually 30 s to 2 min; pass an AbortSignal to stop waiting
const pending = await bridge.waitPendingDeposit(Network.Ton, hash, intentAccount);
const result = await bridge.finishDeposit(pending); // { hash, sender } of the NEAR tx, or null if already credited
```

`finishDeposit` asks the relay (`POST /relay/deposit`) to credit the deposit: it checks it on the source chain, signs
it and sends `mt_deposit_call`, paying the gas. Only if the relay cannot (a legacy receiver, a chain it does not relay)
does the SDK fall back to a signature (`POST /deposit/sign`) and send the call through `executeNearTransaction`.

## Withdraw

```ts theme={null}
const result = await bridge.withdrawToken({
  chain: Network.Bnb,
  token: "native",
  amount: 10n ** 16n,
  receiver: "0x…",
  intentAccount: "alice.near",
  signIntents: async (intents) => signed, // signed by the intents account
  gasless: false,
});
```

The SDK publishes the withdraw intent, reads the omni nonce and records the withdrawal in the bridge registry
(`POST /bridge/withdrawals`), so a stuck one can be found and finished. With `gasless: true` the user pays the payout's
gas in the token, the withdrawal is paid out for them, and `withdrawToken` resolves once it is (with nothing). Otherwise
it answers `{ nonce, tx, sender }` and you pay it out yourself:

```ts theme={null}
const withdraw = await bridge.getPendingWithdrawal(result!.nonce);
await bridge.evm.withdraw({ ...withdraw, sender: "<executor>", sendTransaction: async (tx) => "<tx hash>" });
```

or let the relay do it: `POST /relay/withdraw { chain_id, receiver }` pays out every pending withdrawal of a receiver
on EVM, TON, Stellar and Gonka (see the API reference).

## Finish pending withdrawals

```ts theme={null}
const pendings = await bridge.getPendingWithdrawalsWithStatus(56, "0x…");

// paid on the chain but not cleared on omni: the relay clears them (POST /relay/clear)
const completed = pendings.filter((t) => t.completed);
if (completed.length) await bridge.clearPendingWithdrawals(completed);

// not paid yet: send each payout, oldest first
for (const pending of pendings.filter((t) => !t.completed)) {
  await bridge.evm.withdraw({ ...pending, sender: "<executor>", sendTransaction });
}
```

## Moving from the old endpoints

| Before | Now (`mpc.hex-api.app`) |
| - | - |
| `api0.herewallet.app/…/process_bridge_deposit` | `POST /relay/deposit` |
| `api0.herewallet.app/…/clear_completed_withdrawal` | `POST /relay/clear` |
| `api0.herewallet.app/…/auto_deposit_register` | `POST /bridge/register` |
| `api0.herewallet.app/…/evm/intent-solver` | `POST /intents/solver` |
| `rpc1/rpc2.hotdao.ai` `/withdraw/sign`, `/deposit/sign`, `/clear/sign` | the same paths |

Updating the SDK is enough: its defaults already point here.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.