“个人_sign”的问题在以太埃里姆中。

发布于 2025-01-30 13:03:53 字数 375 浏览 4 评论 0 原文

当我在控制台窗口(从浏览器)中运行此语句以获取帐户的签名时,我会遇到问题:

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

情归归情 2025-02-06 13:03:53

基于 personal_sign docs ,您需要通过两个参数

  • 一个十六进制编码的UTF-8字符串,要向用户介绍。 (不散布任何字符串)

  • 请求的签名帐户的地址。

      const signdata =等待以太坊?。
        方法:“个人_sign”,
        参数:[
          json.stringify(Messagetosign),
          //等待以太坊?。
          帐户,
        ],,
      });
     

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.

    const signedData = await ethereum?.request({
        method: "personal_sign",
        params: [
          JSON.stringify(messageToSign),
          //await ethereum?.request({method: "eth_requestAccounts"})[0]
          account,
        ],
      });
    
浅黛梨妆こ 2025-02-06 13:03:53

参数(“帐户”)的第一个元素必须是连接的帐户之一。

您可以访问帐户;

window.ethereum
  .request({ method: "eth_requestAccounts" })
  .then(accounts => {
    console.log(accounts);
  })

First element of params ("account") have to be one of the connected accounts.

You can access accounts with;

window.ethereum
  .request({ method: "eth_requestAccounts" })
  .then(accounts => {
    console.log(accounts);
  })
御弟哥哥 2025-02-06 13:03:53

这与浏览器中的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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文