DEV Community

Cover image for EIP 712: A simple example using Ethers.js & Hardhat
ali kim
ali kim

Posted on

EIP 712: A simple example using Ethers.js & Hardhat

Several months ago, I was trying to use EIP712 to create verifiable signatures using structured data. It’s a standard way of signing structured data, so theoretically it should be super simple: Sign a message and then decode to verify it, right?

In practice, I had a tough time getting this to work. I looked at various documentation and code examples, but I noticed they all had:

  • different implementations of signing and verifying (decoding) signature
  • different implementations by ethers version
  • different decode implementations
  • overcomplicated demos
  • No end to end example of using ethers.js (only web3.js)

With all these little issues combined, I just couldn’t do a simple sign & verify using EIP712. I ended up wasting so much time.

Here’s a sample repo to help anyone having trouble using EIP-712. If you can’t do a simple sign & verify within 15 minutes, just use my code: https://github.com/alinobrasil/eip712_product_registry

By utilizing EIP712, you will have:

  1. Enhanced Security: EIP712 helps prevent certain types of replay attacks and phishing attacks, thereby enhancing the security of transactions and interactions within the Ethereum ecosystem.
  2. Improved User Experience: EIP712 provides a better user experience by enabling wallets and dApps to display transaction information in a structured, human-readable format, reducing the likelihood of user errors and increasing overall usability.
  3. Interoperability: EIP712 facilitates interoperability between different wallets and dApps by defining a standard for how transaction data is structured and signed, thereby promoting seamless interaction and integration across the Ethereum network.

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

Cloudinary image

Optimize, customize, deliver, manage and analyze your images.

Remove background in all your web images at the same time, use outpainting to expand images with matching content, remove objects via open-set object detection and fill, recolor, crop, resize... Discover these and hundreds more ways to manage your web images and videos on a scale.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay