You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using a network that is defined in the Hardhat config with only url and no accounts, ethers.getContractFactory instantiates a ContractFactory with no runner.
While it may make sense in the context of the ContractFactory itself for deployments (there is no signer for deploying new contracts), subsequent usage of this ContractFactory might attempt to use the runner not as a signer but as a provider.
For example, consider the following code when there are no accounts:
import { ethers } from "hardhat";
async function main() {
const MyToken = await ethers.getContractFactory("MyToken"); // MyToken.runner is null
const instance = MyToken.attach('0xf37F5FE27A63876C172B110B0C229e2Ff3B29Eb8'); // instance.runner is null
await instance.waitForDeployment();
}
This is a simplified example but we want to wait for a contract instance to exist on the network, but the contract instance may either be a new deployment or something that was previously deployed. In the above, it was previously deployed.
Error: runner does not support .provider (operation="getDeployedCode", code=UNSUPPORTED_OPERATION, version=6.7.1)
at makeError (/Users/eric/Downloads/project 19/node_modules/ethers/src.ts/utils/errors.ts:685:21)
at assert (/Users/eric/Downloads/project 19/node_modules/ethers/src.ts/utils/errors.ts:702:25)
at Proxy.getDeployedCode (/Users/eric/Downloads/project 19/node_modules/ethers/src.ts/contract/contract.ts:817:15)
at Proxy.waitForDeployment (/Users/eric/Downloads/project 19/node_modules/ethers/src.ts/contract/contract.ts:838:33)
at main (/Users/eric/Downloads/project 19/scripts/waitForDeployment.ts:10:18)
at processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: 'UNSUPPORTED_OPERATION',
operation: 'getDeployedCode'
}
I am wondering if either of the following would make sense for Hardhat:
getContractFactory should use the default hre.ethers.provider as the runner if there are no accounts
or
Hardhat should provide an alternative to ContractFactory.attach where Hardhat injects the default hre.ethers.provider if there is no runner in the ContractFactory
Alternatively, please let me know if this is a usage error. For example, the following both work. Would any of these be preferred in terms of usage?
import { ethers } from "hardhat";
async function main() {
const MyToken = await ethers.getContractFactory("MyToken");
const MyTokenWithRunner = new ethers.ContractFactory(MyToken.interface, MyToken.bytecode, ethers.provider);
const instance = MyTokenWithRunner.attach('0xf37F5FE27A63876C172B110B0C229e2Ff3B29Eb8');
await instance.waitForDeployment();
}
or
import { ethers } from "hardhat";
async function main() {
const MyToken = await ethers.getContractFactory("MyToken");
const instance = new ethers.Contract('0xf37F5FE27A63876C172B110B0C229e2Ff3B29Eb8', MyToken.interface, ethers.provider);
await instance.waitForDeployment();
}
Minimal reproduction steps
Create a new Hardhat project using ethers and hardhat-ethers.
In hardhat-config.ts, specify the following under networks (without any accounts):
baseGoerli: {
url: 'https://goerli.base.org',
}
Create the following script and run it as npx hardhat run scripts/waitForDeployment.ts --network baseGoerli
runner null
Error: runner does not support .provider (operation="getDeployedCode", code=UNSUPPORTED_OPERATION, version=6.7.1)
at makeError (/Users/eric/Downloads/project 19/node_modules/ethers/src.ts/utils/errors.ts:685:21)
at assert (/Users/eric/Downloads/project 19/node_modules/ethers/src.ts/utils/errors.ts:702:25)
at Proxy.getDeployedCode (/Users/eric/Downloads/project 19/node_modules/ethers/src.ts/contract/contract.ts:817:15)
at Proxy.waitForDeployment (/Users/eric/Downloads/project 19/node_modules/ethers/src.ts/contract/contract.ts:838:33)
at main (/Users/eric/Downloads/project 19/scripts/waitForDeployment.ts:9:18)
at processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: 'UNSUPPORTED_OPERATION',
operation: 'getDeployedCode'
}
Search terms
ContractFactory runner provider accounts
The text was updated successfully, but these errors were encountered:
Version of Hardhat
2.17.2
What happened?
When using a network that is defined in the Hardhat config with only
url
and noaccounts
,ethers.getContractFactory
instantiates a ContractFactory with norunner
.While it may make sense in the context of the ContractFactory itself for deployments (there is no signer for deploying new contracts), subsequent usage of this ContractFactory might attempt to use the
runner
not as a signer but as a provider.For example, consider the following code when there are no accounts:
This is a simplified example but we want to wait for a contract instance to exist on the network, but the contract instance may either be a new deployment or something that was previously deployed. In the above, it was previously deployed.
Since ethers uses the contract instance's
runner
in waitForDeployment to check for deployed code, the above fails with:I am wondering if either of the following would make sense for Hardhat:
getContractFactory
should use the defaulthre.ethers.provider
as therunner
if there are no accountsor
ContractFactory.attach
where Hardhat injects the defaulthre.ethers.provider
if there is no runner in theContractFactory
Alternatively, please let me know if this is a usage error. For example, the following both work. Would any of these be preferred in terms of usage?
or
Minimal reproduction steps
Create a new Hardhat project using ethers and hardhat-ethers.
In hardhat-config.ts, specify the following under
networks
(without any accounts):Create the following script and run it as
npx hardhat run scripts/waitForDeployment.ts --network baseGoerli
Output:
Search terms
ContractFactory runner provider accounts
The text was updated successfully, but these errors were encountered: