Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

populateTransaction() of hardhat-ethers not effective #5514

Open
txhsl opened this issue Jul 12, 2024 · 5 comments
Open

populateTransaction() of hardhat-ethers not effective #5514

txhsl opened this issue Jul 12, 2024 · 5 comments
Labels
status:ready This issue is ready to be worked on

Comments

@txhsl
Copy link

txhsl commented Jul 12, 2024

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
}
  1. 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
Copy link
Contributor

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.

@ChristopherDedominici ChristopherDedominici added status:needs-more-info There's not enough information to start working on this issue and removed status:triaging labels Jul 22, 2024
@txhsl
Copy link
Author

txhsl commented Jul 22, 2024

@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/[email protected]
│ ├── @nomicfoundation/[email protected]
│ ├── @nomicfoundation/[email protected]
│ ├── @nomicfoundation/[email protected]
│ ├── @nomicfoundation/[email protected]
│ ├── @nomicfoundation/[email protected]
│ ├── @typechain/[email protected]
│ ├── @typechain/[email protected]
│ ├── @types/[email protected]
│ ├── @types/[email protected]
│ ├── @types/[email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected] deduped
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ └── [email protected]
├─┬ @openzeppelin/[email protected]
│ └── @openzeppelin/[email protected]
└─┬ [email protected]
  ├── @ethersproject/[email protected]
  ├── @metamask/[email protected]
  ├── @nomicfoundation/[email protected]
  ├── @nomicfoundation/[email protected]
  ├── @nomicfoundation/[email protected]
  ├── @nomicfoundation/[email protected]
  ├── @nomicfoundation/[email protected]
  ├── @sentry/[email protected]
  ├── @types/[email protected]
  ├── @types/[email protected]
  ├── [email protected]
  ├── [email protected]
  ├── [email protected]
  ├── [email protected]
  ├── [email protected]
  ├── [email protected]
  ├── [email protected]
  ├── [email protected]
  ├── [email protected]
  ├── [email protected]
  ├── [email protected]
  ├── [email protected]
  ├── [email protected]
  ├── [email protected]
  ├── [email protected]
  ├── [email protected]
  ├── [email protected]
  ├── [email protected]
  ├── [email protected]
  ├── [email protected]
  ├── [email protected]
  ├── [email protected]
  ├── [email protected]
  ├── [email protected]
  ├── [email protected]
  ├── [email protected]
  ├── [email protected]
  ├── [email protected]
  ├── [email protected]
  ├── [email protected] deduped
  ├── [email protected]
  ├── [email protected] deduped
  ├── [email protected]
  ├── [email protected]
  └── [email protected]

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

@txhsl
Copy link
Author

txhsl commented Jul 22, 2024

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
Copy link
Contributor

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

@ChristopherDedominici ChristopherDedominici added status:triaging and removed status:needs-more-info There's not enough information to start working on this issue labels Jul 23, 2024
@kanej
Copy link
Member

kanej commented Jul 25, 2024

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

@kanej kanej added status:ready This issue is ready to be worked on and removed status:triaging labels Aug 9, 2024
@kanej kanej moved this from Backlog to To-do in Hardhat Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:ready This issue is ready to be worked on
Projects
Status: To-do
Development

No branches or pull requests

3 participants