Skip to main content

SDK Reference

The @velumx/sdk package is the primary integration point for VelumX gasless transactions.

Installation

Initialization


Core Methods

estimateFee(params)

Estimates the required fee in a SIP-010 token based on estimated gas units. Always call this before building a USER_PAYS transaction — the response tells you the active policy, the fee amount, and the relayer address to pass into the paymaster.
relayerAddress is the source of truth for the relayer arg in USER_PAYS transactions. Do not hardcode it or read it from an env var — always use estimate.relayerAddress. The relayer address can change when VelumX rotates keys or when your project is reassigned to a different relayer node.

sponsorBatch(transactions, options?)

Sponsors up to 25 transactions in a single API call. Each transaction is processed independently — one failure does not abort the rest. Always returns HTTP 200; check each item’s error field for per-item failures. When to use batch vs. single sponsor():
  • Airdrop distributions — submit tokens to many recipients without looping over sponsor().
  • Multi-step DeFi setup — approve + stake + claim in one round-trip instead of three sequential calls.
  • Queue draining — flush a backlog of pending user actions (e.g. queued bridge withdrawals) in one shot.
Rate limits: 5 batch calls/min per API key, 10/min per IP.
The primary method. Submits a signed sponsored transaction to the VelumX relayer for co-signing and broadcast.
For DEVELOPER_SPONSORS — omit feeToken and feeAmount:
For USER_PAYS — include fee params:

buildSponsoredContractCall(params)

Helper that builds an unsigned sponsored ContractCall transaction ready for wallet signing.
Getting publicKey: Use stx_getAddresses from @stacks/connect after wallet connection:
Passing to stx_signTransaction: buildSponsoredContractCall returns a Uint8Array. Some wallet versions expect a hex string. Convert if needed:
Nonce handling: If nonce is omitted, the SDK fetches it from the Stacks API. This is fine for single transactions, but for rapid sequential calls (e.g. batch setup flows where you build multiple txs before any confirms), fetch the nonce once and increment manually:

Types


Error Handling

velumx.sponsor() and velumx.sponsorBatch() throw RelayerError when the relayer rejects a request. Always catch it separately from generic errors so you can surface a useful message to the user.
For batch calls, per-item failures are returned inline — only a top-level network/auth failure throws:

Complete Example — DEVELOPER_SPONSORS

Complete Example — USER_PAYS

Complete Example — Batch Sponsorship

sponsorBatch is useful any time you need to submit multiple independent transactions in one shot — without waiting for each to confirm before sending the next. Common use cases:
  • Airdrop distributions — send tokens to hundreds of recipients in a single API call instead of looping over sponsor().
  • Multi-step DeFi setup — approve + stake + claim in one batch rather than three sequential round-trips.
  • Processing a queue — drain a backlog of pending user actions (e.g. queued bridge withdrawals) atomically.
Each transaction is processed independently. One failure does not block the rest.
Rate limits: 5 batch calls/min per API key, 10/min per IP.