无效帐户:网络#0:ropsten-私钥太短,预期32字节

发布于 2025-01-28 09:23:37 字数 987 浏览 2 评论 0原文

错误图片

require("@nomiclabs/hardhat-waffle");

// This is a sample Hardhat task. To learn how to create your own go to
// https://hardhat.org/guides/create-task.html
task("accounts", "Prints the list of accounts", async (taskArgs, hre) => {
  const accounts = await hre.ethers.getSigners();

  for (const account of accounts) {
    console.log(account.address);
  }
});

// You need to export an object to set up your config
// Go to https://hardhat.org/config/ to learn more

/**
 * @type import('hardhat/config').HardhatUserConfig
 */


const INFURA_PROJECT_ID = "3dxxxx";
const ROPSTEN_PRIVATE_KEY = "e6xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

module.exports = {
  networks: {
    ropsten: {
      url: `https://ropsten.infura.io/v3/${INFURA_PROJECT_ID}`,
      accounts: [`0x${ROPSTEN_PRIVATE_KEY}`]
    }
  }
};

我根据网站上的示例部署了合同来ropsten,但错误是报告。私钥大于32位

error picture

require("@nomiclabs/hardhat-waffle");

// This is a sample Hardhat task. To learn how to create your own go to
// https://hardhat.org/guides/create-task.html
task("accounts", "Prints the list of accounts", async (taskArgs, hre) => {
  const accounts = await hre.ethers.getSigners();

  for (const account of accounts) {
    console.log(account.address);
  }
});

// You need to export an object to set up your config
// Go to https://hardhat.org/config/ to learn more

/**
 * @type import('hardhat/config').HardhatUserConfig
 */


const INFURA_PROJECT_ID = "3dxxxx";
const ROPSTEN_PRIVATE_KEY = "e6xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

module.exports = {
  networks: {
    ropsten: {
      url: `https://ropsten.infura.io/v3/${INFURA_PROJECT_ID}`,
      accounts: [`0x${ROPSTEN_PRIVATE_KEY}`]
    }
  }
};

I deployed the contract to ropsten according to the example on the website, but an error was reported. The private key is greater than 32 bits

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

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

发布评论

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

评论(3

深空失忆 2025-02-04 09:23:37

之所以发生,是因为您将“ 0x”放在私钥之前。我也有类似的错误。另外,如果需要,您可以使用炼金术。其他所有内容看起来都不错。

It's happening because you put "0x" before your private key. I had a similar error. Also, you can use Alchemy if you want. Everything else looks good in your config.

新一帅帅 2025-02-04 09:23:37

我遇到了相同的错误,并使用一个env文件存储了常数。
因此,就我而言,通过删除半隆来解决错误。

I had the same error and used an env file to store the constants.
So in my case, the error was solved by removing the semicolon.

倾城花音 2025-02-04 09:23:37

一些可能的修复程序:

  • 将0 x添加到私钥中,
  • 将.ENV文件转换或施放stringtoString()和字符串Interpolation $ 0x {process.env.private_key}
  • 检查我是否正在从正确的目录中调用测试
  • ,以检查.env文件是否在正确(项目root)目录中
  • 检查钱包软件是否为我提供了完整的私人私人键而不是部分密钥

,但解决了问题的原因是:

require("@nomicfoundation/hardhat-toolbox");
require("dotenv").config();

hardhat.config.js文件的顶部

Some possible fixes:

  • Adding a 0x to the private key
  • Converting or casting the private key from .env file to a string with String, toString(), and string interpolation $0x{process.env.PRIVATE_KEY}
  • Checking that I was calling the test from the correct directory
  • Checking that the .env file was in the correct (project root) directory
  • Checking that the wallet software gave me the full private key and not a partial key

But what fixed the issue was importing:

require("@nomicfoundation/hardhat-toolbox");
require("dotenv").config();

at the top of the hardhat.config.js file

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