Skip to content

Latest commit

 

History

History
63 lines (47 loc) · 2 KB

File metadata and controls

63 lines (47 loc) · 2 KB
title Sign Messages on Solana - MetaMask Connect
sidebar_label Sign messages
description Request offchain cryptographic signatures from users on Solana using MetaMask Connect's signMessage Wallet Standard feature.
keywords
solana sign message
signMessage
wallet-standard
offchain signature
message verification
metamask
solana

Sign messages

Your dapp can ask users to sign a message with their Solana account; for example, to verify ownership or authorize an action.

Prerequisites

Follow the quickstart to install, initialize, and connect the Solana client.

Use solana:signMessage

Use the solana:signMessage feature to request a human-readable signature that doesn't need to be verified onchain.

The following example requests a signed message using MetaMask:

import { createSolanaClient } from '@metamask/connect-solana'

const solanaClient = await createSolanaClient({
  dapp: {
    name: 'My Solana Dapp',
    url: window.location.origin,
  },
})

const wallet = solanaClient.getWallet()

// Connect and get the user's account
const { accounts } = await wallet.features['standard:connect'].connect()

async function signMessage() {
  const message = new TextEncoder().encode('Only good humans allowed. Paw-thorize yourself.')

  const [{ signature }] = await wallet.features['solana:signMessage'].signMessage({
    account: accounts[0],
    message,
  })

  return signature
}

Next steps