JavaScript SDK
The official Node.js client for SpaceRouter Proxy. Promise-based API, TypeScript types included.
Install
npm install @spacenetwork/spacerouterRequires Node.js 18 or later. Browser and Bun support are on the roadmap.
SPACE-payment example
import { SpaceRouter, SpaceRouterSPACE } from "@spacenetwork/spacerouter";
const payment = new SpaceRouterSPACE({
gatewayMgmtUrl: "https://gateway.spacerouter.org",
wallet, // your ClientPaymentWallet
});
const router = new SpaceRouter("0xYOUR_WALLET_ADDRESS", {
gatewayUrl: "https://gateway.spacerouter.org",
payment,
region: "KR",
ipType: "residential",
});
const response = await router.get("https://httpbin.org/ip");
console.log(await response.json());
router.close();The first positional argument is the consumer's wallet address (lowercase 0x-hex). The payment helper signs the per-request EIP-191 challenge that the gateway requires.
Constructor
Methods
options accepts headers, body, and an AbortSignal:
The response object
Errors
All errors extend SpaceRouterError:
AuthenticationError
407
Payment headers missing or challenge signature rejected.
QuotaExceededError
402
Escrow balance below the request's price, or legacy Proxy-Authorization: Basic detected (api_key_auth_deprecated).
RateLimitError
429
Rate limited. Has retryAfter.
NoNodesAvailableError
503
No Provider matches your region/type filter.
UpstreamError
502
Provider couldn't reach the target site.
Pay with SPACE
The JavaScript SDK uses on-chain SPACE payment as its only auth mechanism — every request constructed via SpaceRouter is paid per byte from the consumer's escrow balance. See the Pay with SPACE guide for the wallet/escrow setup, the protocol details, and the matching Python reference implementation.
Last updated
Was this helpful?