Leo
Leo

Reputation: 161

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'sign')

I'm trying to sign my transaction as previously I was having an error saying sendTransaction needs signer. Both message (encrypted using keccak256) and signer have value but I have no idea why there's an error in the web3.eth.sign line.

async function signMessage(message: any, signer: any) {
    console.log(`Message: ${message} annnnd signer: ${signer}` )
    const sig = await web3.eth.sign(message.toString(), signer).then(console.log);
    let v = parseInt(sig.substring(130, 132), 16);
    if (v < 27) v += 27;
    const normalizedSig = `${sig.substring(0, 130)}${v.toString(16)}`;
    return normalizedSig;
};

These are my message and signer value:

Message: 0x462b880c3d888d1...137ba2fdd16a45817a8a5d 
signer: 0x624b8A9dC...7db4b5dDCd0F7f

Upvotes: 0

Views: 588

Answers (1)

john stewart
john stewart

Reputation: 1

Maybe your browser doesn't have a injected metamask. So web3.eth is undefined. Or just try window.web3.eth to get the sign function properly.

Upvotes: 0

Related Questions