Skip to main content
  • Snap
  • Restricted

snap_dialog

Description

Display a dialog in the MetaMask UI.

  • type - The type of dialog. Not providing a type will create a fully custom dialog. Possible values are:

    • alert - An alert that can only be acknowledged.
    • confirmation - A confirmation that can be accepted or rejected.
    • prompt - A prompt where the user can enter a text response.
  • One of:

  • placeholder - An optional placeholder text to display in the dialog. Only applicable for the prompt dialog.

Parameters

union

An object containing the contents of the dialog.

Options

union

An alert dialog.

Options

object
required

content

JSXElement
required

The content to display in the alert dialog.

or

object
required

id

string
required

The Snap interface ID, which can be used to display a previously created interface. See snap_createInterface.

Common properties

type

"alert"
required

The literal string "alert" to indicate that this is an alert dialog.

or

union

A confirmation dialog.

Options

object
required

content

JSXElement
required

The content to display in the confirmation dialog.

or

object
required

id

string
required

The Snap interface ID, which can be used to display a previously created interface. See snap_createInterface.

Common properties

type

"confirmation"
required

The literal string "confirmation" to indicate that this is a confirmation dialog.

or

union

A prompt dialog.

Options

object
required

content

JSXElement
required

The content to display in the prompt dialog.

or

object
required

id

string
required

The Snap interface ID, which can be used to display a previously created interface. See snap_createInterface.

Common properties

type

"prompt"
required

The literal string "prompt" to indicate that this is a prompt dialog.

placeholder

string

An optional placeholder text to display in the text input.

or

union

Options

object
required

id

string
required

or

object
required

content

JSXElement
required

Returns

JSON
  • If the dialog is an alert, the result is null.
  • If the dialog is a confirmation, the result is a boolean indicating whether the user confirmed the dialog.
  • If the dialog is a prompt, the result is the value entered by the user.

Example

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

const walletAddress = await snap.request({
method: "snap_dialog",
params: {
type: "prompt",
content: (
<Box>
<Heading>What is the wallet address?</Heading>
<Text>Please enter the wallet address to be monitored.</Text>
</Box>
),
placeholder: "0x123...",
},
});

// `walletAddress` will be a string containing the address entered by the
// user.