NomicFoundation / hardhat

Hardhat is a development environment to compile, deploy, test, and debug your Ethereum software.
https://hardhat.org
Other
7.3k stars 1.41k forks source link

`populateTransaction()` of `hardhat-ethers` not effective #5514

Open txhsl opened 4 months ago

txhsl commented 4 months ago

Version of Hardhat

2.22.3

What happened?

When I'm using const hre = require("hardhat"); to send a transfer transaction on my privnet, the transaction didn't get populated through populateTransaction, and hit an underpriced error due to incorrect price settings.

Minimal reproduction steps

  1. When using ethers v6.13.1 with const ethers = require("ethers");, I run the following codes.
    const provider = new ethers.JsonRpcProvider(URL);
    console.log(await provider.getFeeData());
    const wallet = new ethers.Wallet(KEY, provider);
    const tx = await wallet.populateTransaction({
    to: wallet.address,
    value: 1
    });
    console.log(tx);
    await wallet.sendTransaction(tx);

    I get the following output, the transaction succeeds.

    FeeData {
    gasPrice: 4000000000n,
    maxFeePerGas: 7000000000n,
    maxPriorityFeePerGas: 1000000000n
    }
    {
    to: '0x480dd671880768D24317FA965D00f43D25868892',
    value: 1n,
    from: '0x480dd671880768D24317FA965D00f43D25868892',
    nonce: 6,
    gasLimit: 21000n,
    chainId: 2404291515n,
    type: 2,
    maxFeePerGas: 7000000000n,
    maxPriorityFeePerGas: 1000000000n
    }
  2. When using hardhat v2.22.3 with const hre = require("hardhat");, I run the following codes.
    const accounts = await hre.ethers.getSigners();
    console.log(await hre.ethers.provider.getFeeData());
    const tx = await accounts[0].populateTransaction({
    to: accounts[0].address,
    value: 1
    });
    console.log(tx);
    await accounts[0].sendTransaction(tx);

    I get the following output, the RPC request fails.

    FeeData {
    gasPrice: 4000000000n,
    maxFeePerGas: 7000000000n,
    maxPriorityFeePerGas: 1000000000n
    }
    {
    to: '0x480dd671880768D24317FA965D00f43D25868892',
    value: 1n,
    from: '0x480dd671880768D24317FA965D00f43D25868892'
    }
    ProviderError: transaction underpriced: policy needed 1000000000, gastipcap 1000000000, gasfeecap 3796875000 
    at HttpProvider.request (D:\Bane\go-ethereum\contracts\node_modules\hardhat\src\internal\core\providers\http.ts:96:21)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async HardhatEthersSigner.sendTransaction (D:\Bane\go-ethereum\contracts\node_modules\@nomicfoundation\hardhat-ethers\src\signers.ts:125:18)
    at async main (D:\Bane\go-ethereum\contracts\task\test.ts:23:5)

The baseFee of my privet is a fixed number 30 Gwei.

Search terms

ethers, populateTransaction, underpriced

ChristopherDedominici commented 3 months ago

Hi @txhsl, thanks for reaching out. I tried to reproduce the issue but I did not manage to (I am not using your privnet, so the environment is not exactly the same).

Could you tell me which version of @nomicfoundation/hardhat-ethers you are running? Most likely, this problem has already been fixed in the latest release. Could you try to reproduce using the latest release and see if it is still happening? Thanks.

txhsl commented 3 months ago

@ChristopherDedominici Thanks for your feedback!

I just imported through const hre = require("hardhat"); from hardhat v2.22.3, but if other libraries do make a difference here, the following list shows all the dependencies of my hardhat project.

