1

I saw a lot of videos about smart contract and Dapps and also i developed some simple Dapps but still i don't know how and when i should use sign message which contains my message (what i need to put in sign message), and what is exactly usage of sign message this way. Unfortunately example of most of videos about signing data is sign simple string text and i can't figure out what is usage of sign an message like string, in smart contract?? Can anyone explain it to me with an example (for example doing something useful or in better way using sign message).

1 Answer 1

1

The basic use of message signing is to verify that you have the private key to a certain address. This, then, enables one to sign a message which gives certain permissions for someone else, on behalf of your address.

Once a message is signed (encrypted) by your private key it can be decrypted with your public key. So you can hand out the public key for anyone (that's why it's called public) and they can read the messages you signed - but they can't modify them.

A website may ask you to sign an arbitrary message to verify that you have the private key for an address - so you own the address. Or, to use with smart contracts, you may sign a message which gives ERC20 token allowance to a certain other address. This is called a permit. The other entity (for whom you gave the allowance with the permit) can then redeem the signed message (signature) in a transaction to a certain smart contract to get the allowance you. The benefit of this kind of system is that the signer doesn't need to issue a transaction and pay for its gas cost: they only need to sign a message.

You can read more about permit for example here.

3
  • So what is difference between verify of user by signature or checking address which connected to a site??,For example if i connected to a Dapp with a my metamask, it shows i have private key of this wallet which i can connect to this Dapp, it this situation it's necessary to sign a message that proves its me??
    – Alireza
    Jan 6, 2023 at 12:05
  • Good question! Connecting a wallet and showing your wallet address doesn't guarantee that you have the private key for the address. Different wallets have different types of wallets inside them - also ones for which you don't have the private key. Signing a message is the easiest way to guarantee that someone has the private key. Jan 6, 2023 at 12:23
  • Thanks a lot. Would you please tell me some other usage or examples of sign messages?
    – Alireza
    Jan 6, 2023 at 16:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.