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

Calculated gas fees differ if signer is Wallet or SignerWithAddress #2872

Closed
aaonduollar opened this issue Jun 22, 2022 · 4 comments
Closed
Assignees

Comments

@aaonduollar
Copy link

I'm having an issue where if I instantiate a Wallet object and add it the hardhat provider, gas fees are not getting calculated property whenever I make a transaction. But if I use one of the SignerWithAddress from hre.ethers.getSigners() it works correctly. I have tried both with Alchemy and Moralis.

In this snippet I only show sendTransaction getting used, but the same behaviour is being seen in contract function calls.

This is my configuration and task:

// transfer.ts

import { task } from 'hardhat/config';
import config from '../../config';

task('action-transfer', 'Transfer coins from owner to other')
  .addParam('to', 'Account address to transfer to')
  .addParam('value', 'Value to transfer')
  .setAction(async ({ to, value }: { to: string; value: number }, hre) => {
    const owner1 = (await hre.ethers.getSigners())[0];
    const owner2 = new hre.ethers.Wallet(
      config.crypto.ownerPrivateKey,
      hre.ethers.provider
    );

    const tx1 = await owner1.sendTransaction({ to, value });
    const tx2 = await owner2.sendTransaction({ to, value });

    console.log(tx1);
    console.log(tx2);
  });
$ npx hardhat action-transfer --to 0x7caee40B0F4F5872a3cB5e03d9AeAe2e3210bfbe --value 1 --network mumbai
                                                                                                                              
tx1 {
  hash: '0x36f2746a1c4f59eba9d2438821d69e5d62e687e505e6db26b235b642697ab2c2',
  type: 2,
  accessList: [],
  blockHash: null,
  blockNumber: null,
  transactionIndex: null,
  confirmations: 0,
  from: '0xAf036C8Dac12FCfAD6dEeBb12640d19BA9EF6B26',
  gasPrice: BigNumber { value: "94837263915" },
  maxPriorityFeePerGas: BigNumber { value: "94837263903" },
  maxFeePerGas: BigNumber { value: "94837263915" },
  gasLimit: BigNumber { value: "21000" },
  to: '0x7caee40B0F4F5872a3cB5e03d9AeAe2e3210bfbe',
  value: BigNumber { value: "1" },
  nonce: 166,
  data: '0x',
  r: '0xa0b4580497a53661b47da0a7ed268b84f6e6d472339e7ea098948d12c0de1892',
  s: '0x3cc84c030b7b657e1e0e2cdc47c11e8be551f7bffa445a794a4e1ef8c4633013',
  v: 1,
  creates: null,
  chainId: 80001,
  wait: [Function (anonymous)]
}
tx2 {
  type: 2,
  chainId: 80001,
  nonce: 167,
  maxPriorityFeePerGas: BigNumber { value: "1500000000" },
  maxFeePerGas: BigNumber { value: "1500000020" },
  gasPrice: null,
  gasLimit: BigNumber { value: "21000" },
  to: '0x7caee40B0F4F5872a3cB5e03d9AeAe2e3210bfbe',
  value: BigNumber { value: "1" },
  data: '0x',
  accessList: [],
  hash: '0x04bf854a65a21b6e781c2e22404fb5bac59c64dfa725fe5adcd670dab2db9a5a',
  v: 0,
  r: '0xb703adc9023e5aaf2568a0695f018c329a50bd44cbe256625d876899f4770a81',
  s: '0x2d7bbaf1b537cc5ccf6b6d36fceaf80b4cc922425e843b8d94ab9aa5e6736194',
  from: '0xAf036C8Dac12FCfAD6dEeBb12640d19BA9EF6B26',
  confirmations: 0,
  wait: [Function (anonymous)]
}
// hardhat.config.ts

import cfg from './src/config';

import { HardhatUserConfig } from 'hardhat/config';
import '@nomiclabs/hardhat-etherscan';
import '@nomiclabs/hardhat-waffle';
import '@typechain/hardhat';
import 'hardhat-gas-reporter';
import 'solidity-coverage';

import './src/tasks/actions/transfer';

// Configuration
const config: HardhatUserConfig = {
  solidity: '0.8.4',
  networks: {
    mumbai: {
      url: cfg.crypto.host,
      accounts: [crypto.ownerPrivateKey],
    },
    polygon: {
      url: cfg.crypto.host,
      accounts: [cfg.crypto.ownerPrivateKey],
    },
  },
  paths: {
    sources: './src/contracts',
    tests: './src/tests/contracts',
    cache: './cache',
    artifacts: './artifacts',
  },
  mocha: {
    timeout: 40000,
  },
};

export default config;

./src/config is just a config object used for using different environments.

Thanks.

@github-actions
Copy link
Contributor

This issue is also being tracked on Linear.

We use Linear to manage our development process, but we keep the conversations on Github.

LINEAR-ID: 307a5bad-5cd0-4174-ac6e-243dbdd23ae6

@aaonduollar
Copy link
Author

I think it might have something to do with ethers-io/ethers.js#2828 although it's not clear to me why they provide different gas data.

@github-actions
Copy link
Contributor

This issue was marked as stale because it didn't have any activity in the last 30 days. If you think it's still relevant, please leave a comment indicating so. Otherwise, it will be closed in 7 days.

@github-actions github-actions bot added the Stale label Jul 22, 2022
@github-actions
Copy link
Contributor

This issue was closed because it has been stalled for 7 days with no activity.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants