For AI agents: a documentation index is available at /llms.txt. A markdown version of this page is available at the same URL with .md appended (or via Accept: text/markdown).
Skip to main content

Caveat Enforcer Client reference

The following API methods are related to CaveatEnforcerClient used to check the delegation state.

createCaveatEnforcerClient​

Create a Viem Client extended with caveat enforcer actions. This client allows you to interact with the caveat enforcers of the delegation, and read the required state.

Parameters​

NameTypeRequiredDescription
clientClientYesThe Viem Client to interact with the caveat enforcer contracts and read their state.
environmentSmartAccountsEnvironmentYesEnvironment to resolve the smart contracts for the current chain.

Example​

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

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

getErc20PeriodTransferEnforcerAvailableAmount​

Returns the available amount from the ERC-20 period transfer enforcer for the current period.

Parameters​

NameTypeRequiredDescription
delegationDelegationYesThe delegation object for which you want to check the available amount.

Example​

import { delegation } './config.ts'

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

getErc20StreamingEnforcerAvailableAmount​

Returns the available amount from the ERC-20 streaming enforcer.

Parameters​

NameTypeRequiredDescription
delegationDelegationYesThe delegation object for which you want to check the available amount.

Example​

import { delegation } './config.ts'

// Returns the available amount
const { availableAmount } = await caveatEnforcerClient.getErc20StreamingEnforcerAvailableAmount({
delegation,
})

getNativeTokenPeriodTransferEnforcerAvailableAmount​

Returns the available amount from the native token period enforcer for the current period.

Parameters​

NameTypeRequiredDescription
delegationDelegationYesThe delegation object for which you want to check the available amount.

Example​

import { delegation } './config.ts'

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

getNativeTokenStreamingEnforcerAvailableAmount​

Returns the available amount from the native streaming enforcer.

Parameters​

NameTypeRequiredDescription
delegationDelegationYesThe delegation object for which you want to check the available amount.

Example​

import { delegation } './config.ts'

// Returns the available amount
const { availableAmount } = await caveatEnforcerClient.getNativeTokenStreamingEnforcerAvailableAmount({
delegation,
})

getMultiTokenPeriodEnforcerAvailableAmount​

Returns the available amount from the multi token period transfer enforcer for the current period. You'll need to encode the arguments for the token index you want to check the available amount.

Parameters​

NameTypeRequiredDescription
delegationDelegationYesThe delegation object with token index for which you want to check the available amount.

Example​

import { delegation } './config.ts'

// Encode the args for the multiTokenPeriod enforcer.
const args = encodePacked(['uint256'], [BigInt(0)]);

// Ensure the index is correct when working with multiple enforcers.
delegation.caveats[0].args = args

// Returns the available amount for the first token in the list.
const { availableAmount } = await caveatEnforcerClient.getMultiTokenPeriodEnforcerAvailableAmount({
delegation,
})