Skip to content

feat(cheatcodes): allow forge script to access wallet addresses with vm.getScriptWallets() #7213

@superical

Description

@superical

Component

Forge

Describe the feature you would like

To have a feature where we can access in our foundry scripts the private keys input from --interactives mode or the resolved public addresses of those private keys. This way, we don't have to repeat the sender address in the --sender because we can decide which private keys to use as the sender and pass the intended address as the sender in vm.startBroadcast(sender).

For example:

uint256[] privateKeys = vm.interactives();
// Or, an optional index parameter to get from the list of input private keys
// uint256 privateKey = vm.interactives(0);   // gets the first private key entered from interactive mode

address sender = vm.addr(privateKeys[0]);

vm.startBroadcast(sender);
// ...
vm.stopBroadcast();

Additional context

Currently, when forge is run with --interactives, it doesn't seem like there is a way to access the private keys or the public addresses of those private keys provided through the interactive input in the foundry scripts. The only way (as far as I have tried) to run the foundry scripts with --interactives is:

  • Provide the address of the private key through --sender on top of --interactives
  • AND only use vm.startBroadcast(). I cannot use vm.startBroadcast(sender) since I cannot access the private key supplied through the interactive input and so I won't know the sender address.

Supplying the public address through --sender feels repeated because the address should already be resolvable from the private key.

Moreover, the --interactives parameter can accept more than one private keys which seems to suggest a script should be able to select one of the keys supplied to be the actual sender.

If there is a feature where we can access the input private keys or their translated public addresses in our foundry scripts, we wouldn't have to repeat the address in the --sender because our foundry script can decide which private key to use as sender and pass the correct address as the sender in vm.startBroadcast(sender).

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions