Sponsored paymaster
Sponsorship Paymaster Example
This guide helps you set up a smart account and use SCS’s Sponsorship Paymaster using startale-aa-sdk, @privy-io/react-auth, and viem.
Prerequisites
Make sure you’ve installed:
yarn add viem startale-aa-sdk @privy-io/react-auth
Also, ensure your app is wrapped in Privy’s PrivyProvider.
Step 1: Connect Privy & Get EOA Wallet
import { usePrivy, useWallets } from "@privy-io/react-auth";
const { authenticated } = usePrivy();
const { wallets } = useWallets();
const provider = await wallets[0].getEthereumProvider(); // EOA provider
const address = wallets[0].address
Step 2: Create Smart Account (StartaleSmartAccount)
import { toStartaleSmartAccount } from "startale-aa-sdk";
import { createWalletClient, custom } from "viem";
import { soneiumMinato } from "viem/chains";
const signer = createWalletClient({
account: address,
chain: soneiumMinato,
transport: custom(provider),
});
const startaleAccount = = await toStartaleSmartAccount({
signer: walletClient,
chain: chain,
transport: http(),
index: BigInt(0), // Nonce=index for account instance with same EOA signer as controller
});
Step 3: Create Smart Account Client with Sponsorship Paymaster
import { createSmartAccountClient, createSCSPaymasterClient } from "startale-aa-sdk";
const scsPaymasterClient = createSCSPaymasterClient({
// Obtain paymaster url from https://portal.scs.startale.com/api-keys
transport: http(paymasterUrl)
});
const smartAccountClient = createSmartAccountClient({
account: startaleAccount,
transport: http(BUNDLER_URL),
client: publicClient, // from `createPublicClient()`
paymaster: scsPaymasterClient,
paymasterContext: {
calculateGasLimits: true,
paymasterId: "<YOUR_PAYMASTER_ID_FROM_PORTAL_DASHBOARD>",
},
});
Final Step: Use the Client to Send Transactions
Once you have smartAccountClient, you can use:
const hash = await smartAccountClient.sendUserOperation({
calls: [
{
to: "<recipient>",
value: BigInt(0),
data: "0x", // encoded call data
}
]
});
You can also use modules like Social Recovery or Sessions via startale-aa-sdk.
Notes
- paymasterContext.paymasterId is useful for gated gas sponsorship. You can setup policies on the dashboard which gets attached to your paymaster. All you need to pass is the paymasterId
- Use calculateGasLimits: true to auto-populate missing gas fields.
Quickstart CLI Scripts Example
For a complete working example, check out the quickstart CLI scripts example code: