If you’ve spent any time building decentralized applications (dApps) on Ethereum, you’ve probably run into typed data signatures—they’re the standard way to let users sign structured data that aligns with Ethereum’s EIP-712 specification. Without this, you’d have to work with raw, unstructured hashes that are hard for users to verify, which leads to confusion and security risks. As an Ethers.js supplier, I’ve helped dozens of teams implement this workflow smoothly, so I’m breaking down exactly how to sign typed data with Ethers.js, step by step, with real-world context and pitfalls to avoid. Ethers

First, let’s ground this: EIP-712 was created to solve a critical problem with early Ethereum signatures. Before it, signing arbitrary messages would just hash the raw input, which gave users no context for what they were approving. Typed data lets you define a structured format—like “a transfer of 100 USDC to 0x123…” or a user’s NFT minting authorization—so the wallet (MetaMask, Coinbase Wallet, etc.) can display a human-readable summary to the user before they sign. Ethers.js simplifies this workflow, but there are a few key details that trip up even experienced developers.
To start, make sure you have Ethers.js installed. For most projects, we recommend Ethers v6, as it’s the most stable and widely adopted version right now. If you’re using npm, you’d run: npm install ethers. For yarn: yarn add ethers. If you’re working in a browser or a frontend framework like React, you can import it like this: import { ethers } from "ethers";. A common mistake here is mixing up Ethers v5 and v6 syntax—if you’re supporting older dApps, we have Ethers v5 packages available, but all new implementations should use v6.
Next, you need a signer. The signer is the object that holds the user’s private key (or is connected to their wallet) and will authorize the signature. In most frontend dApps, you’ll get a signer from the user’s connected wallet. For example, if you’re using MetaMask, you can request the provider and get the signer like this:
const provider = new ethers.BrowserProvider(window.ethereum);
const signer = await provider.getSigner();
This is a fundamental step—without a valid signer connected to a user’s wallet, you can’t perform any signature action. One thing to note here: window.ethereum is the standard Ethereum provider injected by browsers like MetaMask, but you should always check if it exists before calling this code. If it doesn’t, you can prompt the user to install a wallet, which is a basic part of dApp onboarding.
Now, the core part: defining the typed data. EIP-712 requires three key pieces to work correctly: the domain, the types, and the value. Let’s break each down with a concrete example, so it’s easy to follow. Let’s say we’re building a dApp that lets users sign a request to transfer 0.5 ETH to a recipient. That typed data would look like this:
Domain: This is metadata about the dApp itself, to prevent replay attacks across different platforms or chains. It should include the name of your app, the version of EIP-712 you’re using (almost always "1"), and the chain ID (for Ethereum mainnet, that’s 1; for Sepolia testnet, it’s 11155111, etc.). For our example, the domain would be:
{
name: "My Sample DApp",
version: "1",
chainId: 1
}
Types: This is the structured format of the data you’re asking the user to sign. It follows a specific structure, where each type is a set of field names and their types. For our transfer request, the type might be:
{
Transfer: [
{ name: "recipient", type: "address" },
{ name: "amount", type: "uint256" },
{ name: "message", type: "string" }
]
}
Valid types for EIP-712 include basic types like address, uint256, string, bool, bytes, and custom structs that reference other types. Never use unvalidated types here—incorrect type definitions will break the wallet’s display of the signature, leading users to reject it.
Value: This is the actual data you want the user to sign, which matches the structure you defined in the types. For our example, the value would be:
{
recipient: "0x742d35Cc6634C0532925a3b8D94C2bB23a09E9F",
amount: ethers.parseEther("0.5"), // We use parseEther to convert the human-readable amount to wei, which is what Ethereum uses
message: "Thank you for supporting our dApp!"
}
Notice that we’re using ethers.parseEther here, not just a plain number. That’s a crucial detail: Ethereum uses wei (1 ETH = 10^18 wei) for all monetary values, so you always need to convert user-facing amounts to the smallest unit before passing them to typed data. If you skip this, you’ll get errors about invalid uint256 values, or even worse, the user will sign the wrong amount.
Once you have all three pieces (domain, types, value), you can use Ethers.js’s signTypedData method. In Ethers v6, that method is part of the signer object, so it’s as simple as:
const signature = await signer.signTypedData(domain, types, value);
Wait—but hold on. A common mistake here is not matching the types exactly. For example, if your Transfer type defines amount as uint256, but you pass a string instead of a bigint or hex string, Ethers.js will throw an error. Also, make sure the name of your type (like "Transfer") is consistent across the types object and the value. Mismatched names here will cause the signature to be invalid when you verify it on-chain.
Let’s test this with a full working example, so you can see how it all comes together. Here’s the complete code for our transfer signature:
import { ethers } from "ethers";
// Connect to MetaMask and get the signer
async function connectWallet() {
if (!window.ethereum) {
throw new Error("Please install MetaMask to use this feature");
}
const provider = new ethers.BrowserProvider(window.ethereum);
await provider.send("eth_requestAccounts", []); // Prompt user to connect their wallet
const signer = await provider.getSigner();
return signer;
}
// Sign typed transfer data
async function signTransfer(signer, recipient, amount, message) {
// Define EIP-712 domain
const domain = {
name: "My Sample DApp",
version: "1",
chainId: 1, // Use 11155111 for Sepolia testnet
};
// Define the type structure
const types = {
Transfer: [
{ name: "recipient", type: "address" },
{ name: "amount", type: "uint256" },
{ name: "message", type: "string" },
],
};
// Define the value to sign
const value = {
recipient: recipient,
amount: ethers.parseEther(amount),
message: message,
};
// Sign the typed data
const signature = await signer.signTypedData(domain, types, value);
return signature;
}
// Usage: Connect wallet, then sign a transfer
async function runWorkflow() {
try {
const signer = await connectWallet();
const recipient = "0x742d35Cc6634C0532925a3b8D94C2bB23a09E9F";
const amount = "0.5";
const message = "Thank you for supporting our dApp!";
const signature = await signTransfer(signer, recipient, amount, message);
console.log("Signature:", signature);
} catch (error) {
console.error("Error:", error.message);
}
}
runWorkflow();
This code works in a browser with MetaMask installed. When you run it, MetaMask will pop up a dialog showing the structured data: it will say “My Sample DApp”, then list the recipient address, 0.5 ETH, and the message, so the user can confirm they’re signing the right thing. That’s the key benefit of EIP-712—no more vague “sign a message” prompts that users ignore or blindly approve.
But wait—what if you’re working with a contract instead of a user’s wallet? For example, if you need to sign typed data off-chain and verify it on-chain, not just with a wallet. Ethers.js can handle that too, using a wallet signer (not BrowserProvider) for local signing. That’s useful for backends or scripts that need to generate signatures without user interaction. Here’s a quick example of that:
import { ethers } from "ethers";
// Create a wallet from a private key (for backend use only—never expose private keys in frontend code)
const privateKey = "0xYourPrivateKeyHere"; // Replace with your actual private key, stored securely
const wallet = new ethers.Wallet(privateKey);
// Define the same domain, types, and value as before
const domain = { name: "My Sample DApp", version: "1", chainId: 1 };
const types = { Transfer: [{ name: "recipient", type: "address" }, { name: "amount", type: "uint256" }, { name: "message", type: "string" }] };
const value = { recipient: "0x742d35Cc6634C0532925a3b8D94C2bB23a09E9F", amount: ethers.parseEther("0.5"), message: "Thank you for supporting our dApp!" };
// Sign typed data with the wallet
const signature = await wallet.signTypedData(domain, types, value);
This is great for backend workflows, but as a reminder: never hardcode private keys in frontend code. If you need to generate signatures in a frontend, always use a wallet signer like BrowserProvider, which keeps the private key local to the user’s device.
Now, let’s talk about common pitfalls I’ve seen as an Ethers.js supplier, because even small mistakes can break your signature. First, chain ID mismatches. The domain’s chainId must match the chain the user is connected to. If a user is on Sepolia (chain ID 11155111) and your domain uses chainId 1 (Ethereum mainnet), the signature will be invalid when verified on-chain. To avoid this, you can get the active chain ID from the provider automatically:
const chainId = await provider.getChainId();
const domain = { name: "My Sample DApp", version: "1", chainId };
That way, the domain is always in sync with the user’s current network. Second, missing or incorrect EIP-712 types. If you have a custom struct type, like a “User” type that has a “name” string and “age” uint256, you need to define it in the types object as a separate entry, not as a top-level field. For example, if your typed data is a “Message” that has a “sender” of type “User”, your types would look like this:
const types = {
User: [ { name: "name", type: "string" }, { name: "age", type: "uint256" } ],
Message: [ { name: "sender", type: "User" }, { name: "text", type: "string" } ]
};
If you don’t define the “User” type, Ethers.js will throw an error when you try to sign, because it doesn’t recognize the custom struct. Third, using v5 syntax in a v6 project. A lot of old tutorials use Ethers v5, where the signTypedData method was called signTypedData_v4, and the provider was created with new ethers.providers.Web3Provider. In v6, the syntax is streamlined, so if you’re using a newer version, make sure you’re following v6 docs, not outdated v5 ones.
Another use case we support frequently at our Ethers.js services is signing typed data for NFT minting, token approvals, and permit functions. For example, EIP-2612’s Permit function uses typed data to let users approve token transfers without sending a transaction, which saves gas. Implementing that with Ethers.js follows the exact same pattern as our transfer example: you define the domain with the token’s name and chain ID, define the Permit type, pass the value with the owner, spender, and amount, and sign it. That’s one of the most common use cases for typed data, and Ethers.js makes it straightforward to implement.
Now, let’s cover verification, because signing is only half the story. Once you have a signature, you’ll need to verify it to make sure it’s valid. Ethers.js has a verifyTypedData method for this, which takes the domain, types, value, and signature, and returns the address of the signer. For example:
const signerAddress = await signer.getAddress(); // We can get the signer’s address to compare
const recoveredAddress = ethers.verifyTypedData(domain, types, value, signature);
console.log(recoveredAddress === signerAddress); // This will be true if the signature is valid
This is useful for backend checks, or for confirming that a signature came from the expected address. If the recovered address doesn’t match the expected one, the signature is tampered with or invalid, so you should reject it.
As an Ethers.js supplier, we also handle custom implementations for teams that need extra functionality. For example, some dApps need to sign typed data with multiple signers, or with hardware wallets like Ledger, which have slightly different requirements. Ethers.js supports both of these: for multiple signers, you can sign each part of the typed data separately and aggregate the signatures, and for hardware wallets, you just use the same BrowserProvider pattern—Ledger will prompt the user to confirm the typed data as usual, no extra work needed.
Before you wrap up your implementation, there are a few security best practices to keep in mind. First, always display the structured data to the user before they sign. Don’t rely on the wallet to show it—you should also log or display the data in your dApp to give the user a second chance to review. Second, never sign data that includes sensitive information like private keys or mnemonics. Typed data signatures are designed for public actions, so avoid putting private data in the value. Third, test across multiple wallets. Some older wallets have limited support for EIP-712, so make sure your code works with MetaMask, Coinbase Wallet, WalletConnect, and any other wallets your users might use.

If you’re looking to implement typed data signatures in your dApp, but don’t have the in-house expertise to handle edge cases, syntax differences across Ethers versions, or wallet compatibility, our Ethers.js solutions are built to streamline this process. We offer custom Ethers.js implementations, testing support for multiple chains and wallets, and ongoing maintenance to keep your signature workflows secure and up-to-date. Whether you need a simple transfer signature or a complex multi-sig typed data setup, our team has the experience to deliver a solution that fits your needs. To discuss your requirements and get a custom quote for Ethers.js services, please reach out to our team.
Esters References
Ethers.js Official Documentation
EIP-712: Ethereum Structured Data Signing Specification
Ethers.js Signer API Documentation
EIP-2612: Permit Extension for ERC-20 Tokens
Qingdao Jinforest Chem Tech Co., Ltd.
Qingdao Jinforest Chem Tech Co., Ltd. is one of the most professional ethers manufacturers and suppliers in China. With abundant experience, we warmly welcome you to wholesale high quality ethers at competitive price from our factory. If you have any enquiry about quotation, please feel free to email us.
Address: Huangdao District, Qingdao City, Shandong Province (3002, Unit 1, Block B, No.226 Changjiang Middle Road, Former Development Zone)
E-mail: cecilia@kozorigin.com
WebSite: https://www.jinforestchem.com/