Signing a Message
When a web application is connected to Phantom, it can also request that the user signs a given message. Applications are free to write their own messages which will be displayed to users from within Phantom's signature prompt. Message signatures do not involve network fees and are a convenient way for apps to verify ownership of an address.
In order to send a message for the user to sign, a web application must:
  1. 1.
    Provide a hex or UTF-8 encoded string as a Uint8Array.
  2. 2.
    Request that the encoded message is signed via the user's Phantom wallet.
The developer sandbox provides an example of signing a message.
For more information on how to verify the signature of a message, please refer to tweetnacl-js.
signMessage()
request()
1
const message = `To avoid digital dognappers,
2
sign below to authenticate with CryptoCorgis`;
3
const encodedMessage = new TextEncoder().encode(message);
4
const signedMessage = await window.solana.signMessage(encodedMessage, "utf8");
Copied!
1
const message = `To avoid digital dognappers,
2
sign below to authenticate with CryptoCorgis`;
3
const encodedMessage = new TextEncoder().encode(message);
4
const signedMessage = await window.solana.request({
5
method: "signMessage",
6
params: {
7
message: encodedMessage,
8
display: "hex",
9
},
10
});
Copied!
Copy link