Clutch Hub SDK (JS) Overview
JavaScript/TypeScript SDK for client-side transaction signing and Clutch Hub API integration.
Features
- Client-side signing — Private keys never leave the user's device. A browser app holds none: the user's wallet (MetaMask, Trust Wallet, TronLink) keeps the key and signs after the user approves
- Full ride lifecycle — Request, offer, accept, pay, cancel; plus Burn for CLT redemption
- Chain-bound and verifiable —
chain_idin every signature;verifyUnsignedTransactionchecks a hub-returned transaction before you sign it - GraphQL integration — Queries, mutations, and WebSocket subscriptions
- TypeScript — Type-safe interfaces for all methods; amounts are
bigint
v3: breaking changes
Amounts are now bigint (not number), the constructor takes an optional chainId, and the signed wire format gained a field. See v3 breaking changes before upgrading from v2.
Install
npm install clutch-hub-sdk-js
Quick example
import { ClutchHubSdk } from 'clutch-hub-sdk-js';
const CHAIN_ID = 2077; // from your app config — never from the hub
const sdk = new ClutchHubSdk('http://localhost:3000', publicKey, undefined, CHAIN_ID);
const tx = await sdk.createUnsignedRideRequest({
pickup: { latitude: 35.7, longitude: 51.4 },
dropoff: { latitude: 35.8, longitude: 51.5 },
fare: 5_000_000n, // $5.00 at 1 USD = 1,000,000 CLT
});
const signed = await sdk.signTransaction(tx, privateKey, { type: 'RideRequest', fare: 5_000_000n });
await sdk.submitTransaction(signed.rawTransaction);
With a wallet instead of a key:
import { discoverInjectedWallets, connectWallet } from 'clutch-hub-sdk-js';
const [wallet] = await discoverInjectedWallets();
const signer = await connectWallet(wallet); // the wallet asks the user
const sdk = new ClutchHubSdk('http://localhost:3000', signer.address, signer, CHAIN_ID);
// ... then pass `signer` where the example passes `privateKey`
Documentation
Source
clutch-hub-sdk-js on GitHub · npm