Skip to main content
  • Snap
  • Restricted

snap_dialog

Description

Display a dialog in the MetaMask UI.

Parameters

union

An object containing the contents of the dialog.

  • 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.

Options

union

An alert dialog.

Options

object

content

JSXElement
required

or

object

id

string
required

Common properties

type

"alert"
required

or

union

A confirmation dialog.

Options

object

content

JSXElement
required

or

object

id

string
required

Common properties

type

"confirmation"
required

or

union

A prompt dialog.

Options

object

content

JSXElement
required

or

object

id

string
required

Common properties

type

"prompt"
required

placeholder

string

or

union

Options

object

id

string
required

or

object

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.