--- title: TypeScript SDK description: The client, the chain adapters, and the helpers worth knowing about. --- The SDK wraps the generated protobuf client with a configured transport, deposit builders for both chain families, and the formatting helpers every integration ends up writing anyway. ```bash npm install @mayanfinance/hular-sdk ``` ## Client ```ts import { createHularClient } from "@mayanfinance/hular-sdk"; const client = createHularClient({ apiKey: process.env.HULAR_API_KEY, token: () => sessionToken, }); const { hular, partner } = client; ``` | Option | Purpose | | --- | --- | | `baseUrl` | The API endpoint. Defaults to `https://api.hular.dev`. | | `apiKey` | Sent as `x-api-key` on every request. Optional. | | `token` | Called per request for a partner session token. Return `null` when signed out. | `hular` and `partner` are typed clients over `HularApi` and `PartnerApi`. Every RPC in the [API reference](/api-reference/overview) is a method on one of them, in camelCase. The transport is gRPC-web, which works in browsers and in Node. ## Chain adapters `ChainAdapter` is the interface that hides the difference between an EVM deposit and a Solana one. ```ts import { createChainAdapter, walletKindOf } from "@mayanfinance/hular-sdk"; const adapter = createChainAdapter(client, chainStatus, chainId); await adapter.balance(owner, token); const steps = await adapter.steps(wallet, quoteHash, orderParams); ``` `steps` returns an ordered list. Each has a `kind` of `approve` or `deposit` and a `run` that sends it and resolves to a transaction hash. EVM deposits produce one or two steps depending on the existing allowance; Solana always produces one. `chainId` is required for EVM chains and ignored for Solana. `walletKindOf(chain)` tells you which wallet family a chain needs. The entry point and target contract are chosen from the quote: `depositNative`, `depositToken`, `depositWithSwap`, or `swapAndForward` for a same-chain swap. See [Deposit on EVM](/integration/deposit-evm) and [Same-chain swaps](/integration/same-chain-swaps). For a gasless quote, `gaslessSteps(wallet, quoteHash, orderParams, { sponsorAddress })` replaces `steps`: it collects the permit2 signature on EVM or the sponsor-paid transaction on Solana, submits it through `SubmitGaslessOrder`, and resolves once the relayed deposit is on chain. `canPayGas(owner)` tells you whether the wallet could pay for a normal deposit at all, which is the usual trigger for offering gasless. ## Wallets Browser wallet plumbing, for apps that do not already have it: | Export | Purpose | | --- | --- | | `discoverWallets` | Lists injected EVM providers and Solana wallet-standard wallets. | | `connectWallet` | Connects one and returns a `ConnectedWallet`. | | `rememberWallets`, `restoreWallets` | Persist and rehydrate connections across reloads. | | `disconnectWallet` | Drops a connection. | | `switchEvmChain` | Switches or adds a network on an EIP-1193 provider. | | `sendEvmTransaction`, `signAndSendSvmTransaction` | Submit a built transaction. | If you already have wagmi, viem, or a wallet adapter, use yours and pass a `ConnectedWallet`-shaped object to `steps`. ## Quote helpers ```ts import { quoteOf, isSameChainSwap } from "@mayanfinance/hular-sdk"; const quote = quoteOf(response); // unwraps the oneof, undefined if empty const sameChain = isSameChainSwap(response); ``` ## Order helpers ```ts import { orderOutcome, isTerminalState, explorerTxUrl, explorerAddressUrl } from "@mayanfinance/hular-sdk"; orderOutcome(state); // "pending" | "fulfilled" | "refunded" | "failed" isTerminalState(state); // stop polling explorerTxUrl(chain.explorerTxUrl, txHash); explorerAddressUrl(chain.explorerAddressUrl, address); ``` ## Amount helpers ```ts import { parseAmount, formatAmount, trimAmount, formatUsdMicros } from "@mayanfinance/hular-sdk"; parseAmount("25.5", 6); // 25500000n formatAmount("25500000", 6); // "25.5" trimAmount("25.500000", 2); // "25.5" formatUsdMicros("25500000"); // "$25.50" ``` `parseAmount` truncates beyond the token's decimals rather than rounding, which matches what the contract will accept. ## Low-level building blocks `encodeDepositNative`, `encodeDepositToken`, `encodeDepositWithSwap`, `evmBalance`, `evmAllowance`, `buildSvmDeposit`, and `buildSvmSwapDeposit` are exported for integrations that want the calldata without the step machinery. The generated protobuf types are re-exported too, so `OrderParams`, `ChainStatus`, and the rest are importable from the package root.