full-blockchain-solidity-course-js
full-blockchain-solidity-course-js copied to clipboard
exceeds block gas limit when deploy contract to rinkeby
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.

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)
})
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 : )
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).
The gasLimit must be gWei not wei