Code Monkey home page Code Monkey logo

ecrecover's Introduction

Ecrecover

Signing and verifying message with Solidity.

Installation

Deploy the solidity code on localhost in Ethereum in remix. Have metamask wallet

 Make sure to have Metamask or any Ethereum Wallet.
  1.Go to the deployed contract and find a function named "getMessageHash" 
    and enter a string that you want to hash.
  2.Copy the bytes32 output and use that as an input in the another function
    named "ethSignedMessageHash:".
  3.Open console in the browser(Ctrl+Shift+I) and write "ethereum.enable".
    A pop comes up and accept that.
  4."account="your metamask wallet address"". Write this in the console.
  5."hash="The output of getMessageHash"".
    In this line we create two variable and stored the account and hash.
  6.ethereum.request({ method: "personal_sign", params: [account, hash]}).then(console.log)
    This is the way we are signing through Metamask. Metamask pops up and accept it.
  7.Now call a function "recover signer". The first input is _ethSignedMessageHash.
    Copy the output of ethSignedMessageHash and paste it. Second input is signature, 
    get it from the output in the console of your browser.

      Your output will be your address from which you signed.

  8.Now call the function "verify". _signer: "the wallet address", 
    _message: "the message you wrote in the starting", 
    signature: "the output you got in the console". 
  Your output will be true, i.e. it verifies the signature.
If you want to try, change anything in the input of this function, your output will be false.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.