Skip to main content

What You’ll Accomplish

By the end of this guide, you’ll have:
  • ✅ Installed the avnu SDK
  • ✅ Fetched the best swap quote
  • ✅ Executed a token swap on Starknet

Prerequisites

Download from nodejs.org

Step 1: Install the SDK

Step 2: Initialize Your Account

Every execute* method takes a starknet.js account. In a script or backend, build it from a private key:
In a dapp, build it around the connected wallet instead. Your wallet-connection layer (get-starknet, @starknet-start/react, …) exposes the wallet-standard object and the connected address — note that hook-based libraries no longer return a ready-made account object, only these two:
This constructor is the intended API: WalletAccountV6.connect / connectSilent are thin wrappers that fetch the address from the wallet and call it (use connectSilent when you don’t already have the address — no prompt if the dapp is authorized). It subscribes to wallet events, so call account.unsubscribeChange() when you drop or replace the instance.
Security Note: Never hardcode private keys in production.

Step 3: Fetch Swap Quotes

Optional Parameters:
  • size: Number of quotes to return (default: 1)
  • excludeSources: Array of source names to exclude
  • integratorFees: Your integration fees in bps
  • integratorFeeRecipient: Address to receive fees
  • integratorName: Your platform name
  • onlyDirect: if you want only direct routes

Step 4: Execute the Swap

Default Behavior:
  • executeApprove: true - Automatically approves token spending if needed
  • slippage - Required parameter for price protection
  • Reverts if price moves beyond slippage tolerance

Complete Example

Next Steps

Paymaster

Sponsor gas or multi-token gas payments

API Reference

Complete REST API docs

DCA Orders

Add automated recurring buys

Resources

API Reference

REST API documentation

SDK

TypeScript/JavaScript SDK

Support

Telegram community