> For the complete documentation index, see [llms.txt](/llms.txt).

# Check the delegation state

When using [spending limit delegation scopes](/smart-accounts-kit/development/guides/delegation/use-delegation-scopes/spending-limit/) or relevant [caveat enforcers](/smart-accounts-kit/development/reference/delegation/caveats/), you might need to check the remaining transferrable amount in a delegation. For example, if a delegation allows a user to spend 10 USDC per week and they have already spent 10 - n USDC in the current period, you can determine how much of the allowance is still available for transfer.

Use the `CaveatEnforcerClient` to check the available balances for specific scopes or caveats.

## Prerequisites[​](#prerequisites "Direct link to Prerequisites")

- [Install and set up the Smart Accounts Kit.](/smart-accounts-kit/development/get-started/install/)
- [Create a delegator account.](/smart-accounts-kit/development/guides/delegation/execute-on-smart-accounts-behalf/#3-create-a-delegator-account)
- [Create a delegate account.](/smart-accounts-kit/development/guides/delegation/execute-on-smart-accounts-behalf/#4-create-a-delegate-account)
- [Create a delegation with an ERC-20 periodic scope.](/smart-accounts-kit/development/guides/delegation/use-delegation-scopes/spending-limit/#erc-20-periodic-scope)

## Create a `CaveatEnforcerClient`[​](#create-a-caveatenforcerclient "Direct link to create-a-caveatenforcerclient")

To check the delegation state, create a [CaveatEnforcerClient](/smart-accounts-kit/development/reference/delegation/caveat-enforcer-client/). This client allows you to interact with the [caveat enforcers](/smart-accounts-kit/development/reference/glossary#caveat-enforcer)**Caveat enforcer** A smart contract that enforces delegation rules by validating caveat conditions during redemption hooks. of the delegation, and read the required state.

- example.ts
- config.ts

```
import { environment, publicClient as client } from './config.ts'
import { createCaveatEnforcerClient } from '@metamask/smart-accounts-kit'

const caveatEnforcerClient = createCaveatEnforcerClient({
  environment,
  client,
})

```

```
import { sepolia as chain } from 'viem/chains'
import { createPublicClient, http } from 'viem'
import { getSmartAccountsEnvironment } from '@metamask/smart-accounts-kit'

export const environment = getSmartAccountsEnvironment(chain.id)

export const publicClient = createPublicClient({
  chain,
  transport: http(),
})

```

## Read the caveat enforcer state[​](#read-the-caveat-enforcer-state "Direct link to Read the caveat enforcer state")

This example uses the [getErc20PeriodTransferEnforcerAvailableAmount](/smart-accounts-kit/development/reference/delegation/caveat-enforcer-client/#geterc20periodtransferenforceravailableamount) method to read the state and retrieve the remaining amount for the current transfer period.

- example.ts
- config.ts

```
import { delegation } from './config.ts'

// Returns the available amount for current period.
const { availableAmount } =
  await caveatEnforcerClient.getErc20PeriodTransferEnforcerAvailableAmount({
    delegation,
  })

```

```
import { createDelegation, ScopeType } from '@metamask/smart-accounts-kit'
import { parseUnits } from 'viem'

// startDate should be in seconds.
const startDate = Math.floor(Date.now() / 1000)

export const delegation = createDelegation({
  scope: {
    type: ScopeType.Erc20PeriodTransfer,
    tokenAddress: '0xb4aE654Aca577781Ca1c5DE8FbE60c2F423f37da',
    periodAmount: parseUnits('10', 6),
    periodDuration: 86400,
    startDate,
  },
  to: delegateAccount,
  from: delegatorAccount,
  environment: delegatorAccount.environment,
})

```

## Next steps[​](#next-steps "Direct link to Next steps")

See the [Caveat Enforcer Client reference](/smart-accounts-kit/development/reference/delegation/caveat-enforcer-client/) for the full list of available methods.
