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

const permission = await requestSpendPermission({
  account: "0xUserBaseAccountAddress",
  spender: "0xAppSpenderAddress",
  token: "0xTokenContractAddress",
  chainId: 84532,
  allowance: 1_000_000n,
  periodInDays: 30,
});

console.log("Spend Permission:", permission);
Defined in the Base Account SDK
Constructs an EIP-712 payload for a spend permission and prompts the user to sign it. Returns a SpendPermission object containing the signature and normalized permission data you can later use to spend or register onchain.

Parameters

account
address
required
Smart account that this spend permission applies to.
spender
address
required
The spender that can move funds from account within the configured limits.
token
address
required
Token address. Supports ERC-7528 native token address and ERC-20 contracts.
chainId
number
required
Chain ID where this permission is valid.
allowance
bigint
required
Maximum amount that can be spent during each period (in wei).
periodInDays
number
required
Length of each allowance period in days.
start
Date
Start time when the spend permission becomes valid. Defaults to now.
end
Date
Time when the spend permission expires. Defaults to never.
salt
string
Arbitrary salt to differentiate otherwise identical permissions. Hex string. Defaults to a random value.
extraData
string
Arbitrary data to attach to the permission. Hex string. Defaults to 0x.

Returns

permission
SpendPermission
Signed spend permission payload.
import { requestSpendPermission } from "@base-org/account/spend-permission";

const permission = await requestSpendPermission({
  account: "0xUserBaseAccountAddress",
  spender: "0xAppSpenderAddress",
  token: "0xTokenContractAddress",
  chainId: 84532,
  allowance: 1_000_000n,
  periodInDays: 30,
});

console.log("Spend Permission:", permission);

Error Handling

Always wrap the call in a try-catch block to handle these errors gracefully.