{"id":3774,"date":"2026-11-23T09:50:13","date_gmt":"2026-11-23T01:50:13","guid":{"rendered":"http:\/\/www.egodaam.com\/blog\/?p=3774"},"modified":"2026-11-23T09:50:13","modified_gmt":"2026-11-23T01:50:13","slug":"how-to-sign-a-typed-data-with-ethers-js-4669-57f6d1","status":"publish","type":"post","link":"http:\/\/www.egodaam.com\/blog\/2026\/11\/23\/how-to-sign-a-typed-data-with-ethers-js-4669-57f6d1\/","title":{"rendered":"How to sign a typed data with Ethers.js?"},"content":{"rendered":"<p>If you\u2019ve spent any time building decentralized applications (dApps) on Ethereum, you\u2019ve probably run into typed data signatures\u2014they\u2019re the standard way to let users sign structured data that aligns with Ethereum\u2019s EIP-712 specification. Without this, you\u2019d 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\u2019ve helped dozens of teams implement this workflow smoothly, so I\u2019m breaking down exactly how to sign typed data with Ethers.js, step by step, with real-world context and pitfalls to avoid. <a href=\"https:\/\/www.jinforestchem.com\/ethers\/\">Ethers<\/a><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.jinforestchem.com\/uploads\/202648780\/small\/industrial-grade-ethanolebd2acf3-af8c-4369-bb5d-74a6042c9046.jpg\"><\/p>\n<p>First, let\u2019s 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\u2014like \u201ca transfer of 100 USDC to 0x123\u2026\u201d or a user\u2019s NFT minting authorization\u2014so 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.<\/p>\n<p>To start, make sure you have Ethers.js installed. For most projects, we recommend Ethers v6, as it\u2019s the most stable and widely adopted version right now. If you\u2019re using npm, you\u2019d run: npm install ethers. For yarn: yarn add ethers. If you\u2019re working in a browser or a frontend framework like React, you can import it like this: import { ethers } from &quot;ethers&quot;;. A common mistake here is mixing up Ethers v5 and v6 syntax\u2014if you\u2019re supporting older dApps, we have Ethers v5 packages available, but all new implementations should use v6.<\/p>\n<p>Next, you need a signer. The signer is the object that holds the user\u2019s private key (or is connected to their wallet) and will authorize the signature. In most frontend dApps, you\u2019ll get a signer from the user\u2019s connected wallet. For example, if you\u2019re using MetaMask, you can request the provider and get the signer like this:<\/p>\n<p>const provider = new ethers.BrowserProvider(window.ethereum);<br \/>\nconst signer = await provider.getSigner();<\/p>\n<p>This is a fundamental step\u2014without a valid signer connected to a user\u2019s wallet, you can\u2019t 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\u2019t, you can prompt the user to install a wallet, which is a basic part of dApp onboarding.<\/p>\n<p>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\u2019s break each down with a concrete example, so it\u2019s easy to follow. Let\u2019s say we\u2019re building a dApp that lets users sign a request to transfer 0.5 ETH to a recipient. That typed data would look like this:<\/p>\n<p>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\u2019re using (almost always &quot;1&quot;), and the chain ID (for Ethereum mainnet, that\u2019s 1; for Sepolia testnet, it\u2019s 11155111, etc.). For our example, the domain would be:<br \/>\n{<br \/>\nname: &quot;My Sample DApp&quot;,<br \/>\nversion: &quot;1&quot;,<br \/>\nchainId: 1<br \/>\n}<\/p>\n<p>Types: This is the structured format of the data you\u2019re 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:<br \/>\n{<br \/>\nTransfer: [<br \/>\n{ name: &quot;recipient&quot;, type: &quot;address&quot; },<br \/>\n{ name: &quot;amount&quot;, type: &quot;uint256&quot; },<br \/>\n{ name: &quot;message&quot;, type: &quot;string&quot; }<br \/>\n]<br \/>\n}<\/p>\n<p>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\u2014incorrect type definitions will break the wallet\u2019s display of the signature, leading users to reject it.<\/p>\n<p>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:<br \/>\n{<br \/>\nrecipient: &quot;0x742d35Cc6634C0532925a3b8D94C2bB23a09E9F&quot;,<br \/>\namount: ethers.parseEther(&quot;0.5&quot;), \/\/ We use parseEther to convert the human-readable amount to wei, which is what Ethereum uses<br \/>\nmessage: &quot;Thank you for supporting our dApp!&quot;<br \/>\n}<\/p>\n<p>Notice that we\u2019re using ethers.parseEther here, not just a plain number. That\u2019s 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\u2019ll get errors about invalid uint256 values, or even worse, the user will sign the wrong amount.<\/p>\n<p>Once you have all three pieces (domain, types, value), you can use Ethers.js\u2019s signTypedData method. In Ethers v6, that method is part of the signer object, so it\u2019s as simple as:<\/p>\n<p>const signature = await signer.signTypedData(domain, types, value);<\/p>\n<p>Wait\u2014but 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 &quot;Transfer&quot;) 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.<\/p>\n<p>Let\u2019s test this with a full working example, so you can see how it all comes together. Here\u2019s the complete code for our transfer signature:<\/p>\n<p>import { ethers } from &quot;ethers&quot;;<\/p>\n<p>\/\/ Connect to MetaMask and get the signer<br \/>\nasync function connectWallet() {<br \/>\nif (!window.ethereum) {<br \/>\nthrow new Error(&quot;Please install MetaMask to use this feature&quot;);<br \/>\n}<br \/>\nconst provider = new ethers.BrowserProvider(window.ethereum);<br \/>\nawait provider.send(&quot;eth_requestAccounts&quot;, []); \/\/ Prompt user to connect their wallet<br \/>\nconst signer = await provider.getSigner();<br \/>\nreturn signer;<br \/>\n}<\/p>\n<p>\/\/ Sign typed transfer data<br \/>\nasync function signTransfer(signer, recipient, amount, message) {<br \/>\n\/\/ Define EIP-712 domain<br \/>\nconst domain = {<br \/>\nname: &quot;My Sample DApp&quot;,<br \/>\nversion: &quot;1&quot;,<br \/>\nchainId: 1, \/\/ Use 11155111 for Sepolia testnet<br \/>\n};<\/p>\n<p>\/\/ Define the type structure<br \/>\nconst types = {<br \/>\nTransfer: [<br \/>\n{ name: &quot;recipient&quot;, type: &quot;address&quot; },<br \/>\n{ name: &quot;amount&quot;, type: &quot;uint256&quot; },<br \/>\n{ name: &quot;message&quot;, type: &quot;string&quot; },<br \/>\n],<br \/>\n};<\/p>\n<p>\/\/ Define the value to sign<br \/>\nconst value = {<br \/>\nrecipient: recipient,<br \/>\namount: ethers.parseEther(amount),<br \/>\nmessage: message,<br \/>\n};<\/p>\n<p>\/\/ Sign the typed data<br \/>\nconst signature = await signer.signTypedData(domain, types, value);<br \/>\nreturn signature;<br \/>\n}<\/p>\n<p>\/\/ Usage: Connect wallet, then sign a transfer<br \/>\nasync function runWorkflow() {<br \/>\ntry {<br \/>\nconst signer = await connectWallet();<br \/>\nconst recipient = &quot;0x742d35Cc6634C0532925a3b8D94C2bB23a09E9F&quot;;<br \/>\nconst amount = &quot;0.5&quot;;<br \/>\nconst message = &quot;Thank you for supporting our dApp!&quot;;<br \/>\nconst signature = await signTransfer(signer, recipient, amount, message);<br \/>\nconsole.log(&quot;Signature:&quot;, signature);<br \/>\n} catch (error) {<br \/>\nconsole.error(&quot;Error:&quot;, error.message);<br \/>\n}<br \/>\n}<\/p>\n<p>runWorkflow();<\/p>\n<p>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 \u201cMy Sample DApp\u201d, then list the recipient address, 0.5 ETH, and the message, so the user can confirm they\u2019re signing the right thing. That\u2019s the key benefit of EIP-712\u2014no more vague \u201csign a message\u201d prompts that users ignore or blindly approve.<\/p>\n<p>But wait\u2014what if you\u2019re working with a contract instead of a user\u2019s 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\u2019s useful for backends or scripts that need to generate signatures without user interaction. Here\u2019s a quick example of that:<\/p>\n<p>import { ethers } from &quot;ethers&quot;;<\/p>\n<p>\/\/ Create a wallet from a private key (for backend use only\u2014never expose private keys in frontend code)<br \/>\nconst privateKey = &quot;0xYourPrivateKeyHere&quot;; \/\/ Replace with your actual private key, stored securely<br \/>\nconst wallet = new ethers.Wallet(privateKey);<\/p>\n<p>\/\/ Define the same domain, types, and value as before<br \/>\nconst domain = { name: &quot;My Sample DApp&quot;, version: &quot;1&quot;, chainId: 1 };<br \/>\nconst types = { Transfer: [{ name: &quot;recipient&quot;, type: &quot;address&quot; }, { name: &quot;amount&quot;, type: &quot;uint256&quot; }, { name: &quot;message&quot;, type: &quot;string&quot; }] };<br \/>\nconst value = { recipient: &quot;0x742d35Cc6634C0532925a3b8D94C2bB23a09E9F&quot;, amount: ethers.parseEther(&quot;0.5&quot;), message: &quot;Thank you for supporting our dApp!&quot; };<\/p>\n<p>\/\/ Sign typed data with the wallet<br \/>\nconst signature = await wallet.signTypedData(domain, types, value);<\/p>\n<p>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\u2019s device.<\/p>\n<p>Now, let\u2019s talk about common pitfalls I\u2019ve seen as an Ethers.js supplier, because even small mistakes can break your signature. First, chain ID mismatches. The domain\u2019s 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:<\/p>\n<p>const chainId = await provider.getChainId();<br \/>\nconst domain = { name: &quot;My Sample DApp&quot;, version: &quot;1&quot;, chainId };<\/p>\n<p>That way, the domain is always in sync with the user\u2019s current network. Second, missing or incorrect EIP-712 types. If you have a custom struct type, like a \u201cUser\u201d type that has a \u201cname\u201d string and \u201cage\u201d 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 \u201cMessage\u201d that has a \u201csender\u201d of type \u201cUser\u201d, your types would look like this:<\/p>\n<p>const types = {<br \/>\nUser: [ { name: &quot;name&quot;, type: &quot;string&quot; }, { name: &quot;age&quot;, type: &quot;uint256&quot; } ],<br \/>\nMessage: [ { name: &quot;sender&quot;, type: &quot;User&quot; }, { name: &quot;text&quot;, type: &quot;string&quot; } ]<br \/>\n};<\/p>\n<p>If you don\u2019t define the \u201cUser\u201d type, Ethers.js will throw an error when you try to sign, because it doesn\u2019t 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\u2019re using a newer version, make sure you\u2019re following v6 docs, not outdated v5 ones.<\/p>\n<p>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\u2019s 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\u2019s name and chain ID, define the Permit type, pass the value with the owner, spender, and amount, and sign it. That\u2019s one of the most common use cases for typed data, and Ethers.js makes it straightforward to implement.<\/p>\n<p>Now, let\u2019s cover verification, because signing is only half the story. Once you have a signature, you\u2019ll need to verify it to make sure it\u2019s 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:<\/p>\n<p>const signerAddress = await signer.getAddress(); \/\/ We can get the signer&#8217;s address to compare<br \/>\nconst recoveredAddress = ethers.verifyTypedData(domain, types, value, signature);<br \/>\nconsole.log(recoveredAddress === signerAddress); \/\/ This will be true if the signature is valid<\/p>\n<p>This is useful for backend checks, or for confirming that a signature came from the expected address. If the recovered address doesn\u2019t match the expected one, the signature is tampered with or invalid, so you should reject it.<\/p>\n<p>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\u2014Ledger will prompt the user to confirm the typed data as usual, no extra work needed.<\/p>\n<p>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\u2019t rely on the wallet to show it\u2014you 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.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.jinforestchem.com\/uploads\/48780\/small\/industrial-grade-phenol13746.png\"><\/p>\n<p>If you\u2019re looking to implement typed data signatures in your dApp, but don\u2019t 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.<\/p>\n<p><a href=\"https:\/\/www.jinforestchem.com\/esters\/\">Esters<\/a> References<br \/>\nEthers.js Official Documentation<br \/>\nEIP-712: Ethereum Structured Data Signing Specification<br \/>\nEthers.js Signer API Documentation<br \/>\nEIP-2612: Permit Extension for ERC-20 Tokens<\/p>\n<hr>\n<p><a href=\"https:\/\/www.jinforestchem.com\/\">Qingdao Jinforest Chem Tech Co., Ltd.<\/a><br \/>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.<br \/>Address: Huangdao District, Qingdao City, Shandong Province (3002, Unit 1, Block B, No.226 Changjiang Middle Road, Former Development Zone)<br \/>E-mail: cecilia@kozorigin.com<br \/>WebSite: <a href=\"https:\/\/www.jinforestchem.com\/\">https:\/\/www.jinforestchem.com\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you\u2019ve spent any time building decentralized applications (dApps) on Ethereum, you\u2019ve probably run into typed &hellip; <a title=\"How to sign a typed data with Ethers.js?\" class=\"hm-read-more\" href=\"http:\/\/www.egodaam.com\/blog\/2026\/11\/23\/how-to-sign-a-typed-data-with-ethers-js-4669-57f6d1\/\"><span class=\"screen-reader-text\">How to sign a typed data with Ethers.js?<\/span>Read more<\/a><\/p>\n","protected":false},"author":169,"featured_media":3774,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[3737],"class_list":["post-3774","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-industry","tag-ethers-4553-582a62"],"_links":{"self":[{"href":"http:\/\/www.egodaam.com\/blog\/wp-json\/wp\/v2\/posts\/3774","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.egodaam.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.egodaam.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.egodaam.com\/blog\/wp-json\/wp\/v2\/users\/169"}],"replies":[{"embeddable":true,"href":"http:\/\/www.egodaam.com\/blog\/wp-json\/wp\/v2\/comments?post=3774"}],"version-history":[{"count":0,"href":"http:\/\/www.egodaam.com\/blog\/wp-json\/wp\/v2\/posts\/3774\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.egodaam.com\/blog\/wp-json\/wp\/v2\/posts\/3774"}],"wp:attachment":[{"href":"http:\/\/www.egodaam.com\/blog\/wp-json\/wp\/v2\/media?parent=3774"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.egodaam.com\/blog\/wp-json\/wp\/v2\/categories?post=3774"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.egodaam.com\/blog\/wp-json\/wp\/v2\/tags?post=3774"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}