Skip to content

Out of gas error using default args when deploying a contract setting tx.gasPrice to a state variable in the constructor #5855

Open
@0xSamWitch

Description

@0xSamWitch

Version of Hardhat

2.22.15

What happened?

Cannot deploy a specific contract to a blockchain (tried fantom, sonic testnet and arbitrum). It stores the tx.gasPrice in the constructor.

Transaction failing to deploy it with default args:

  const contract = await ethers.deployContract("Contract");
  await contract.waitForDeployment();

https://arbiscan.io/tx/0x4aba3be69ebbff1c9696fd7f71f62334249ad72a21e150973917bd425cdabf98

Transaction successful specifying a higher gas price:

  const contract = await ethers.deployContract("Contract", {gasLimit: 200000});
  await contract.waitForDeployment();

https://arbiscan.io/tx/0x3b97e44c329f71a7ba502162578e7761d20b2cb1ab64475f41d066a9f7a2e1d1

Minimal reproduction steps

Create this contract:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;

contract Contract {
  uint64 private price; // Making it immutable works

  constructor() {
    price = uint64(tx.gasprice);
  }
}

Try to deploy it on a network other than hardhat:

  const contract = await ethers.deployContract("Contract");
  await contract.waitForDeployment();

A repo which can replicate this has been set up:
https://github.com/0xSamWitch/VRFRequestInfoDeploymentFailure

Search terms

out of gas, tx.gasPrice

Metadata

Metadata

Labels

status:readyThis issue is ready to be worked on

Type

No type

Projects

Status

Backlog

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions