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

# Snaps entry points

Snaps can expose the following entry points.

## `onCronjob`[​](#oncronjob "Direct link to oncronjob")

To run [cron jobs](/snaps/features/cron-jobs/) for the user, a Snap must expose the `onCronjob` entry point. MetaMask calls the `onCronjob` handler method at the specified schedule with the requests defined in the [endowment:cronjob](/snaps/reference/permissions/#endowmentcronjob) permission.

note

For MetaMask to call the Snap's `onCronjob` method, you must request the [endowment:cronjob](/snaps/reference/permissions/#endowmentcronjob) permission.

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

An object containing an RPC request specified in the `endowment:cronjob` permission.

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

- TypeScript
- JavaScript

index.ts

```
import type { OnCronjobHandler } from '@metamask/snaps-sdk'

export const onCronjob: OnCronjobHandler = async ({ request }) => {
  switch (request.method) {
    case 'exampleMethodOne':
      return snap.request({
        method: 'snap_notify',
        params: {
          type: 'inApp',
          message: 'Hello, world!',
        },
      })

    default:
      throw new Error('Method not found.')
  }
}

```

index.js

```
module.exports.onCronjob = async ({ request }) => {
  switch (request.method) {
    case 'exampleMethodOne':
      return snap.request({
        method: 'snap_notify',
        params: {
          type: 'inApp',
          message: 'Hello, world!',
        },
      })

    default:
      throw new Error('Method not found.')
  }
}

```

## `onHomePage`[​](#onhomepage "Direct link to onhomepage")

To display a [home page](/snaps/features/custom-ui/home-pages/) within MetaMask, a Snap must expose the `onHomePage` entry point. MetaMask calls the `onHomePage` handler method when the user selects the Snap name in the Snaps menu.

note

For MetaMask to call the Snap's `onHomePage` method, you must request the [endowment:page-home](/snaps/reference/permissions/#endowmentpage-home) permission.

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

None.

#### Returns[​](#returns "Direct link to Returns")

One of the following:

- A `content` object displayed using [custom UI](/snaps/features/custom-ui/).
- An `id` returned by [snap_createInterface](/snaps/reference/snaps-api/snap%5Fcreateinterface/) for [interactive UI](/snaps/features/custom-ui/interactive-ui/).

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

- JSX
- Functions

index.tsx

```
import type { OnHomePageHandler } from '@metamask/snaps-sdk'
import { Box, Heading, Text } from '@metamask/snaps-sdk/jsx'

export const onHomePage: OnHomePageHandler = async () => {
  return {
    content: (
      <Box>
        <Heading>Hello world!</Heading>
        <Text>Welcome to my Snap home page!</Text>
      </Box>
    ),
  }
}

```

index.js

```
import { panel, text, heading } from '@metamask/snaps-sdk'

module.exports.onHomePage = async () => {
  return {
    content: panel([heading('Hello world!'), text('Welcome to my Snap home page!')]),
  }
}

```

## `onInstall`[​](#oninstall "Direct link to oninstall")

To implement a [lifecycle hook](/snaps/features/lifecycle-hooks/) that runs an action upon installation, a Snap must expose the `onInstall` entry point. MetaMask calls the `onInstall` handler method after the Snap is installed successfully.

note

For MetaMask to call the Snap's `onInstall` method, you must request the [endowment:lifecycle-hooks](/snaps/reference/permissions/#endowmentlifecycle-hooks) permission.

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

None.

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

- JSX
- Functions

index.tsx

```
import type { OnInstallHandler } from '@metamask/snaps-sdk'
import { Box, Heading, Text } from '@metamask/snaps-sdk/jsx'

export const onInstall: OnInstallHandler = async () => {
  await snap.request({
    method: 'snap_dialog',
    params: {
      type: 'alert',
      content: (
        <Box>
          <Heading>Thank you for installing my Snap</Heading>
          <Text>
            To use this Snap, visit the companion dapp at{' '}
            <a href="https://metamask.io">metamask.io</a>.
          </Text>
        </Box>
      ),
    },
  })
}

```

index.js

```
import { heading, panel, text } from '@metamask/snaps-sdk'

module.exports.onInstall = async () => {
  await snap.request({
    method: 'snap_dialog',
    params: {
      type: 'alert',
      content: panel([
        heading('Thank you for installing my Snap'),
        text('To use this Snap, visit the companion dapp at [metamask.io](https://metamask.io).'),
      ]),
    },
  })
}

```

## `onKeyringRequest`[​](#onkeyringrequest "Direct link to onkeyringrequest")

To implement the [Account Management API](/snaps/reference/keyring-api/account-management/) to integrate [custom EVM accounts](/snaps/features/custom-evm-accounts/), an account management Snap must expose the `onKeyringRequest` entry point. Whenever the Snap receives an Account Management API request, MetaMask calls the `onKeyringRequest`handler method.

note

For MetaMask to call the Snap's `onKeyringRequest` method, you must request the [endowment:keyring](/snaps/reference/permissions/#endowmentkeyring) permission.

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

An object containing:

- `origin` - The origin as a string.
- `request` - The JSON-RPC request.

#### Returns[​](#returns-1 "Direct link to Returns")

A promise containing the return of the implemented method.

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

- TypeScript
- JavaScript

index.ts

```
export const onKeyringRequest: OnKeyringRequestHandler = async ({ origin, request }) => {
  // Any custom logic or extra security checks here.
  return handleKeyringRequest(keyring, request)
}

```

index.js

```
module.exports.onKeyringRequest = async ({ origin, request }) => {
  // Any custom logic or extra security checks here.
  return handleKeyringRequest(keyring, request)
}

```

## `onNameLookup`[​](#onnamelookup "Direct link to onnamelookup")

To provide [custom name resolution](/snaps/features/custom-name-resolution/), a Snap must export `onNameLookup`. Whenever a user types in the send field, MetaMask calls this method. MetaMask passes the user input to the `onNameLookup` handler method.

note

For MetaMask to call the Snap's `onNameLookup` method, you must request the [endowment:name-lookup](/snaps/reference/permissions/#endowmentname-lookup) permission.

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

An object containing:

- `chainId` - The [CAIP-2](https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-2.md)chain ID.
- `address` or `domain` - One of these parameters is defined, and the other is undefined.

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

- TypeScript
- JavaScript

index.ts

```
import type { OnNameLookupHandler } from '@metamask/snaps-sdk'

export const onNameLookup: OnNameLookupHandler = async request => {
  const { chainId, address, domain } = request

  if (address) {
    const shortAddress = address.substring(2, 5)
    const chainIdDecimal = parseInt(chainId.split(':')[1], 10)
    const resolvedDomain = `${shortAddress}.${chainIdDecimal}.test.domain`
    return { resolvedDomains: [{ resolvedDomain, protocol: 'test protocol' }] }
  }

  if (domain) {
    const resolvedAddress = '0xc0ffee254729296a45a3885639AC7E10F9d54979'
    return {
      resolvedAddresses: [{ resolvedAddress, protocol: 'test protocol', domainName: domain }],
    }
  }

  return null
}

```

index.js

```
module.exports.onNameLookup = async ({ request }) => {
  const { chainId, address, domain } = request

  if (address) {
    const shortAddress = address.substring(2, 5)
    const chainIdDecimal = parseInt(chainId.split(':')[1], 10)
    const resolvedDomain = `${shortAddress}.${chainIdDecimal}.test.domain`
    return { resolvedDomains: [{ resolvedDomain, protocol: 'test protocol' }] }
  }

  if (domain) {
    const resolvedAddress = '0xc0ffee254729296a45a3885639AC7E10F9d54979'
    return {
      resolvedAddresses: [{ resolvedAddress, protocol: 'test protocol', domainName: domain }],
    }
  }

  return null
}

```

## `onRpcRequest`[​](#onrpcrequest "Direct link to onrpcrequest")

To implement a [custom JSON-RPC API](/snaps/learn/about-snaps/apis/#custom-json-rpc-apis) to communicate with dapps and other Snaps, a Snap must expose the `onRpcRequest` entry point. Whenever the Snap receives a JSON-RPC request, MetaMask calls the `onRpcRequest` handler method.

note

For MetaMask to call the Snap's `onRpcRequest` method, you must request the [endowment:rpc](/snaps/reference/permissions/#endowmentrpc) permission.

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

An object containing:

- `origin` - The origin as a string.
- `request` - The JSON-RPC request.

#### Returns[​](#returns-2 "Direct link to Returns")

A promise containing the return of the implemented method.

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

- TypeScript
- JavaScript

index.ts

```
import type { OnRpcRequestHandler } from '@metamask/snaps-sdk'

export const onRpcRequest: OnRpcRequestHandler = async ({ origin, request }) => {
  switch (request.method) {
    case 'hello':
      return 'world!'

    default:
      throw new Error('Method not found.')
  }
}

```

index.js

```
module.exports.onRpcRequest = async ({ origin, request }) => {
  switch (request.method) {
    case 'hello':
      return 'world!'

    default:
      throw new Error('Method not found.')
  }
}

```

## `onSignature`[​](#onsignature "Direct link to onsignature")

To provide [signature insights](/snaps/features/signature-insights/) before a user signs a message, a Snap must expose the `onSignature` entry point. Whenever a signing method is called, such as `personal_sign` or `eth_signTypedData_v4`, MetaMask passes the raw unsigned signature payload to the `onSignature`handler method.

note

For MetaMask to call the Snap's `onSignature` method, you must request the [endowment:signature-insight](/snaps/reference/permissions/#endowmentsignature-insight) permission.

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

An object containing:

- `signature` - The raw signature payload.
- `signatureOrigin` - The signature origin if [allowSignatureOrigin](/snaps/reference/permissions/#endowmentsignature-insight) is set to `true`.

#### Returns[​](#returns-3 "Direct link to Returns")

- An optional `severity` property that, if present, must be set to `SeverityLevel.Critical`.
- A `content` object displayed using [custom UI](/snaps/features/custom-ui/) after the user selects the **Sign** button. Due to current limitations of MetaMask's signature confirmation UI, the content will only be displayed if the `severity` property is present and set to `SeverityLevel.Critical`.

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

- JSX
- Functions

index.tsx

```
import type { OnSignatureHandler, SeverityLevel } from "@metamask/snaps-sdk";
import { Box, Heading, Text } from "@metamask/snaps-sdk/jsx";

export const onSignature: OnSignatureHandler = async ({
  signature,
  signatureOrigin,
}) => {
  const insights = /* Get insights */;
  return {
    content: (
      <Box>
        <Heading>My Signature Insights</Heading>
        <Text>Here are the insights:</Text>
        {insights.map((insight) => (
          <Text>{insight.value}</Text>
        ))}
      </Box>
    ),
    severity: SeverityLevel.Critical,
  };
};

```

index.ts

```
import type { OnSignatureHandler, SeverityLevel } from "@metamask/snaps-sdk";
import { panel, heading, text } from "@metamask/snaps-sdk";

export const onSignature: OnSignatureHandler = async ({
  signature,
  signatureOrigin,
}) => {
  const insights = /* Get insights */;
  return {
    content: panel([
      heading("My Signature Insights"),
      text("Here are the insights:"),
      ...(insights.map((insight) => text(insight.value))),
    ]),
    severity: SeverityLevel.Critical,
  };
};

```

## `onTransaction`[​](#ontransaction "Direct link to ontransaction")

To provide [transaction insights](/snaps/features/transaction-insights/) before a user signs a transaction, a Snap must expose the `onTransaction` entry point. When a user submits a transaction in the MetaMask extension, MetaMask calls the `onTransaction`handler method. MetaMask passes the raw unsigned transaction payload to `onTransaction`.

note

For MetaMask to call the Snap's `onTransaction` method, you must request the [endowment:transaction-insight](/snaps/reference/permissions/#endowmenttransaction-insight) permission.

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

An object containing:

- `transaction` - The raw transaction payload.
- `chainId` - The [CAIP-2](https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-2.md)chain ID.
- `transactionOrigin` - The transaction origin if [allowTransactionOrigin](/snaps/reference/permissions/#endowmenttransaction-insight) is set to `true`.

note

When interacting with EVM chain IDs, the provided chain ID uses the format `namespace:reference`, where the `reference` is a base 10 integer.

#### Returns[​](#returns-4 "Direct link to Returns")

- An optional `severity` property that, if present, must be set to `"critical"`. This feature is only available in Flask.
- One of the following:  
  - A `content` object displayed using [custom UI](/snaps/features/custom-ui/), alongside the confirmation for the transaction that `onTransaction` was called with.
  - An `id` returned by [snap_createInterface](/snaps/reference/snaps-api/snap%5Fcreateinterface/) for [interactive UI](/snaps/features/custom-ui/interactive-ui/).

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

- JSX
- Functions

index.tsx

```
import type { OnTransactionHandler } from "@metamask/snaps-sdk";
import { Box, Heading, Text } from "@metamask/snaps-sdk/jsx";

export const onTransaction: OnTransactionHandler = async ({
  transaction,
  chainId,
  transactionOrigin,
}) => {
  const insights = /* Get insights */;
  return {
    content: (
      <Box>
        <Heading>My Transaction Insights</Heading>
        <Text>Here are the insights:</Text>
        {insights.map((insight) => (
          <Text>{insight.value}</Text>
        ))}
      </Box>
    ),
  };
};

```

index.ts

```
import type { OnTransactionHandler } from "@metamask/snaps-sdk";
import { panel, heading, text } from "@metamask/snaps-sdk";

export const onTransaction: OnTransactionHandler = async ({
  transaction,
  chainId,
  transactionOrigin,
}) => {
  const insights = /* Get insights */;
  return {
    content: panel([
      heading("My Transaction Insights"),
      text("Here are the insights:"),
      ...(insights.map((insight) => text(insight.value))),
    ]),
  };
};

```

## `onUpdate`[​](#onupdate "Direct link to onupdate")

To implement a [lifecycle hook](/snaps/features/lifecycle-hooks/) that runs an action upon update, a Snap must expose the `onUpdate` entry point. MetaMask calls the `onUpdate` handler method after the Snap is updated successfully.

note

For MetaMask to call the Snap's `onUpdate` method, you must request the [endowment:lifecycle-hooks](/snaps/reference/permissions/#endowmentlifecycle-hooks) permission.

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

None.

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

- JSX
- Functions

index.tsx

```
import type { OnUpdateHandler } from '@metamask/snaps-sdk'
import { Box, Heading, Text } from '@metamask/snaps-sdk/jsx'

export const onUpdate: OnUpdateHandler = async () => {
  await snap.request({
    method: 'snap_dialog',
    params: {
      type: 'alert',
      content: (
        <Box>
          <Heading>Thank you for updating my Snap</Heading>
          <Text>New features added in this version:</Text>
          <Text>Added a dialog that appears when updating.</Text>
        </Box>
      ),
    },
  })
}

```

index.ts

```
import type { OnUpdateHandler } from '@metamask/snaps-sdk'
import { heading, panel, text } from '@metamask/snaps-sdk'

export const onUpdate: OnUpdateHandler = async () => {
  await snap.request({
    method: 'snap_dialog',
    params: {
      type: 'alert',
      content: panel([
        heading('Thank you for updating my Snap'),
        text('New features added in this version:'),
        text('Added a dialog that appears when updating.'),
      ]),
    },
  })
}

```

## `onUserInput`[​](#onuserinput "Direct link to onuserinput")

To respond to [interactive UI](/snaps/features/custom-ui/interactive-ui/) events, a Snap must export `onUserInput`.

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

- `id` - The ID of the interface being acted on.
- `event` - An event object containing:  
  - `type` - The type of the event. Possible values are `ButtonClickEvent`, `FormSubmitEvent`, `InputChangeEvent`, and `FileInputEvent`. These enums are exported from the `@metamask/snaps-sdk` module.
  - `name` - The name of the component that fired the event. Optional when the event type is `ButtonClickEvent`.
  - `value` - When the event type is `FormSubmitEvent`, the values in the form as an object.
- `context` - The context object passed to the interface when calling [snap_createInterface](/snaps/reference/snaps-api/snap%5Fcreateinterface/), or `null`.

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

- TypeScript
- JavaScript

index.ts

```
import type { OnUserInputHandler } from '@metamask/snaps-sdk'
import { UserInputEventType } from '@metamask/snaps-sdk'

export const onUserInput: OnUserInputHandler = async ({ id, event }) => {
  if (event.type === UserInputEventType.FormSubmitEvent) {
    console.log('The submitted form values are', event.value)
  }
}

```

index.js

```
const { UserInputEventType } = require('@metamask/snaps-sdk')

module.exports.onUserInput = async ({ id, event }) => {
  if (event.type === UserInputEventType.FormSubmitEvent) {
    console.log('The submitted form values are', event.value)
  }
}

```
