forge

package
v1.20.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 37 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrCompiled is returned by RunScript when forge starts to compile the project.
	ErrCompiled = errors.New("forge compiled the project")
	// ErrScriptReverted is returned by RunScript when the script itself reverts. Any other failure,
	// such as an RPC error or a failed cheatcode, may pass when the script runs again.
	ErrScriptReverted = errors.New("forge script reverted")
)
View Source
var ArtifactsReadPermission = FsPermission{Access: "read", Path: "./forge-artifacts/"}

ArtifactsReadPermission lets the scripts of a contracts bundle read its artifacts, as DeployUtils.getCode does.

View Source
var StandardVersion string

StandardVersion is the Foundry version that op-deployer will download if it's not found on PATH.

Functions

func ConvertAnonStructToTyped

func ConvertAnonStructToTyped[T any](anonStruct any) (result T, err error)

ConvertAnonStructToTyped converts anonStruct to T and returns conversion failures as errors. The source and target must be structs with equal field counts at every corresponding struct.

func GoStructToABITuple

func GoStructToABITuple(structType reflect.Type, tupleName string) (abi.Type, error)

func GoTypeToABIType

func GoTypeToABIType(goType reflect.Type) (string, error)

Types

type Bin

type Bin struct {
	// contains filtered or unexported fields
}

func (*Bin) Ensure

func (b *Bin) Ensure(ctx context.Context) error

func (*Bin) Path

func (b *Bin) Path() string

type Binary

type Binary interface {
	Ensure(ctx context.Context) error
	Path() string
}

func PathBinary

func PathBinary() Binary

func StaticBinary

func StaticBinary(path string) Binary

type BytesScriptDecoder

type BytesScriptDecoder[T any] struct {
	TypeName string // e.g., "DeploySuperchainOutput"
}

func (*BytesScriptDecoder[T]) Decode

func (d *BytesScriptDecoder[T]) Decode(rawOutput []byte) (T, error)

type BytesScriptEncoder

type BytesScriptEncoder[T any] struct {
	TypeName string // e.g., "DeploySuperchainInput"
}

func (*BytesScriptEncoder[T]) Encode

func (e *BytesScriptEncoder[T]) Encode(input T) ([]byte, error)

type Client

type Client struct {
	Binary Binary
	Stdout io.Writer
	Stderr io.Writer
	Wd     string
	// FsPermissions are the file accesses of a script run. The project config's are ignored.
	FsPermissions []FsPermission
	// Timeout bounds each forge invocation. Zero means no limit.
	Timeout time.Duration
	// Env holds KEY=VALUE variables for each forge command, on top of the inherited environment.
	Env []string
	// AnyCacheProfile lets a script run take the compile settings of the project profile that the
	// compile cache was built with, such as a lite build's, instead of only the default profile's.
	// Such a build can hold contracts above the EIP-170 code size limit, so set it only for runs
	// that deploy no contract to a chain, such as an offline genesis run without a code size limit.
	AnyCacheProfile bool
}

func NewClient

func NewClient(binary Binary) *Client

NewClient returns a client for binary. forge output goes to stderr; stdout is for results.

func NewStandardClient

func NewStandardClient(workdir string, binOpts ...StandardBinOpt) (*Client, error)

func (*Client) Build

func (c *Client) Build(ctx context.Context, opts ...string) error

func (*Client) Clean

func (c *Client) Clean(ctx context.Context, opts ...string) error

func (*Client) RunScript

func (c *Client) RunScript(ctx context.Context, script string, sig string, args []byte, opts ...string) (string, []Transaction, error)

RunScript runs a prebuilt script without a compile. It returns forge's output and the transactions that the script would send, which forge records in the run's private dry-run file; a --broadcast run sends them itself and returns none. Not --offline: offline, forge requires the solc versions of the cache installed even when it compiles nothing. Each run gets its own copy of the compile cache and its own broadcast directory, so concurrent runs write no shared file.

func (*Client) VerifyContract

func (c *Client) VerifyContract(ctx context.Context, opts ...string) (string, error)

func (*Client) Version

func (c *Client) Version(ctx context.Context) (VersionInfo, error)

func (*Client) WithEnv added in v1.20.2

func (c *Client) WithEnv(env ...string) *Client

WithEnv returns a copy of the client with the given KEY=VALUE variables added.

type Fork added in v1.20.2

type Fork struct {
	// contains filtered or unexported fields
}

Fork is an ephemeral anvil fork. Every account is unlocked, so forge can send with --unlocked.

func StartFork added in v1.20.2

func StartFork(ctx context.Context, anvil Binary, rpcURL string, blockNumber uint64) (*Fork, error)

StartFork starts anvil on a free loopback port as a fork of rpcURL at blockNumber.

func (*Fork) RPCURL added in v1.20.2

func (f *Fork) RPCURL() string

RPCURL returns the RPC URL of the fork.

func (*Fork) Stop added in v1.20.2

func (f *Fork) Stop() error

Stop stops anvil and removes its state.

type FsPermission added in v1.20.2

type FsPermission struct {
	Access string `toml:"access"`
	Path   string `toml:"path"`
}

FsPermission is one entry of the fs_permissions of a forge config.

type None added in v1.20.2

type None struct{}

None is the empty input or output of a script.

type NoneDecoder added in v1.20.2

type NoneDecoder struct{}

NoneDecoder decodes an empty return value.

func (NoneDecoder) Decode added in v1.20.2

func (NoneDecoder) Decode(rawOutput []byte) (None, error)

type NoneEncoder added in v1.20.2

type NoneEncoder struct{}

NoneEncoder encodes None as no input.

func (NoneEncoder) Encode added in v1.20.2

func (NoneEncoder) Encode(None) ([]byte, error)

type PathBin

type PathBin struct {
	// contains filtered or unexported fields
}

func (*PathBin) Ensure

func (b *PathBin) Ensure(ctx context.Context) error

func (*PathBin) Path

func (b *PathBin) Path() string

type ScriptCallDecoder

type ScriptCallDecoder[O any] interface {
	Decode(raw []byte) (O, error)
}

type ScriptCallEncoder

type ScriptCallEncoder[I any] interface {
	Encode(I) ([]byte, error)
}

type ScriptCaller

type ScriptCaller[I any, O any] func(ctx context.Context, input I, opts ...string) (O, []Transaction, error)

ScriptCaller calls a forge script. It returns the decoded return value and the transactions that the script would send.

func NewScriptCaller

func NewScriptCaller[I any, O any](client *Client, script string, sig string, encoder ScriptCallEncoder[I], decoder ScriptCallDecoder[O]) ScriptCaller[I, O]

type StandardBin

type StandardBin struct {
	// contains filtered or unexported fields
}

StandardBin forces the use of the standard version of a foundry tool, forge by default, by first checking for the version locally, then downloading from github if needed

func NewAnvilBinary added in v1.20.2

func NewAnvilBinary(opts ...StandardBinOpt) (*StandardBin, error)

NewAnvilBinary returns the standard version of anvil.

func NewStandardBinary

func NewStandardBinary(opts ...StandardBinOpt) (*StandardBin, error)

func (*StandardBin) Ensure

func (b *StandardBin) Ensure(ctx context.Context) error

func (*StandardBin) Path

func (b *StandardBin) Path() string

type StandardBinOpt

type StandardBinOpt func(s *StandardBin)

func WithCachePather

func WithCachePather(pather func() (string, error)) StandardBinOpt

func WithChecksummer

func WithChecksummer(checksummer func(r io.Reader) error) StandardBinOpt

func WithProgressor

func WithProgressor(p ioutil.Progressor) StandardBinOpt

func WithTool added in v1.20.2

func WithTool(tool string) StandardBinOpt

WithTool selects the foundry tool, one of foundryTools.

func WithURL

func WithURL(url string) StandardBinOpt

type Transaction added in v1.20.2

type Transaction struct {
	From       common.Address   `json:"from"`
	To         *common.Address  `json:"to"`
	Nonce      hexutil.Uint64   `json:"nonce"`
	Value      *hexutil.U256    `json:"value"`
	Input      hexutil.Bytes    `json:"input"`
	ChainID    *hexutil.Big     `json:"chainId"`
	Type       hexutil.Uint64   `json:"type"`
	AccessList types.AccessList `json:"accessList"`
}

Transaction is an unsigned transaction that forge recorded for a script. It has no fees or gas limit: txmgr sets them.

type VersionConfig

type VersionConfig struct {
	Forge     string            `json:"forge"`
	Checksums map[string]string `json:"checksums"`
}

type VersionInfo

type VersionInfo struct {
	Semver string
	SHA    string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL