$npx -y skills add aptos-labs/aptos-agent-skills --skill smoothsend-gaslessHow to sponsor gas fees for Aptos dApp users using SmoothSend. Paid commercial service: free on testnet, credit-based on mainnet. Covers 3-line wallet adapter integration (transactionSubmitter), Script Composer for fee-in-token stablecoin transfers. Triggers on: 'gasless', 'spons
| 1 | # TypeScript SDK: SmoothSend Gasless Transactions |
| 2 | |
| 3 | ## Purpose |
| 4 | |
| 5 | Guide **gasless transaction sponsorship** on Aptos using [SmoothSend](https://smoothsend.xyz). Users sign transactions |
| 6 | via their wallet but never pay gas — you pay per transaction from pre-loaded credits. Works as a drop-in |
| 7 | `transactionSubmitter` for `AptosWalletAdapterProvider`. |
| 8 | |
| 9 | **Paid commercial service:** Free on testnet; mainnet uses credit-based billing. See |
| 10 | [Pricing](https://docs.smoothsend.xyz/pricing) for current rates. |
| 11 | |
| 12 | ## ALWAYS |
| 13 | |
| 14 | 1. **Use `@smoothsend/sdk`** — official npm package for SmoothSend integration. |
| 15 | 2. **Pass `SmoothSendTransactionSubmitter` as `transactionSubmitter`** in `AptosWalletAdapterProvider` — this enables |
| 16 | gasless for all `signAndSubmitTransaction` calls. |
| 17 | 3. **Store API key in env** — use `NEXT_PUBLIC_SMOOTHSEND_API_KEY` or `VITE_SMOOTHSEND_API_KEY` (never hardcode). |
| 18 | 4. **Use testnet for development** — testnet is always free; no credits required. |
| 19 | 5. **Handle 402 (Insufficient credits)** — API returns 402 when credits run out; show user-friendly message and link to |
| 20 | billing. |
| 21 | |
| 22 | ## NEVER |
| 23 | |
| 24 | 1. **Do not expose API key in server-side only apps to client** — for frontend, use `NEXT_PUBLIC_` or `VITE_` prefixed |
| 25 | env vars. |
| 26 | 2. **Do not skip `transactionSubmitter`** — without it, users pay gas themselves; the provider falls back to normal |
| 27 | submission. |
| 28 | 3. **Do not use Script Composer for arbitrary transactions** — Script Composer is for stablecoin transfers (USDC, USDT, |
| 29 | etc.) only; use Wallet Adapter for everything else. |
| 30 | |
| 31 | --- |
| 32 | |
| 33 | ## Method 1: Wallet Adapter (Recommended — Any Transaction) |
| 34 | |
| 35 | Use for swaps, NFT mints, contract calls — any transaction type. |
| 36 | |
| 37 | ### Installation |
| 38 | |
| 39 | ```bash |
| 40 | npm install @smoothsend/sdk @aptos-labs/wallet-adapter-react |
| 41 | ``` |
| 42 | |
| 43 | ### Provider Setup (3 lines) |
| 44 | |
| 45 | ```tsx |
| 46 | import { SmoothSendTransactionSubmitter } from "@smoothsend/sdk"; |
| 47 | import { AptosWalletAdapterProvider } from "@aptos-labs/wallet-adapter-react"; |
| 48 | import { Network } from "@aptos-labs/ts-sdk"; |
| 49 | |
| 50 | const smoothSend = new SmoothSendTransactionSubmitter({ |
| 51 | apiKey: process.env.NEXT_PUBLIC_SMOOTHSEND_API_KEY!, |
| 52 | network: "mainnet" // or 'testnet' (always free) |
| 53 | }); |
| 54 | |
| 55 | export function Providers({ children }: { children: React.ReactNode }) { |
| 56 | return ( |
| 57 | <AptosWalletAdapterProvider |
| 58 | autoConnect={true} |
| 59 | dappConfig={{ |
| 60 | network: Network.MAINNET, |
| 61 | transactionSubmitter: smoothSend |
| 62 | }} |
| 63 | onError={(error) => console.error("Wallet error:", error)} |
| 64 | > |
| 65 | {children} |
| 66 | </AptosWalletAdapterProvider> |
| 67 | ); |
| 68 | } |
| 69 | ``` |
| 70 | |
| 71 | After this, every `signAndSubmitTransaction` call is gasless. No other code changes needed. |
| 72 | |
| 73 | --- |
| 74 | |
| 75 | ## Method 2: Script Composer (Fee-in-Token — Stablecoin Only) |
| 76 | |
| 77 | Use for USDC, USDT, WBTC, USDe, USD1 transfers. Fee (~$0.01) is deducted from the token being sent — no APT or |
| 78 | SmoothSend credits required. |
| 79 | |
| 80 | ```typescript |
| 81 | import { ScriptComposerClient } from "@smoothsend/sdk"; |
| 82 | |
| 83 | const client = new ScriptComposerClient({ |
| 84 | apiKey: process.env.NEXT_PUBLIC_SMOOTHSEND_API_KEY!, |
| 85 | network: "mainnet" |
| 86 | }); |
| 87 | |
| 88 | // USDC Mainnet asset address |
| 89 | const USDC_ASSET = "0xbae207659db88bea0cbead6da0ed00aac12edcdda169e591cd41c94180b46f3b"; |
| 90 | |
| 91 | const build = await client.buildTransfer({ |
| 92 | sender: walletAddress, |
| 93 | recipient: "0xRecipient...", |
| 94 | amount: "1000000", // 1 USDC (6 decimals) |
| 95 | assetType: USDC_ASSET, |
| 96 | decimals: 6, |
| 97 | symbol: "USDC" |
| 98 | }); |
| 99 | |
| 100 | // Sign with wallet, then submit build.signedTransaction |
| 101 | ``` |
| 102 | |
| 103 | --- |
| 104 | |
| 105 | ## Error Handling |
| 106 | |
| 107 | ```tsx |
| 108 | try { |
| 109 | const response = await signAndSubmitTransaction(payload); |
| 110 | await aptos.waitForTransaction({ transactionHash: response.hash }); |
| 111 | } catch (error: any) { |
| 112 | if (error?.status === 402 || error?.message?.includes("Insufficient credits")) { |
| 113 | // Credits exhausted — show upgrade CTA |
| 114 | toast.error("Service temporarily unavailable. Please try again later."); |
| 115 | window.open("https://dashboard.smoothsend.xyz/billing", "_blank"); |
| 116 | } else { |
| 117 | throw error; |
| 118 | } |
| 119 | } |
| 120 | ``` |
| 121 | |
| 122 | --- |
| 123 | |
| 124 | ## Pricing |
| 125 | |
| 126 | See [SmoothSend Pricing](https://docs.smoothsend.xyz/pricing) for current rates. Testnet is free; mainnet uses credit |
| 127 | packs. |
| 128 | |
| 129 | --- |
| 130 | |
| 131 | ## Common Mistakes |
| 132 | |
| 133 | | Mistake | Correct approach | |
| 134 | | ----------------------------------------- | ------------------------------------------------------------ | |
| 135 | | Forgetting `transactionSubmitter` | Pass `smoothSend` in `d |