2

(This is using local ganache, metamask set up to localhost which is working otherwise)

I am trying to establish how to sign, here is my code:

        async function sign()
        {
            console.log("sign func");

            let accounts = await web3.eth.getAccounts();
            console.log("account:", accounts[0]);
            let msg = "Some data";
            console.log("in data message:", msg);
            let prefix = "\x19Ethereum Signed Message:\n" + msg.length;
            let msgHash1 = web3.utils.sha3(prefix+msg);
            console.log("using hash:", msgHash1);

            let sig1 = await web3.eth.sign(msg, accounts[0]);
            console.log("signing...", sig1);

            //web3.eth.sign(msg, accounts[0]).then(console.log);

            let whoSigned1 = await web3.eth.accounts.recover(msg, sig1);
            console.log("WHO SIGNED", whoSigned1);
        }

(code is triggered via a button, works fine functionally aka it gets called)

All console logs until eth.sign happen just normal, correct account as well. Then metamask asks to confirm the signature, just like I would expect.

confirm

I click sign and thats it, nothing ever happens. The function does not return, no further code is ever called. Meaning it never calls back, it awaits forever. I also used then() syntax, same thing, never calls back.

If I do another transaction, while waiting, like minting an NFT, no problem goes through.

I switched metamask to rinkeby, same behavior. Switched it's mainnet, same. So I guess it's my code?

1 Answer 1

1

I encountered the same issue. As a workaround, I used web3.eth.personal.sign with the same arguments and omitted the password argument.

1
  • so it works even when you omit the password, hm. I mean thats the main issue with that function, you dont want to leak any keys.
    – Opcode
    Commented Dec 18, 2021 at 6:11

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.