Blockchain Development Tips

What is a Signature? How can we sign it with blockchain?

A signature is an evidence that you agree with a particular statement.

Arnish Gupta
BLOCK6

--

When we do some business with third party so we create an agreement that is signed by both parties even there is also an agreement when we purchase items online here are the terms:

  • Item can be returned in 15 days.
  • Item Delivery date will be X day.
  • Item only return if it is a damaged product.
  • Item return amount will be credited in X days.

It’s all about traditional business and in terms of blockchain, the same things also happen here.

Photo by krakenimages on Unsplash

So let’s embark on our journey and shine sunlight on the below topics.

  • What is a Signature?
  • What is EIP-712 Protocol?
  • How to sign/verify our message with Metamask?
  • Create/Verify Signature From Etherscan
  • Example of OpenSea?

What is Signature?

  • The Signature is the hash key that is the combination of a private key and the message.
  • It is free of cost. You don’t have to pay any Gas Fees.
  • A message is always a string. If you want to sign a JSON then you have to convert it into the string using JSON.stringify()
  • Signature proof that you own this address otherwise If you want to make someone believe that you are the owner of this address then you have to send the minimum amount that has the cost.

What is EIP-712 Protocol?

  • EIP-712 is the Ethereum Improvement Protocol For Data Hashing and Signing.
  • This protocol simplifies signing information and is easily readable by the user.
  • Before EIP-712 the signing request comes with a hash and it is not readable by the common user like this:
Figure 1: a signature request before using EIP712
  • After EIP-712 the request popup will look like
Figure 2: a signature request after using EIP712

How to sign/verify our message with Metamask?

  • The first step is to sign/verify a message that is connected to the wallet using the command.
const accounts = await ethereum.request({
method: ‘eth_requestAccounts’
});
const account = accounts[0]; // get the address
  • Sign Message: For signature requests, we have to use thepersonal_sign method.
const message = "Address own by Arnish Gupta";
const sign = await ethereum.request({
method: 'personal_sign',
params: [message, account],
});
// in the sign constant you will get the signature
  • Verify Message: To get the address from the signature we use the recover method.
const recoveredAdd = web3.eth.accounts.recover(message, sign);// recoveredAdd is the address of this message

You can download the complete source code here.

Create/Verify Signature From Etherscan

Figure 3: etherscan signature verification
  • Write any message in the message box and click the Sign Message button then a request window will open in your dApp.
Figure 4: Metamask window for signing request
  • Click the sign button in metamask then a popup will open in etherscan and you can see the signature hash.
Figure 5: Etherscan window after signing
  • you can publish your signature on etherscan then you will get the unique public URL so you can share it with anyone for justification.
  • For other signature verification, you can click Verify Signature button near Sign Message and you will get the three input boxes to write signature hash, message and address. It will tell you whether it is valid or not.

Example of OpenSea?

  • OpenSea is a leading NFT platform. People can buy and sell the NFTs.
  • OpenSea gives the feature that we can Make Offer of any NFT. It means that we want to buy it at X price.
Figure 6: OpenSea Make Offer Button
  • In the Make Offer process OpenSea signs the NFT detail with the price that you offered.
Figure 7: OpenSea Signature Request
  • If the owner is interested in your bids then OpenSea can buy this NFT that you are interested in and the amount transferred from your account to the NFT owner account.

I hope you understand the concept of Signature. If you have any doubt then you can write to me. I am happy to read your words.

Join me and learn blockchain every Monday at 9 AM.

Thank you for reading..!!

Contents distributed by Learn.Block6.tech

👉 Discord — Live Talks

👉 Twitter — Latest articles

👉 LinkTr.ee

--

--

Arnish Gupta
BLOCK6
Writer for

Learn Blockchain with me every Monday at 9AM (GMT+5:30).