Skip to content

feat(anvil): add --fund-accounts CLI flag#14392

Open
exp0nge wants to merge 1 commit intofoundry-rs:masterfrom
exp0nge:feat/fund-accounts
Open

feat(anvil): add --fund-accounts CLI flag#14392
exp0nge wants to merge 1 commit intofoundry-rs:masterfrom
exp0nge:feat/fund-accounts

Conversation

@exp0nge
Copy link
Copy Markdown
Contributor

@exp0nge exp0nge commented Apr 21, 2026

Motivation

When testing with Anvil, it's common to need specific addresses funded with custom balances on startup (e.g. for impersonation testing or reproducing on-chain scenarios). Currently this requires sending transactions after startup or using a custom genesis file.

Solution

Add a --fund-accounts CLI flag that accepts ADDRESS:AMOUNT pairs (amount in ETH):

anvil --fund-accounts 0x1234...5678:1000 0xabcd...ef01:5000

This funds the specified addresses during node initialization, after state loading but before the node is ready.

  • Add --fund-accounts arg to NodeArgs with space-delimited values
  • Add funded_accounts field + with_funded_accounts() builder to NodeConfig
  • Apply funding via set_balance during backend setup

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

Copy link
Copy Markdown
Collaborator

@mablr mablr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for you proposition.

Just wondering why anvil_setBalance/anvil_addBalance endpoints aren't enough ?

@exp0nge
Copy link
Copy Markdown
Contributor Author

exp0nge commented Apr 23, 2026

Hi, thanks for you proposition.

Just wondering why anvil_setBalance/anvil_addBalance endpoints aren't enough ?

This would be a one-shot (startup) option. IIUC the anvil_* namespace would need to be part of the post startup bootstrapping?

@mablr
Copy link
Copy Markdown
Collaborator

mablr commented Apr 23, 2026

IIUC the anvil_* namespace would need to be part of the post startup

Yes simply call anvil_setBalance/anvil_addBalance endpoints after startup.

Is there a specific use-case where this is not suitable ? If so could please you elaborate more ?

@exp0nge
Copy link
Copy Markdown
Contributor Author

exp0nge commented Apr 23, 2026

IIUC the anvil_* namespace would need to be part of the post startup

Yes simply call anvil_setBalance/anvil_addBalance endpoints after startup.

Is there a specific use-case where this is not suitable ? If so could please you elaborate more ?

We are using this as a drop-in replacement for other dev/localnets which come with some pre-funded addresses. Similar to the genesis configurations where you can bake in your addresses. Post-boostrap would be extra setup, I can do that and close this PR if you don't think this is worth as a extra feature

@mablr
Copy link
Copy Markdown
Collaborator

mablr commented Apr 23, 2026

I see, it shouldn't hurt to have this.

Could you please resolve the merge conflict? Once done, I’ll trigger CI. 👍

Allow funding specific accounts with custom ETH balances on startup
via `--fund-accounts 0xAddr:amount` (amount in ETH).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@exp0nge exp0nge force-pushed the feat/fund-accounts branch from 5e0bceb to 67cfbeb Compare April 23, 2026 15:56
@exp0nge exp0nge requested a review from mablr April 23, 2026 16:35
@exp0nge
Copy link
Copy Markdown
Contributor Author

exp0nge commented Apr 23, 2026

I see, it shouldn't hurt to have this.

Could you please resolve the merge conflict? Once done, I’ll trigger CI. 👍

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants