I have to sign a random string with my metamask. So created a js code like that:

await window.ethereum.request({
        method: "eth_sign",
        params: ["my address","My string"],
        id: "1"
    }).then(result => {
    }).catch(error => {

But i never got a response after i clicked "sign" on metamask window. The promise is always in "pending" status.

enter image description here

Is it a bug or i'm doing somethings wrong ?

Thanks you !

EDIT: enter image description here

  • can you try -> params: [<hex-value>]
    – Majd TL
    Apr 22 at 8:55
  • if this works then you need to hash ("myaddress" + "myString") and then give it in params instead of ("my address" "My string")
    – Majd TL
    Apr 22 at 8:56
  • yes i made a mistake, there is a "," beetwen "myadress" and "string" Apr 22 at 9:59
  • if i try what you said i got this error: MetaMask - RPC Error: e is undefined. It tells that there is no message to sign Apr 22 at 10:16
  • Can you add what I said as a picture in your question
    – Majd TL
    Apr 22 at 10:40

I tried it on the console of my browser look like this

Connect to metamask and get accounts:

let accs;
ethereum.request({ method: 'eth_requestAccounts' }).then(res => accs = res);

you should take an action in metamask at this point then:

let account = accs[0]
    method: 'eth_sign', 
        [ account, '0xaaaa' ]
}).then(data => {
    console.log("data ", data);

The params are the address which will sign the message, and the message as hex start with 0x.

But you should not use eth_sign its bad, read here why and use the alternative https://docs.metamask.io/guide/signing-data.html#signing-data-with-metamask

  • Thanks, "eth_sign" don't works although i do the same as you. But i tried with "personal_sign" and it's works well. Maybe "eth_sign" is deprecated now or it's because the website is not link to any ethereum RPC. Yeah i know for the securities issues but that's i use it in local and i never archieve to verify the signature of the "signTypedData_v4" method. Apr 22 at 14:45
  • @Jean-benoitRichez Richez Okay then modify my answer and then accept it if u can
    – Majd TL
    Apr 22 at 16:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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