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:
content- The content of the alert, as a custom UI component.id- The ID of an interactive interface.
-
placeholder- An optional placeholder text to display in the dialog. Only applicable for thepromptdialog.
Parameters
An object containing the contents of the dialog.
Options
An alert dialog.
Options
content
JSXElementThe content to display in the alert dialog.
or
id
stringThe Snap interface ID, which can be used to display a previously
created interface. See snap_createInterface.
Common properties
type
"alert"The literal string "alert" to indicate that this is an alert dialog.
or
A confirmation dialog.
Options
content
JSXElementThe content to display in the confirmation dialog.
or
id
stringThe Snap interface ID, which can be used to display a previously
created interface. See snap_createInterface.
Common properties
type
"confirmation"The literal string "confirmation" to indicate that this is a confirmation dialog.
or
A prompt dialog.
Options
content
JSXElementThe content to display in the prompt dialog.
or
id
stringThe Snap interface ID, which can be used to display a previously
created interface. See snap_createInterface.
Common properties
type
"prompt"The literal string "prompt" to indicate that this is a prompt dialog.
placeholder
stringAn optional placeholder text to display in the text input.
or
Options
id
stringor
content
JSXElementReturns
- If the dialog is an
alert, the result isnull. - 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.