import { useSolana } from "@phantom/react-sdk";
function SignMessage() {
const solana = useSolana();
const handleSign = async () => {
const message = new TextEncoder().encode("Hello from my dApp!");
try {
const { signature } = await solana.signMessage(message);
console.log("Signature:", signature);
} catch (error) {
console.error("Signing failed:", error);
}
};
return <button onClick={handleSign}>Sign Message</button>;
}
async function signMessage(sdk: BrowserSDK) {
const message = new TextEncoder().encode("Hello from my dApp!");
try {
const { signature } = await sdk.solana.signMessage(message);
console.log("Signature:", signature);
} catch (error) {
console.error("Signing failed:", error);
}
}
For Ethereum/EVM chains, use signPersonalMessage:
import { useEthereum } from "@phantom/react-sdk";
function SignEVMMessage() {
const ethereum = useEthereum();
const handleSign = async () => {
try {
const { signature } = await ethereum.signPersonalMessage("Hello from my dApp!");
console.log("Signature:", signature);
} catch (error) {
console.error("Signing failed:", error);
}
};
return <button onClick={handleSign}>Sign EVM Message</button>;
}
SIWS provides a standardized authentication flow — proving wallet ownership to your backend:
import { useSolana, useAccounts } from "@phantom/react-sdk";
function SignInWithSolana() {
const solana = useSolana();
const { accounts } = useAccounts();
const handleSIWS = async () => {
const solanaAccount = accounts.find((a) => a.chain === "solana");
if (!solanaAccount) return;
// Construct the SIWS message
const domain = window.location.host;
const uri = window.location.origin;
const nonce = await fetch("/api/auth/nonce").then((r) => r.text()); // Must be server-issued
const issuedAt = new Date().toISOString();
const message = [
`${domain} wants you to sign in with your Solana account:`,
solanaAccount.address,
"",
"Sign in to access your account.",
"",
`URI: ${uri}`,
`Version: 1`,
`Nonce: ${nonce}`,
`Issued At: ${issuedAt}`,
].join("\n");
try {
const { signature } = await solana.signMessage(
new TextEncoder().encode(message)
);
// Send signature + message to your backend for verification
const response = await fetch("/api/auth/verify", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
message,
signature,
publicKey: solanaAccount.address,
}),
});
if (response.ok) {
console.log("Authenticated successfully!");
}
} catch (error) {
console.error("SIWS failed:", error);
}
};
return <button onClick={handleSIWS}>Sign in with Solana</button>;
}
| Chain | Method | Input | Output |
|---|---|---|---|
| Solana | solana.signMessage(bytes) | Uint8Array | { signature } |
| Ethereum | ethereum.signPersonalMessage(msg) | string | { signature } |
signMessage expects a Uint8Array — use new TextEncoder().encode(...) to convert strings.signPersonalMessage accepts a plain string.Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Set up and use 1Password CLI (op). Use when installing the CLI, enabling desktop app integration, signing in (single or multi-account), or reading/injecting/running secrets via op.
CLI to manage emails via IMAP/SMTP. Use `himalaya` to list, read, write, reply, forward, search, and organize emails from the terminal. Supports multiple accounts and message composition with MML (MIME Meta Language).
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Set up and use 1Password CLI (op). Use when installing the CLI, enabling desktop app integration, signing in (single or multi-account), or reading/injecting/running secrets via op.
CLI to manage emails via IMAP/SMTP. Use `himalaya` to list, read, write, reply, forward, search, and organize emails from the terminal. Supports multiple accounts and message composition with MML (MIME Meta Language).