> ## Documentation Index
> Fetch the complete documentation index at: https://solana.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> This page is part of the Solana developer documentation at https://solana.com/developers/docs. Append `.md` to any docs URL, or send `Accept: text/markdown`, to get the page as Markdown.
> Index of all pages: https://solana.com/llms.txt. Per-section indexes such as https://solana.com/developers/docs/payments/llms.txt are smaller; prefer them when working on one task.
> Coding agents: install the official Solana skill for current APIs and conventions with `npx skills add https://github.com/solana-foundation/solana-dev-skill` (also served at https://solana.com/SKILL.md).
> Code in the cookbook and task pages comes from tested example files. Prefer it over writing API calls from memory.

# EIP-712 on Solana: Signing and Verifying Messages

> Replace EIP-712 typed data and ERC1271 with Solana offchain message signing, Ed25519 verification, and PDA signing.

EIP-712 defines how Ethereum wallets sign structured data so that users can read
what they approve and contracts can verify it. Solana wallets sign messages with
the account's Ed25519 key, and programs verify those signatures through a
signature verification instruction.

## What EIP-712 defines

EIP-712 hashes a typed struct together with a domain separator that names the
app, the chain ID, and the verifying contract. Wallets display the fields, and a
contract recovers the signer with `ecrecover`. It underlies permits, order
books, and gasless flows. ERC1271 extends verification to contract wallets
through `isValidSignature`.

## Message signing on Solana

Solana wallets [sign messages](/developers/docs/frontend/messages-and-auth) in
two ways. Use offchain messages where the wallet supports them, and fall back to
raw messages where it does not.

<Columns cols={2}>
<Card title="Offchain messages: solana:signOffchainMessage">

- Wraps your text in a standard format.
- Cannot be mistaken for a transaction.
- Names the accounts that must sign. It is the format hardware wallets can sign,
  though support depends on the device.

</Card>
<Card title="Raw messages: solana:signMessage">

- Signs exactly the bytes your app passes in.
- Supported by most software wallets.
- Nothing in the bytes marks them as a message.

</Card>
</Columns>

| Piece | EIP-712 | Solana |
| --- | --- | --- |
| Signature scheme | secp256k1 | Ed25519 |
| Message format | Typed structs hashed with a domain separator | An offchain message envelope around your text |
| Domain binding | Chain ID and verifying contract in the domain | Fields you include in the message, such as your domain and program ID |
| Onchain verification | `ecrecover` in the contract | An Ed25519 verification instruction that your program inspects |
| Contract wallets | ERC1271 `isValidSignature` | PDAs sign onchain through CPIs |

## Verify a signature on your server

For sign-in and other offchain actions, your backend verifies the signature. No
transaction or fee is involved.

<Steps>
<Step title="Server issues a challenge">

It includes your domain, a nonce, and an expiry time.

</Step>
<Step title="Wallet signs">

The user approves the message in their wallet.

</Step>
<Step title="Server verifies">

It checks the Ed25519 signature against the user's address.

</Step>
<Step title="Server consumes the nonce">

It rejects a second use of the same message.

</Step>
</Steps>

## Verify a signature in a program

Verifying an Ed25519 signature inside a program costs too much compute, and the
verification program cannot be called through a CPI. Instead, the transaction
includes an instruction for the Ed25519 signature verification program, and your
program uses [instruction
introspection](/developers/docs/core/instructions/instruction-introspection) to
confirm that the instruction checked the expected signer and message. With an
offchain message, the signed bytes include the signing domain, the version, and
the signer list before your text, so pass the full signed message to the
verification instruction and parse it in your program.

<Steps>
<Step title="User signs a message">

For example, an order with a price and an expiry.

</Step>
<Step title="Relayer builds a transaction">

It adds the verification instruction, then your program's instruction.

</Step>
<Step title="Runtime verifies">

The transaction fails if the signature is invalid.

</Step>
<Step title="Program inspects">

It reads the verification instruction and compares the signer and the signed
bytes with the values it expects.

</Step>
</Steps>

<Warning>

**Check the contents of the verification instruction**

A verification instruction can point at data in another instruction, so its
presence proves nothing. Confirm its program ID, that it holds exactly the
number of signatures you expect, and that each offset's instruction index points
at the verification instruction itself. Then compare the public key and the
message bytes at those offsets with the values you expect. Load instructions
only from the real Instructions sysvar address.

</Warning>

## Design the message

EIP-712's domain separator prevents a signature from being replayed on another
app or chain. On Solana, put the same protections in the message itself.

- Include your app's domain and the program ID that will consume the signature.
- Include the cluster, so a Devnet signature cannot be used on Mainnet.
- Include a nonce that your program or server marks as used.
- Include an expiry time and reject messages after it.
- Write the message so a person can read what they are approving.

## Signatures from programs

ERC1271 exists because a contract wallet has no private key. A Solana program
has none either, and it does not need an offchain signature: it authorizes
actions onchain by signing for its [PDAs](/developers/docs/core/pda) in a
cross-program invocation. If a multisig or smart wallet must approve an offchain
message, have its members sign and verify their signatures against the wallet's
stored owners.

## Next steps

<Columns cols={3}>
<Card title="Messages and auth" href="/developers/docs/frontend/messages-and-auth" arrow>

Sign and verify messages with tested code.

</Card>
<Card title="EIP-2612 on Solana" href="/developers/docs/migrate-to-solana/ethereum/standards/eip2612">

Replace permit signatures with one transaction.

</Card>
<Card title="ERC4337 on Solana" href="/developers/docs/migrate-to-solana/ethereum/standards/erc4337">

Build a smart wallet with PDAs.

</Card>
</Columns>
