Skip to content

feat(forge script): eliminate redundant --sender flag when using --account #10632

Open
@mshakeg

Description

@mshakeg

Component

Forge

Describe the feature you would like

Summary

Make the --sender flag optional when using --account in forge script commands by automatically deriving the sender address from the specified account's private key.

Problem Statement

Currently, when using forge script with wallet accounts, developers must specify both --account and --sender flags, creating unnecessary redundancy and friction in the developer experience.

Current Required Usage

forge script script/Deploy.s.sol --rpc-url unichain --sender 0x123...abc --account deployer --broadcast

This creates several issues:

1. Redundant Information

When specifying --account deployer, Foundry already has access to:

  • The private key associated with that account
  • The address derived from that private key
  • The intent to use this account for transaction signing

The --sender flag provides no additional information that can't be derived from --account.

2. Error-Prone Workflow

Developers can accidentally:

  • Specify mismatched addresses between --sender and --account
  • Copy/paste wrong addresses when switching between accounts
  • Mix up account names with addresses

3. Verbose Commands

# Current: Long and repetitive
forge script script/Deploy.s.sol --rpc-url mainnet --sender 0x123...abc --account deployer --broadcast --verify

# Desired: Clean and concise  
forge script script/Deploy.s.sol --rpc-url mainnet --account deployer --broadcast --verify

Proposed Solution

Primary Enhancement

Make --sender optional when --account is specified. Foundry should automatically derive the sender address from the account's private key.

Desired Usage

# Simple case - sender automatically derived from account
forge script script/Deploy.s.sol --rpc-url unichain --account deployer --broadcast

Implementation Logic

  1. When --account is provided without --sender:

    • Load the specified account from the keystore
    • Derive the address from the private key
    • Use that address as the sender for transactions
    • Set msg.sender appropriately in the script context
  2. When both --account and --sender are provided:

    • Validate that the sender address matches the account's derived address
    • Throw a clear error if there's a mismatch
    • This maintains backward compatibility for existing scripts
  3. When only --sender is provided (current behavior):

    • Continue to work as before for raw private key workflows
    • Maintain full backward compatibility

Additional context

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Backlog

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions