diff --git a/packages/builder/src/util.ts b/packages/builder/src/util.ts index 06d73d2cf..734df98ae 100644 --- a/packages/builder/src/util.ts +++ b/packages/builder/src/util.ts @@ -36,7 +36,7 @@ export async function getExecutionSigner( const address = ('0x' + hash.slice(0, 40)) as viem.Address; await provider.impersonateAccount({ address }); - await provider.setBalance({ address, value: BigInt(1e22) }); + await provider.setBalance({ address, value: viem.parseEther('10000') }); const client = viem.createWalletClient({ account: address, diff --git a/packages/cli/src/commands/alter.ts b/packages/cli/src/commands/alter.ts index bcd5ea3c7..384fe4e7c 100644 --- a/packages/cli/src/commands/alter.ts +++ b/packages/cli/src/commands/alter.ts @@ -65,7 +65,7 @@ export async function alter( async getSigner(addr: viem.Address) { // on test network any user can be conjured //await provider.impersonateAccount({ address: addr }); - //await provider.setBalance({ address: addr, value: BigInt(1e22) }); + //await provider.setBalance({ address: addr, value: viem.parseEther('10000') }); return { address: addr, wallet: provider as viem.WalletClient }; }, snapshots: false, diff --git a/packages/cli/src/commands/build.ts b/packages/cli/src/commands/build.ts index c83087f88..39e9d92d9 100644 --- a/packages/cli/src/commands/build.ts +++ b/packages/cli/src/commands/build.ts @@ -132,7 +132,7 @@ export async function build({ async function (addr: viem.Address) { // on test network any user can be conjured await (provider as unknown as viem.TestClient).impersonateAccount({ address: addr }); - await (provider as unknown as viem.TestClient).setBalance({ address: addr, value: BigInt(1e22) }); + await (provider as unknown as viem.TestClient).setBalance({ address: addr, value: viem.parseEther('10000') }); return { address: addr, diff --git a/packages/cli/src/commands/run.ts b/packages/cli/src/commands/run.ts index 6322c9f27..3a9fefdfc 100644 --- a/packages/cli/src/commands/run.ts +++ b/packages/cli/src/commands/run.ts @@ -57,12 +57,13 @@ export async function run(packages: PackageSpecification[], options: RunOptions) // Start the rpc server const node = options.node; + const provider = getProvider(node)!; const nodeLogging = await createLoggingInterface(node); if (options.fundAddresses && options.fundAddresses.length) { for (const fundAddress of options.fundAddresses) { - await provider?.setBalance({ address: fundAddress as viem.Address, value: BigInt(1e22) }); + await provider?.setBalance({ address: fundAddress as viem.Address, value: viem.parseEther('10000') }); } } @@ -76,11 +77,12 @@ export async function run(packages: PackageSpecification[], options: RunOptions) // set up signers for (const addr of (options.impersonate || '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266').split(',')) { await provider.impersonateAccount({ address: addr as viem.Address }); - await provider.setBalance({ address: addr as viem.Address, value: BigInt(1e22) }); + await provider.setBalance({ address: addr as viem.Address, value: viem.parseEther('10000') }); signers = [{ address: addr as viem.Address, wallet: provider }]; } const chainId = await provider.getChainId(); + const basicRuntime = new ChainBuilderRuntime( { provider: provider, @@ -88,7 +90,7 @@ export async function run(packages: PackageSpecification[], options: RunOptions) async getSigner(addr: viem.Address) { // on test network any user can be conjured await provider.impersonateAccount({ address: addr }); - await provider.setBalance({ address: addr, value: BigInt(1e22) }); + await provider.setBalance({ address: addr, value: viem.parseEther('10000') }); return { address: addr, wallet: provider }; }, snapshots: chainId === CANNON_CHAIN_ID, diff --git a/packages/cli/src/commandsConfig.ts b/packages/cli/src/commandsConfig.ts index 24ae8c8b6..1834a9eab 100644 --- a/packages/cli/src/commandsConfig.ts +++ b/packages/cli/src/commandsConfig.ts @@ -636,7 +636,6 @@ const commandsConfig = { { flags: '-c --chain-id ', description: 'Chain ID of deployment to interact with ', - required: true, }, { flags: '-n --provider-url [url]', diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts index 230ad5ab2..6bfe75975 100644 --- a/packages/cli/src/index.ts +++ b/packages/cli/src/index.ts @@ -155,6 +155,10 @@ function configureRun(program: Command) { forkProvider: provider, }); } else { + if (options.providerUrl) { + const _provider = viem.createPublicClient({ transport: viem.http(options.providerUrl) }); + options.chainId = await _provider.getChainId(); + } node = await runRpc(pickAnvilOptions(options)); } @@ -516,17 +520,28 @@ applyCommandsConfig(program.command('interact'), commandsConfig.interact).action ) { const cliSettings = resolveCliSettings(opts); - let chainId = opts.chainId; + let chainId: number | undefined = opts.chainId ? Number(opts.chainId) : undefined; - // throw an error if the chainId is not consistent with the provider's chainId - await ensureChainIdConsistency(opts.providerUrl, chainId); + const isProviderUrl = cliSettings.providerUrl.startsWith('http'); - const { provider, signers } = await resolveWriteProvider(cliSettings, chainId); + // throw an error if both chainId and providerUrl are not provided + if (!chainId && !isProviderUrl) { + throw new Error('Please provide one of the following options: --chain-id or --provider-url'); + } + // if chainId is not provided, get it from the provider if (!chainId) { - chainId = await provider.getChainId(); + const _provider = viem.createPublicClient({ transport: viem.http(cliSettings.providerUrl) }); + chainId = await _provider.getChainId(); } + // throw an error if the chainId is not consistent with the provider's chainId + if (isProviderUrl) { + await ensureChainIdConsistency(cliSettings.providerUrl, chainId); + } + + const { provider, signers } = await resolveWriteProvider(cliSettings, chainId); + const resolver = await createDefaultReadRegistry(cliSettings); const [name, version] = [packageDefinition.name, packageDefinition.version]; @@ -553,7 +568,7 @@ applyCommandsConfig(program.command('interact'), commandsConfig.interact).action async getSigner(address: viem.Address) { // on test network any user can be conjured //await p.provider.impersonateAccount({ address: addr }); - //await p.provider.setBalance({ address: addr, value: BigInt(1e22) }); + //await p.provider.setBalance({ address: addr, value: viem.parseEther('10000') }); return { address: address, wallet: provider }; }, snapshots: false, diff --git a/packages/cli/src/util/build.ts b/packages/cli/src/util/build.ts index 4e3d1b95e..1c25135d3 100644 --- a/packages/cli/src/util/build.ts +++ b/packages/cli/src/util/build.ts @@ -179,7 +179,7 @@ async function configureSigners( getDefaultSigner = async () => { const addr = signers && signers.length > 0 ? signers[0].address : '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'; await provider.impersonateAccount({ address: addr }); - await provider.setBalance({ address: addr, value: BigInt(1e22) }); + await provider.setBalance({ address: addr, value: viem.parseEther('10000') }); return { address: addr, wallet: provider }; }; } else { diff --git a/packages/hardhat-cannon/src/tasks/build.ts b/packages/hardhat-cannon/src/tasks/build.ts index b0b85a60b..22b399a6e 100644 --- a/packages/hardhat-cannon/src/tasks/build.ts +++ b/packages/hardhat-cannon/src/tasks/build.ts @@ -136,7 +136,7 @@ task(TASK_BUILD, 'Assemble a defined chain and save it to to a state which can b if (hre.network.name !== 'cannon') { if (impersonate) { await provider.impersonateAccount({ address: impersonate }); - await provider.setBalance({ address: impersonate, value: BigInt(1e22) }); + await provider.setBalance({ address: impersonate, value: viem.parseEther('10000') }); defaultSigner = getSigner(impersonate) || null; // Add the impersonated signer if it is not part of the hardhat config if (!defaultSigner) {