`populateTransaction()` of `hardhat-ethers` not effective
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
- When using
ethers v6.13.1withconst 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
}
- When using
hardhat v2.22.3withconst 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
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 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.
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
}
Hi @txhsl , thanks for the quick response. I'll take a look and come back to you asap
We think our next step is to investigate whether we are diverging from ethers in our implementation of populateTransaction.
Just wanted to chime in and say this is still an issue - it looks like the Harhat signer behaves the same as the ethers.JsonRpcSigner in that it only resolves properties (like ENS domains) but doesn't populate things like gas.
This is kind of annoying with the Ledger integration for example.