[英]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
.我正在尝试签署我的交易,因为之前我有一个错误说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. message (encrypted using keccak256)
和signer
都有价值,但我不知道为什么web3.eth.sign
行中有错误。
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
Maybe your browser doesn't have a injected metamask.也许您的浏览器没有注入元掩码。 So web3.eth is undefined.所以 web3.eth 是未定义的。 Or just try window.web3.eth to get the sign function properly.或者只是尝试 window.web3.eth 来正确获取签名功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.