New:Introducing Socket Scanning for VS Code Marketplace Extensions.Learn more →
Get Started

@layerhop/sdk

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@layerhop/sdk

LayerHop SDK — best-price cross-chain and same-chain swaps

Source
npmnpm
Version
0.1.0
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

@layerhop/sdk

npm license docs

Typed TypeScript client for the LayerHop API: best-price cross-chain and same-chain swaps across EVM chains and Solana through one non-custodial API.

  • Zero runtime dependencies. Uses the global fetch; works in Node 18+, browsers, Deno, Bun and edge runtimes.
  • ESM + CommonJS builds with bundled type definitions.
  • Never holds keys. It fetches quotes and builds unsigned transactions; your wallet signs.

Install

npm install @layerhop/sdk
# or: pnpm add @layerhop/sdk / yarn add @layerhop/sdk / bun add @layerhop/sdk

Quickstart

Amounts are always integer strings in base units (100 USDC = "100000000"), never floats.

import { LayerHop, LayerHopApiError } from "@layerhop/sdk";

const lh = new LayerHop({ apiKey: process.env.LAYERHOP_API_KEY, integrator: "myapp" });

// 1. Quote every provider; `best` is the highest output for the user.
const { best } = await lh.quote({
  srcChain: "base", srcToken: "USDC", amount: "100000000",
  dstChain: "solana", dstToken: "SOL",
  sender: "0xYourEvmAddress", recipient: "YourSolanaAddress",
});

// 2. Build the unsigned transaction (EVM txs may include an `approval` to send first).
const tx = await lh.buildTx(best.quoteId);

// 3. Sign and send with your own wallet stack (viem, ethers, wallet adapter...), then report it.
//    const hash = await wallet.sendTransaction(tx);
//    await lh.reportSubmitted(best.quoteId, hash);

// 4. Track until filled / refunded / failed.
//    for await (const s of lh.watch(best.provider, hash)) console.log(s.state);

Errors are thrown as LayerHopApiError with a stable code (see the error catalog):

try {
  await lh.buildTx(quoteId);
} catch (e) {
  if (e instanceof LayerHopApiError && e.code === "QUOTE_EXPIRED") {
    // re-quote
  }
}

API

MethodEndpointWhat
quote(params)GET /v1/quoteEvery successful quote, best for the user first.
buildTx(quoteId)POST /v1/ordersThe unsigned transaction for a quote (EvmTx or SvmTx).
submit(quoteId, signedTx)POST /v1/orders/submitSolana txs with submitViaApi: send the signed tx through LayerHop.
reportSubmitted(quoteId, txHash)POST /v1/orders/{quoteId}/submittedTell LayerHop the tx was broadcast.
simulate(quoteId)POST /v1/simulateDry-run the tx (EVM eth_call + gas, Solana simulateTransaction).
listOrders(params)GET /v1/ordersOrders from or to an address, newest first.
status(provider, id)GET /v1/orders/{provider}/{id}Order status.
watch(provider, id, opts?)polls statusAsync generator yielding each state change until final.

Options for new LayerHop(options): baseUrl (default https://api.layerhop.com), apiKey, channel, integrator, integratorFeeBps, fetch.

The package also exports the chain and token registry (CHAINS, getChain, TOKENS, findToken, SOLANA_CHAIN_ID, EVM_NATIVE, SOL_NATIVE) and all request/response types.

Full reference: https://docs.layerhop.com/sdk.

License

MIT

Keywords

layerhop

FAQs

Package last updated on 18 Oct 2026

Related posts