TypeScript SDK: SmoothSend Gasless Transactions
Purpose
Guide gasless transaction sponsorship on Aptos using SmoothSend. Users sign transactions
via their wallet but never pay gas — you pay per transaction from pre-loaded credits. Works as a drop-in
transactionSubmitter for AptosWalletAdapterProvider.
Paid commercial service: Free on testnet; mainnet uses credit-based billing. See
Pricing for current rates.
ALWAYS
- 1. Use
@smoothsend/sdk — official npm package for SmoothSend integration. - Pass
SmoothSendTransactionSubmitter as transactionSubmitter in AptosWalletAdapterProvider — this enables
gasless for all
signAndSubmitTransaction calls.
- 3. Store API key in env — use
NEXT_PUBLIC_SMOOTHSEND_API_KEY or VITE_SMOOTHSEND_API_KEY (never hardcode). - Use testnet for development — testnet is always free; no credits required.
- Handle 402 (Insufficient credits) — API returns 402 when credits run out; show user-friendly message and link to
billing.
NEVER
- 1. Do not expose API key in server-side only apps to client — for frontend, use
NEXT_PUBLIC_ or VITE_ prefixed
env vars.
- 2. Do not skip
transactionSubmitter — without it, users pay gas themselves; the provider falls back to normal
submission.
- 3. Do not use Script Composer for arbitrary transactions — Script Composer is for stablecoin transfers (USDC, USDT,
etc.) only; use Wallet Adapter for everything else.
Method 1: Wallet Adapter (Recommended — Any Transaction)
Use for swaps, NFT mints, contract calls — any transaction type.
Installation
CODEBLOCK0
Provider Setup (3 lines)
CODEBLOCK1
After this, every signAndSubmitTransaction call is gasless. No other code changes needed.
Method 2: Script Composer (Fee-in-Token — Stablecoin Only)
Use for USDC, USDT, WBTC, USDe, USD1 transfers. Fee (~$0.01) is deducted from the token being sent — no APT or
SmoothSend credits required.
CODEBLOCK2
Error Handling
CODEBLOCK3
Pricing
See SmoothSend Pricing for current rates. Testnet is free; mainnet uses credit
packs.
Common Mistakes
| Mistake | Correct approach |
|---|
| Forgetting INLINECODE13 | Pass smoothSend in INLINECODE15 |
| Hardcoding API key |
Use env var with
NEXT_PUBLIC_ or
VITE_ prefix |
| Using Script Composer for non-transfer tx | Use Wallet Adapter for swaps, mints, contract calls |
| Not handling 402 | Catch and show user-friendly message + billing link |
| Wrong network | Match
network in SmoothSend config to
dappConfig.network |
References
- - SmoothSend Docs: https://docs.smoothsend.xyz
- Pricing: https://docs.smoothsend.xyz/pricing
- Dashboard: https://dashboard.smoothsend.xyz
- npm: https://www.npmjs.com/package/@smoothsend/sdk
- MCP (AI context):
npx @smoothsend/mcp — tools for getdocs, estimatecredits, getcodesnippet - Related: ts-sdk-wallet-adapter,
ts-sdk-transactions
TypeScript SDK: SmoothSend 无 Gas 交易
目的
指导在 Aptos 上使用 SmoothSend 实现无 Gas 交易赞助。用户通过钱包签署交易,但无需支付 Gas 费用——您从预充值积分中按交易付费。可作为 AptosWalletAdapterProvider 的即插即用 transactionSubmitter。
付费商业服务: 测试网免费;主网采用积分制计费。当前费率请参阅 定价页面。
务必遵守
- 1. 使用 @smoothsend/sdk——SmoothSend 集成的官方 npm 包。
- 在 AptosWalletAdapterProvider 中将 SmoothSendTransactionSubmitter 作为 transactionSubmitter 传入——这将使所有 signAndSubmitTransaction 调用实现无 Gas。
- 将 API 密钥存储在环境变量中——使用 NEXTPUBLICSMOOTHSENDAPIKEY 或 VITESMOOTHSENDAPI_KEY(切勿硬编码)。
- 使用测试网进行开发——测试网始终免费,无需积分。
- 处理 402(积分不足)错误——API 在积分耗尽时返回 402;显示用户友好提示信息并提供计费链接。
严禁事项
- 1. 不要在仅服务端应用中向客户端暴露 API 密钥——前端请使用 NEXTPUBLIC 或 VITE_ 前缀的环境变量。
- 不要跳过 transactionSubmitter——没有它,用户将自行支付 Gas;提供者将回退到正常提交方式。
- 不要将 Script Composer 用于任意交易——Script Composer 仅用于稳定币转账(USDC、USDT 等);其他所有交易请使用 Wallet Adapter。
方法一:Wallet Adapter(推荐——适用于任何交易)
适用于兑换、NFT 铸造、合约调用等任何交易类型。
安装
bash
npm install @smoothsend/sdk @aptos-labs/wallet-adapter-react
提供者设置(3 行代码)
tsx
import { SmoothSendTransactionSubmitter } from @smoothsend/sdk;
import { AptosWalletAdapterProvider } from @aptos-labs/wallet-adapter-react;
import { Network } from @aptos-labs/ts-sdk;
const smoothSend = new SmoothSendTransactionSubmitter({
apiKey: process.env.NEXTPUBLICSMOOTHSENDAPIKEY!,
network: mainnet // 或 testnet(始终免费)
});
export function Providers({ children }: { children: React.ReactNode }) {
return (
autoConnect={true}
dappConfig={{
network: Network.MAINNET,
transactionSubmitter: smoothSend
}}
onError={(error) => console.error(钱包错误:, error)}
>
{children}
);
}
此后,每次 signAndSubmitTransaction 调用均为无 Gas。无需其他代码更改。
方法二:Script Composer(代币内扣费——仅限稳定币)
适用于 USDC、USDT、WBTC、USDe、USD1 转账。费用(约 $0.01)从发送的代币中扣除——无需 APT 或 SmoothSend 积分。
typescript
import { ScriptComposerClient } from @smoothsend/sdk;
const client = new ScriptComposerClient({
apiKey: process.env.NEXTPUBLICSMOOTHSENDAPIKEY!,
network: mainnet
});
// USDC 主网资产地址
const USDC_ASSET = 0xbae207659db88bea0cbead6da0ed00aac12edcdda169e591cd41c94180b46f3b;
const build = await client.buildTransfer({
sender: walletAddress,
recipient: 0xRecipient...,
amount: 1000000, // 1 USDC(6 位小数)
assetType: USDC_ASSET,
decimals: 6,
symbol: USDC
});
// 使用钱包签名,然后提交 build.signedTransaction
错误处理
tsx
try {
const response = await signAndSubmitTransaction(payload);
await aptos.waitForTransaction({ transactionHash: response.hash });
} catch (error: any) {
if (error?.status === 402 || error?.message?.includes(积分不足)) {
// 积分耗尽——显示升级提示
toast.error(服务暂时不可用,请稍后重试。);
window.open(https://dashboard.smoothsend.xyz/billing, _blank);
} else {
throw error;
}
}
定价
当前费率请参阅 SmoothSend 定价页面。测试网免费;主网使用积分包。
常见错误
| 错误 | 正确做法 |
|---|
| 忘记设置 transactionSubmitter | 在 dappConfig 中传入 smoothSend |
| 硬编码 API 密钥 |
使用 NEXT
PUBLIC 或 VITE_ 前缀的环境变量 |
| 将 Script Composer 用于非转账交易 | 兑换、铸造、合约调用请使用 Wallet Adapter |
| 未处理 402 错误 | 捕获错误并显示用户友好提示信息 + 计费链接 |
| 网络配置错误 | 确保 SmoothSend 配置中的 network 与 dappConfig.network 一致 |
参考资料
- - SmoothSend 文档:https://docs.smoothsend.xyz
- 定价页面:https://docs.smoothsend.xyz/pricing
- 控制台:https://dashboard.smoothsend.xyz
- npm:https://www.npmjs.com/package/@smoothsend/sdk
- MCP(AI 上下文):npx @smoothsend/mcp——用于 getdocs、estimatecredits、getcodesnippet 的工具
- 相关技能:ts-sdk-wallet-adapter、ts-sdk-transactions