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');}
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');}
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.
The spend permission object to check status for. This should be a SpendPermission object returned from requestSpendPermission or fetched via fetchPermissions.
Remaining allowance in wei for the current period. Calculated as the difference between the allowance and the amount already spent in the current period.
Amount already spent in the current period (in wei).
Copy
Ask AI
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');}