import { prepareSpendCallData } from "@base-org/account/spend-permission";

const spendCalls = await prepareSpendCallData({
  permission,
  amount: 10_000n, // optional
});

// If supported, submit both in a batch via wallet_sendCalls
await provider.request({
  method: "wallet_sendCalls",
  params: [
    {
      version: "2.0",
      atomicRequired: true,
      from: spender,
      calls: spendCalls,
    },
  ],
});

// Or submit sequentially with eth_sendTransaction
for (const call of spendCalls) {
  await provider.request({
    method: "eth_sendTransaction",
    params: [{ ...call, from: spender }],
  });
}
Defined in the Base Account SDK
Returns one or two calls your app’s spender can submit to execute a spend. If the permission is not yet registered onchain, an approveWithSignature call is prepended before the spend call.

Parameters

permission
SpendPermission
required
Signed permission returned from requestSpendPermission or fetched via fetchPermissions.
amount
bigint
Amount to spend (in wei). Omit to spend the remaining allowance.

Returns

result
Call[]
Array of calls to submit in order.
import { prepareSpendCallData } from "@base-org/account/spend-permission";

const spendCalls = await prepareSpendCallData({
  permission,
  amount: 10_000n, // optional
});

// If supported, submit both in a batch via wallet_sendCalls
await provider.request({
  method: "wallet_sendCalls",
  params: [
    {
      version: "2.0",
      atomicRequired: true,
      from: spender,
      calls: spendCalls,
    },
  ],
});

// Or submit sequentially with eth_sendTransaction
for (const call of spendCalls) {
  await provider.request({
    method: "eth_sendTransaction",
    params: [{ ...call, from: spender }],
  });
}

Error Handling

Always wrap the call in a try-catch block to handle these errors gracefully.
Use getPermissionStatus to check isActive and remainingSpend before preparing a spend.