Skip to content

ProviderError: the method has been deprecated: eth_accounts when using eth_call #6632

Closed
@gnpar

Description

@gnpar

Version of Hardhat

2.23.0

What happened?

When calling a view on a smart contract, the AutomaticSenderProvider tries to get the sender address by calling eth_accounts, but that raises this error on most nodes:

ProviderError: the method has been deprecated: eth_accounts
    at HttpProvider.request (/home/gabriel/workspace/ensuro/eth-prototype/tests/hardhat-project/node_modules/hardhat/internal/core/providers/http.js:91:27)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async AutomaticSenderProvider._getSender (/home/gabriel/workspace/ensuro/eth-prototype/tests/hardhat-project/node_modules/hardhat/internal/core/providers/accounts.js:289:31)
    at async AutomaticSenderProvider.request (/home/gabriel/workspace/ensuro/eth-prototype/tests/hardhat-project/node_modules/hardhat/internal/core/providers/accounts.js:274:39)
    at async staticCallResult (/home/gabriel/workspace/ensuro/eth-prototype/tests/hardhat-project/node_modules/ethers/lib.commonjs/contract/contract.js:245:22)
    at async staticCall (/home/gabriel/workspace/ensuro/eth-prototype/tests/hardhat-project/node_modules/ethers/lib.commonjs/contract/contract.js:219:24)
    at async Proxy.totalSupply (/home/gabriel/workspace/ensuro/eth-prototype/tests/hardhat-project/node_modules/ethers/lib.commonjs/contract/contract.js:259:20)
    at async main (/home/gabriel/workspace/ensuro/eth-prototype/tests/hardhat-project/script.js:5:15)

This is similar to #5572, but that issue and fix only cover the getSigners function. This one applies to all contract calls.

There are several workarounds for this:

  • Setting the signer on contract creation.
  • Adding accounts to the network config
  networks: {
    polygon: {
      url: process.env.NODE_URL,
      chainId: 137,
      accounts: ["0xdf57089febbacf7ba0bc227dafbffa9fc08a93fdc68e1e42411a14efcf23656e"],
    },
  },
  • Settting from on the network config:
  networks: {
    polygon: {
      url: process.env.NODE_URL,
      chainId: 137,
      from: "0x0000000000000000000000000000000000000000",
    },
  },

Installed versions:

[email protected] ~/scratch/hardhat
├── @nomicfoundation/[email protected]
├── @nomicfoundation/[email protected]
└── [email protected]

I'm not sure if this is a bug or a documentation issue, but a more descriptive message like "No sender configured" is better than the raw eth_accounts deprecated error.

Minimal reproduction steps

Set up a hardhat project with hardhat-toolbox. Set up a network such as polygon:

require("@nomicfoundation/hardhat-toolbox");

/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
  solidity: "0.8.20",
  networks: {
    polygon: {
      url: process.env.ALCHEMY_URL_POLYGON,
      chainId: 137,
    },
  },
};

Run this script with HARDHAT_NETWORK=polygon node script.sj:

// script.js
const hre = require("hardhat");

async function main() {
  const contract = await hre.ethers.getContractAt("IERC20", "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174");
  console.log(await contract.totalSupply());
}

main().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});

Search terms

eth_accounts deprecated

Metadata

Metadata

Assignees

Labels

status:readyThis issue is ready to be worked on

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions