当我在控制台窗口(从浏览器)中运行此语句以获取帐户的签名时,我会遇到问题:
ethereum.request({方法:“ personal_sign”,params:[account,hash]});
我以前没有这个问题,它可以正常工作,并通过该帐户的数字签名(来自MetAmask)回报了承诺。它将打开MetAmask,我将进行数字签名,并将数字签名的结果归还承诺。
现在,每当我运行语句时,它都会报告错误。错误消息是:
代码:-32602
消息:“无效参数:必须提供一个以太坊地址。”
有什么变化吗?我找不到以ethereum.org或metamask的其他细节。如果有人对此有所了解,那似乎是什么问题?
I am getting a problem when I run this statement in the console window (from browser) to get signature of the account:
ethereum.request({ method: "personal_sign", params: [account, hash] });
I did not used to have this problem, it works fine and returns a promise with the digital signature of the account (from Metamask). It would open up Metamask, I would do a digital signing and return the result of the digital signature to the promise.
Now it reports an error whenever I run the statement. The error message is:
code: -32602
message: "Invalid parameters: must provide an Ethereum address."
Has something changed? I could not find any other details from ethereum.org or Metamask. If anyone has some knowledge on this, what seems to be the problem?
发布评论
评论(3)
基于 personal_sign docs ,您需要通过两个参数
一个十六进制编码的UTF-8字符串,要向用户介绍。 (不散布任何字符串)
请求的签名帐户的地址。
Based on personal_sign docs, you need to pass two parameters
A hex-encoded UTF-8 string to present to the user. (not hash any string)
The address of the requested signing account.
参数(“帐户”)的第一个元素必须是连接的帐户之一。
您可以访问帐户;
First element of params ("account") have to be one of the connected accounts.
You can access accounts with;
这与浏览器中的metamask和以太坊窗口对象有关。
最初,我使用注射的Web3提供商在测试网上测试了合同。
当我试图在本地测试时,我使用了JVM生成的帐户之一。
您不应该使用它们。相反
哈希= bytes32您的哈希消息的值
我可以发出 ethereum.request 命令,该命令将运行“ personal_sign”方法,并使用帐户和哈希参数。
签署消息时,承诺将返回帐户的数字签名。
This has to do with MetaMask and the Ethereum window object in the browser.
Originally I tested the contract on a testnet using an injected Web3 provider.
When I was trying to test locally I used one of the JVM generated accounts.
You should not use them. Instead use a MetaMask account (copy the address) and do the ff:
assign the address to a variable (do the same with the hash):
account = Metamask address,
hash = bytes32 value of your hashed message
I can then issue the ethereum.request command that will run the "personal_sign" method with the parameters of account and hash.
The promise will return the digital signature of the account when signing a message.