Skip to main content
import { getPermissionStatus } from "@base-org/account/spend-permission";

// Check the status of a permission (no client needed)
const status = await getPermissionStatus(permission);

console.log(`Remaining spend: ${status.remainingSpend} wei`);
console.log(`Next period starts: ${status.nextPeriodStart}`);
console.log(`Is revoked: ${status.isRevoked}`);
console.log(`Is expired: ${status.isExpired}`);
console.log(`Is active: ${status.isActive}`);

if (status.isActive && status.remainingSpend > BigInt(0)) {
  console.log('Permission can be used for spending');
}
{
  remainingSpend: 1000000000000000000n,
  nextPeriodStart: new Date("2024-01-31T00:00:01Z"),
  isRevoked: false,
  isExpired: false,
  isActive: true,
  currentPeriod: {
    start: 1704067200,
    end: 1706659200,
    spend: 0n
  }
}
Defined in the Base Account SDK
This helper method queries the blockchain to retrieve real-time information about a spend permission, including how much can still be spent in the current period, when the next period starts, and whether the permission is still active.The function automatically uses the appropriate blockchain client based on the permission’s chain ID and calls multiple view functions on the SpendPermissionManager contract to gather comprehensive status information.

Parameters

permission
SpendPermission
required
The spend permission object to check status for. This should be a SpendPermission object returned from requestSpendPermission or fetched via fetchPermissions.

Returns

status
GetPermissionStatusResponseType
A promise that resolves to an object containing permission status details.
import { getPermissionStatus } from "@base-org/account/spend-permission";

// Check the status of a permission (no client needed)
const status = await getPermissionStatus(permission);

console.log(`Remaining spend: ${status.remainingSpend} wei`);
console.log(`Next period starts: ${status.nextPeriodStart}`);
console.log(`Is revoked: ${status.isRevoked}`);
console.log(`Is expired: ${status.isExpired}`);
console.log(`Is active: ${status.isActive}`);

if (status.isActive && status.remainingSpend > BigInt(0)) {
  console.log('Permission can be used for spending');
}
{
  remainingSpend: 1000000000000000000n,
  nextPeriodStart: new Date("2024-01-31T00:00:01Z"),
  isRevoked: false,
  isExpired: false,
  isActive: true,
  currentPeriod: {
    start: 1704067200,
    end: 1706659200,
    spend: 0n
  }
}

Error Handling

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