full-blockchain-solidity-course-js icon indicating copy to clipboard operation
full-blockchain-solidity-course-js copied to clipboard

exceeds block gas limit when deploy contract to rinkeby

Open benduongquangmobile opened this issue 3 years ago • 2 comments
trafficstars

Lesson

Lesson 4

exceeds block gas limit

Operating System

macOS (Apple Silicon)

Describe the bug

This error is happen when I run deploy.js file All the config as the same video. Screen Shot 2022-08-05 at 21 46 46

const fs = require("fs-extra")
const ethers = require("ethers")

require("dotenv").config()

const aibFilePath = "contacts_SimpleStorage_sol_SimpleStorage.abi"
const binFilePath = "contacts_SimpleStorage_sol_SimpleStorage.bin"

async function main() {
  const provider = new ethers.providers.JsonRpcProvider(process.env.RPC_URL)
  // ! Old wallet code.
  const wallet = new ethers.Wallet(process.env.PRIVATE_KEY, provider)

  const binary = fs.readFileSync(binFilePath, "utf8")
  const abi = fs.readFileSync(aibFilePath, "utf8")

  // TODO: send transaction factory
  const contractFactory = new ethers.ContractFactory(abi, binary, wallet)
  const contract = await contractFactory.deploy({
    gasLimit: 10000000000000,
  })
  await contract.deployTransaction.wait(1)
  console.log("deployed")
  console.log("address", contract.address)

  let currentFavoriteNumber = await contract.retrieve()
  const transactionRespone = await contract.store("7")
  currentFavoriteNumber = await contract.retrieve()
}


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

benduongquangmobile avatar Aug 05 '22 14:08 benduongquangmobile

Hello! I think the problem is that you specified gasLimit equal to 10_000_000_000_000 gas, but at the moment the block has a limit of 30_000_000 gas and in this case you are going beyond the block limit anyway.

Try to reduce the specified gasLimit and everything should work. I hope my answer will help you, have a nice day : )

KumaCrypto avatar Aug 11 '22 07:08 KumaCrypto

Again, irrelevant here as it is not a code bug. Create a discussion for logical errors :)

Please close the issue (it can always be re-opened in the future).

krakxn avatar Sep 15 '22 04:09 krakxn

The gasLimit must be gWei not wei

nixjs avatar Jan 12 '23 09:01 nixjs