Skip to content

Latest commit

 

History

History
127 lines (83 loc) · 4.3 KB

forge-script.md

File metadata and controls

127 lines (83 loc) · 4.3 KB

forge script

NAME

forge-script - Run a smart contract as a script, building transactions that can be sent onchain.

SYNOPSIS

forge script [options] path [args...]

DESCRIPTION

Run a smart contract as a script, building transactions that can be sent onchain.

Scripts can be used to apply state transitions on live contracts, or deploy and initialize a complex set of smart contracts using Solidity.

OPTIONS

--broadcast
    Broadcasts the transactions.

--debug
    Open the script in the debugger. Takes precedence over broadcast.

-g
--gas-estimate-multiplier multiplier
    Relative percentage by which to multiply all gas estimates. (i.e. set to 200 to double them)     Default: 130

--json
    Output results in JSON format.
    Note: The output is under development and prone to change.

--legacy
    Use legacy transactions instead of EIP1559 ones. This is auto-enabled for common networks without EIP1559.

--resume
    Resumes submitting transactions that failed or timed-out previously.

-s
--sig signature
    The signature of the function you want to call in the contract, or raw calldata.
    Default: run()

--skip-simulation
    Skips on-chain simulation.

--skip
    Skip compilation of non-essential contract directories like test or script (usage --skip test).

--non-interactive
    Remove interactive prompts which appear if the contract is near the EIP-170 size limit.

--slow
    Makes sure a transaction is sent, only after its previous one has been confirmed and succeeded.

--target-contract contract_name
    The name of the contract you want to run.

--priority-gas-price
    Sets the priority gas price for EIP1559 transactions. Useful for when gas prices are volatile and you want to get your transaction included.

--with-gas-price price
    Sets the gas price for broadcasted legacy transactions, or the max fee for broadcasted EIP1559 transactions.
    Note: To set the gas price in the execution environment of the script use --gas-price instead (see below).

{{#include ../common/etherscan-options.md}}

Verification Options

--verify
    If it finds a matching broadcast log, it tries to verify every contract found in the receipts.

{{#include ../common/verifier-options.md}}

{{#include ../common/retry-options.md}}

{{#include core-build-options.md}}

Build Options

--names
    Print compiled contract names.

--sizes
    Print compiled non-test contract sizes, exiting with code 1 if any of them are above the size limit.

{{#include watch-options.md}}

{{#include ../common/multi-wallet-options.md}}

{{#include evm-options.md}}

{{#include executor-options.md}}

{{#include common-options.md}}

EXAMPLES

  1. Run BroadcastTest as a script, broadcasting generated transactions on-chain

    forge script ./test/Broadcast.t.sol --tc BroadcastTest --sig "deploy()" \
        -vvv --fork-url $SEPOLIA_RPC_URL
  2. Deploy a contract on Polygon (see scripting tutorial for an example script). The verifier url is different for every network.

    forge script script/NFT.s.sol:MyScript --chain-id 137 --rpc-url $RPC_URL \
        --etherscan-api-key $POLYGONSCAN_API_KEY --verifier-url https://api.polygonscan.com/api \
        --broadcast --verify -vvvv
  3. Resume a failed script. Using the above as an example, remove --broadcast add --resume

    forge script script/NFT.s.sol:MyScript --chain-id 137 --rpc-url $RPC_URL \
        --etherscan-api-key $POLYGONSCAN_API_KEY --verifier-url https://api.polygonscan.com/api \
        --verify -vvvv --resume
  4. Verify contracts that were just deployed with a script

    forge script script/NFT.s.sol --rpc-url $RPC_URL --verify --resume