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

const sdk = createBaseAccountSDK({
  appName: 'My App',
  appLogoUrl: 'https://example.com/logo.png',
  appChainIds: [84532],
});

// Fetch a specific permission by its hash
const permission = await fetchPermission({
  permissionHash: "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
  provider: sdk.getProvider(),
});

if (permission) {
  console.log('Permission found:', permission);
} else {
  console.log('Permission not found');
}

// Using without explicit provider (uses default SDK provider)
const permission2 = await fetchPermission({
  permissionHash: "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
});
Defined in the Base Account SDK
Returns a single spend permission by its unique hash identifier. This is useful when you have a permission hash from a previous operation and need to retrieve its current details.

Parameters

permissionHash
string
required
The unique hash identifier of the permission to retrieve.
provider
EIP1193Provider
Optional. EIP-1193 compliant Ethereum provider instance. Get this from sdk.getProvider(). If not provided, uses the default SDK provider.

Returns

permission
SpendPermission | null
The spend permission matching the hash, or null if not found.
import { fetchPermission } from "@base-org/account/spend-permission";
import { createBaseAccountSDK } from "@base-org/account";

const sdk = createBaseAccountSDK({
  appName: 'My App',
  appLogoUrl: 'https://example.com/logo.png',
  appChainIds: [84532],
});

// Fetch a specific permission by its hash
const permission = await fetchPermission({
  permissionHash: "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
  provider: sdk.getProvider(),
});

if (permission) {
  console.log('Permission found:', permission);
} else {
  console.log('Permission not found');
}

// Using without explicit provider (uses default SDK provider)
const permission2 = await fetchPermission({
  permissionHash: "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
});

Error Handling

The function returns null if the permission is not found rather than throwing an error. Always check for null values:
const permission = await fetchPermission({
  permissionHash: hash,
});

if (!permission) {
  // Handle permission not found
  console.error('Permission not found');
  return;
}

// Safe to use permission here
console.log('Permission details:', permission);

Usage Notes

This function is particularly useful when:
  • You have a permission hash from a previous operation (e.g., from requestSpendPermission)
  • You want to verify the current state of a specific permission
  • You need to look up permission details without knowing the account or spender information
  • You’re tracking specific permissions across sessions
Unlike fetchPermissions, this function:
  • Returns a single permission instead of an array
  • Does not require account, chain, or spender parameters
  • Provides direct access via the permission’s unique identifier
  • Returns null instead of an empty array when no permission is found