Skip to main content
  • Snap
  • Restricted

snap_dialog

Description

Display a dialog in the MetaMask UI.

Parameters

{ content: JSXElement } | { id: string } | { type: "alert"; content: JSXElement } | { type: "alert"; id: string } | { type: "confirmation"; content: JSXElement } | { type: "confirmation"; id: string } | { type: "prompt"; content: JSXElement; placeholder?: string | null } | { type: "prompt"; id: string; placeholder?: string | null }

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.

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.