在Goerli上使用Hardhat部署时出现错误,错误信息为“内在交易成本不足”。

huangapple go评论55阅读模式
英文:

deploying on Goerli with hardhat error insufficient funds for intrinsic transaction cost

问题

很多人遇到了相同的错误,找不到有效的解决方案。它曾在本地的Ganache上运行,但我需要迁移到Goerli网络,但它不起作用。

Deploy.js

async function main() {
  const [deployer] = await ethers.getSigners();

  console.log("使用账户部署合同:", deployer.address);

  console.log("账户余额:", (await deployer.getBalance()).toString());

  const Contract = await ethers.getContractFactory("SLCAVotes");
  const contract = await Contract.deploy();

  console.log("合同地址:", contract.address);
}

main()
  .then(() => process.exit(0))
  .catch((error) => {
    console.error(error);
    process.exit(1);
  });

我在我的部署账户中有0.2个Goerli ETH。控制台日志证实了这一点,我还在etherscan上进行了检查。

配置文件

require("@nomiclabs/hardhat-waffle");
require('dotenv').config()

module.exports = {
  defaultNetwork: "goerli",
  networks: {
    hardhat: {
    },
    localhost: {
      url: "http://127.0.0.1:8545"
    },
    goerli: {
      url: process.env.ENDPOINT_URL,
      accounts: [process.env.DEPLOYER_KEY]
    }
  },
  solidity: {
    version: '0.8.11',
    settings: {
      optimizer: {
        enabled: true,
        runs: 200
      }
    }
  },
  paths: {
    sources: "./src/contracts",
    artifacts: "./src/abis"
  },
  mocha: {
    timeout: 40000
  }
}

我不知道这些信息是否足够帮助您解决问题。如果需要更多信息,请提出您需要的内容。

英文:

Many people with the same error couldn't find a working solution.
It used to work on a local Ganache but I need to move over to goerli. But it doesn't work.

Deploy.js

async function main() {
  const [deployer] = await ethers.getSigners();

  console.log("Deploying contracts with the account:", deployer.address);

  console.log("Account balance:", (await deployer.getBalance()).toString());

  const Contract = await ethers.getContractFactory("SLCAVotes");
  const contract = await Contract.deploy();

  console.log("Contract address:", contract.address);
}

main()
  .then(() => process.exit(0))
  .catch((error) => {
    console.error(error);
    process.exit(1);
  });

I have 0.2 goerli eth in my deployer account. The console.log confirms that + I checked on etherscan.
config file

require('dotenv').config()

module.exports = {
  defaultNetwork: "goerli",
  networks: {
    hardhat: {
    },
    localhost: {
      url: "http://127.0.0.1:8545"
    },
    goerli: {
      url: process.env.ENDPOINT_URL,
      accounts: [process.env.DEPLOYER_KEY]
    }
  },
  solidity: {
    version: '0.8.11',
    settings: {
      optimizer: {
        enabled: true,
        runs: 200
      }
    }
  },
  paths: {
    sources: "./src/contracts",
    artifacts: "./src/abis"
  },
  mocha: {
    timeout: 40000
  }
}

I dont't know if this is enough information for you guys to help fix the issue. Please ask for anything you need.

答案1

得分: 0

代码翻译结果:

// scripts/deploy.js
async function main () {
  // We get the contract to deploy
  const Contract = await ethers.getContractFactory('SLCAVotes');
  console.log('Deploying Contract...');
  const contract = await Contract.deploy();
  await contract.deployed();
  console.log('Contract deployed to:', contract.address);
}

main()
  .then(() => process.exit(0))
  .catch(error => {
    console.error(error);
    process.exit(1);
  });

如果您有任何其他需要翻译的内容,请继续提出。

英文:

It works now!

I changed my deploy script to this one I found on OpenZeppelin.

// scripts/deploy.js
async function main () {
  // We get the contract to deploy
  const Contract = await ethers.getContractFactory('SLCAVotes');
  console.log('Deploying Contract...');
  const contract = await Contract.deploy();
  await contract.deployed();
  console.log('Contract deployed to:', contract.address);
}

main()
  .then(() => process.exit(0))
  .catch(error => {
    console.error(error);
    process.exit(1);
  });

huangapple
  • 本文由 发表于 2023年2月24日 00:18:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/75547492.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定