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

# x402 API reference

The following API methods are related to x402 to create payments using [delegation](/smart-accounts-kit/development/reference/glossary#delegation)**Delegation** The ability for a MetaMask smart account to authorize another account to perform specific executions on its behalf..

## `createx402DelegationProvider`[​](#createx402delegationprovider "Direct link to createx402delegationprovider")

Creates a delegation provider function to be used with `x402Erc7710Client`.

The provider creates an [open delegation](/smart-accounts-kit/development/reference/glossary#open-delegation)**Open delegation** A delegation that leaves the delegate unspecified, allowing any account to redeem it., signs it, and returns an ABI-encoded delegation chain as a hex string. The provider internally appends redeemer, payee, and expiry [caveats](/smart-accounts-kit/development/reference/glossary#caveat)**Caveat** A restriction attached to a delegation that limits how delegated authority can be used. when the existing caveats, or the [root delegation](/smart-accounts-kit/development/reference/glossary#root-delegation)**Root delegation** The first delegation in a chain, where an account delegates its own authority directly. doesn't have it.

When both `redeemers.addresses` and `facilitatorAddresses` from the server's payment requirements are provided, the provider resolves redeemers as the intersection of the two lists. If only one is provided, that list is used. An error is thrown if the resolved list is empty.

### Parameters[​](#parameters "Direct link to Parameters")

| Name                    | Type                                                                                                                                                            | Required | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| ----------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| account                 | [MaybeDeferred](/smart-accounts-kit/reference/types/#maybedeferred)<Account>                                                                                    | Yes      | The Viem Account that signs the [delegation](/smart-accounts-kit/development/reference/glossary#delegation)**Delegation** The ability for a MetaMask smart account to authorize another account to perform specific executions on its behalf..                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| environment             | [MaybeDeferred](/smart-accounts-kit/reference/types/#maybedeferred)<[SmartAccountsEnvironment](/smart-accounts-kit/reference/types/#smartaccountsenvironment)\> | No       | Environment to resolve the smart contracts for the current chain. If omitted, resolved automatically from the chain ID in the payment requirements.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| from                    | [MaybeDeferred](/smart-accounts-kit/reference/types/#maybedeferred)<Hex>                                                                                        | No       | The address that is granting the [delegation](/smart-accounts-kit/development/reference/glossary#delegation)**Delegation** The ability for a MetaMask smart account to authorize another account to perform specific executions on its behalf.. The default is account.                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| salt                    | [MaybeDeferred](/smart-accounts-kit/reference/types/#maybedeferred)<Hex>                                                                                        | No       | The salt for generating the delegation hash. The default is a random 32-byte value.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| caveats                 | [MaybeDeferred](/smart-accounts-kit/reference/types/#maybedeferred)<Caveats>                                                                                    | No       | [Caveats](/smart-accounts-kit/development/reference/glossary#caveat)**Caveat** A restriction attached to a delegation that limits how delegated authority can be used. that further refine the authority granted by the [delegation](/smart-accounts-kit/development/reference/glossary#delegation)**Delegation** The ability for a MetaMask smart account to authorize another account to perform specific executions on its behalf.. [redeemer](/smart-accounts-kit/reference/delegation/caveats/#redeemer), [allowedTargets](/smart-accounts-kit/reference/delegation/caveats/#allowedtargets), and [timestamp](/smart-accounts-kit/reference/delegation/caveats/#timestamp) caveats are auto-appended if not already present. |
| parentPermissionContext | [MaybeDeferred](/smart-accounts-kit/reference/types/#maybedeferred)<PermissionContext>                                                                          | No       | Parent chain as Hex or as decoded [Delegation](/smart-accounts-kit/reference/types/#delegation) values (leaf first). Use this when creating a [redelegation](/smart-accounts-kit/development/reference/glossary#redelegation)**Redelegation** A delegation that passes on authority granted by a previous delegation..                                                                                                                                                                                                                                                                                                                                                                                                            |
| expirySeconds           | [MaybeDeferred](/smart-accounts-kit/reference/types/#maybedeferred)<number>                                                                                     | No       | Relative expiry in seconds. Adds a timestamp caveat if no tighter constraint exists.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| redeemers               | [MaybeDeferred](/smart-accounts-kit/reference/types/#maybedeferred)<[RedeemersConfig](/smart-accounts-kit/reference/types/#redeemersconfig)\>                   | No       | Constrains the addresses that are allowed to redeem the [delegation](/smart-accounts-kit/development/reference/glossary#delegation)**Delegation** The ability for a MetaMask smart account to authorize another account to perform specific executions on its behalf.. Use this to restrict redemption to specific facilitators.                                                                                                                                                                                                                                                                                                                                                                                                  |

### Example[​](#example "Direct link to Example")

- Delegation
- Redelegation

```
import { privateKeyToAccount } from 'viem/accounts'
import { createx402DelegationProvider } from '@metamask/smart-accounts-kit/experimental'
import { x402Erc7710Client } from '@metamask/x402'

const account = privateKeyToAccount(privateKey)

const erc7710Client = new x402Erc7710Client({
  delegationProvider: createx402DelegationProvider({
    account,
  }),
})

```

```
import { createx402DelegationProvider } from '@metamask/smart-accounts-kit/experimental'

const parentPermissionContext = '0x...' // Previously stored/issued permission context.

const delegationProvider = createx402DelegationProvider({
  account,
  parentPermissionContext,
})

```

## `parseEip155ChainId`[​](#parseeip155chainid "Direct link to parseeip155chainid")

Parses an [EIP-155 CAIP](https://namespaces.chainagnostic.org/eip155/caip2) network identifier into a numeric chain ID.

### Parameters[​](#parameters-1 "Direct link to Parameters")

| Name    | Type   | Required | Description                                             |
| ------- | ------ | -------- | ------------------------------------------------------- |
| network | string | Yes      | EIP-155 CAIP network identifier. For example, eip155:1. |

### Example[​](#example-1 "Direct link to Example")

```
import { parseEip155ChainId } from '@metamask/smart-accounts-kit/experimental'

// Returns 137
const chainId = parseEip155ChainId('eip155:137')

```