"devDependencies": {
  "@nomicfoundation/hardhat-toolbox": "^5.0.0",
  "hardhat": "^2.22.3"
},
"dependencies": {
  "@openzeppelin/contracts-upgradeable": "^5.0.2"
}
├─┬ @nomicfoundation/hardhat-toolbox@5.0.0
│ ├── @nomicfoundation/hardhat-chai-matchers@2.0.7
│ ├── @nomicfoundation/hardhat-ethers@3.0.6
│ ├── @nomicfoundation/hardhat-ignition-ethers@0.15.5
│ ├── @nomicfoundation/hardhat-network-helpers@1.0.11
│ ├── @nomicfoundation/hardhat-verify@2.0.8
│ ├── @typechain/ethers-v6@0.5.1
│ ├── @typechain/hardhat@9.1.0
│ ├── @types/chai@4.3.16
│ ├── @types/mocha@10.0.6
│ ├── @types/node@20.14.6
│ ├── chai@4.4.1
│ ├── ethers@6.13.1
│ ├── hardhat-gas-reporter@1.0.10
│ ├── hardhat@2.22.5 deduped
│ ├── solidity-coverage@0.8.12
│ ├── ts-node@10.9.2
│ ├── typechain@8.3.2
│ └── typescript@5.4.5
├─┬ @openzeppelin/contracts-upgradeable@5.0.2
│ └── @openzeppelin/contracts@5.0.2
└─┬ hardhat@2.22.5
  ├── @ethersproject/abi@5.7.0
  ├── @metamask/eth-sig-util@4.0.1
  ├── @nomicfoundation/edr@0.4.0
  ├── @nomicfoundation/ethereumjs-common@4.0.4
  ├── @nomicfoundation/ethereumjs-tx@5.0.4
  ├── @nomicfoundation/ethereumjs-util@9.0.4
  ├── @nomicfoundation/solidity-analyzer@0.1.2
  ├── @sentry/node@5.30.0
  ├── @types/bn.js@5.1.5
  ├── @types/lru-cache@5.1.1
  ├── adm-zip@0.4.16
  ├── aggregate-error@3.1.0
  ├── ansi-escapes@4.3.2
  ├── boxen@5.1.2
  ├── chalk@2.4.2
  ├── chokidar@3.6.0
  ├── ci-info@2.0.0
  ├── debug@4.3.5
  ├── enquirer@2.4.1
  ├── env-paths@2.2.1
  ├── ethereum-cryptography@1.2.0
  ├── ethereumjs-abi@0.6.8
  ├── find-up@2.1.0
  ├── fp-ts@1.19.3
  ├── fs-extra@7.0.1
  ├── glob@7.2.0
  ├── immutable@4.3.6
  ├── io-ts@1.10.4
  ├── keccak@3.0.4
  ├── lodash@4.17.21
  ├── mnemonist@0.38.5
  ├── mocha@10.4.0
  ├── p-map@4.0.0
  ├── raw-body@2.5.2
  ├── resolve@1.17.0
  ├── semver@6.3.1
  ├── solc@0.7.3
  ├── source-map-support@0.5.21
  ├── stacktrace-parser@0.1.10
  ├── ts-node@10.9.2 deduped
  ├── tsort@0.0.1
  ├── typescript@5.4.5 deduped
  ├── undici@5.28.4
  ├── uuid@8.3.2
  └── ws@7.5.10

I may have updated the dependencies, so I'm trying to reproduce the issue again if it is still there.

txhsl commented 3 months ago

Yes, it is still there. Only the from field is full-filled.

FeeData {
  gasPrice: 4000000000n,
  maxFeePerGas: 7000000000n,
  maxPriorityFeePerGas: 1000000000n
}
{
  to: '0x480dd671880768D24317FA965D00f43D25868892',
  value: 1n,
  from: '0x480dd671880768D24317FA965D00f43D25868892'
}

And the transaction is still underpriced.

ProviderError: transaction underpriced: policy needed 1000000000, gastipcap 1000000000, gasfeecap 3796875000
    at HttpProvider.request (D:\Bane\governance-test\node_modules\hardhat\src\internal\core\providers\http.ts:96:21)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async HardhatEthersSigner.sendTransaction (D:\Bane\governance-test\node_modules\@nomicfoundation\hardhat-ethers\src\signers.ts:125:18)
    at async main (D:\Bane\governance-test\task\test.ts:12:5) {
  parent: undefined,
  _stack: 'ProviderError: transaction underpriced: policy needed 1000000000, gastipcap 1000000000, gasfeecap 3796875000 \n' +
    '    at HttpProvider.request (D:\\Bane\\governance-test\\node_modules\\hardhat\\src\\internal\\core\\providers\\http.ts:96:21)\n' +
    '    at processTicksAndRejections (node:internal/process/task_queues:95:5)\n' +
    '    at async HardhatEthersSigner.sendTransaction (D:\\Bane\\governance-test\\node_modules\\@nomicfoundation\\hardhat-ethers\\src\\signers.ts:125:18)\n' +
    '    at async main (D:\\Bane\\governance-test\\task\\test.ts:12:5)',
  code: -32000,
  _isProviderError: true,
  data: undefined
}
ChristopherDedominici commented 3 months ago

Hi @txhsl , thanks for the quick response. I'll take a look and come back to you asap

kanej commented 3 months ago

We think our next step is to investigate whether we are diverging from ethers in our implementation of populateTransaction.