forge bind
NAME
forge-bind - Generate Rust bindings for smart contracts.
SYNOPSIS
forge bind
[options]
DESCRIPTION
Generates Rust bindings for smart contracts using ethers-rs.
The bindings are generated from the project's artifacts, which by default is ./out/
.
If you want to generate bindings for artifacts in a different directory, pass --bindings-path <PATH>
.
There are three output options:
- Generate bindings in a crate (default)
- Generate bindings in a module by passing
--module
- Generate bindings in a single file by passing
--single-file
By default, the command will check that existing bindings are correct and exit accordingly.
You can overwrite the existing bindings by passing --overwrite
.
OPTIONS
Project Options
-b
path
--bindings-path
path
The project's root path. By default, this is the root directory of the current git repository, or the current working directory.
--crate-name
name
The name of the Rust crate to generate, if you are generating a crate (default).
This should be a valid crates.io crate name.
Default: foundry-contracts
--crate-version
semver
The version of the Rust crate to generate, if you are generating a crate (default).
This should be a standard semver version string.
Default: 0.0.1
--module
Generate the bindings as a module instead of a crate.
--single-file
Generate bindings as a single file.
--overwrite
Overwrite existing generated bindings. By default, the command will check that the bindings are correct, and then exit.
If --overwrite
is passed, it will instead delete and overwrite the bindings.
--root
path
The project's root path. By default, this is the root directory of the current git repository, or the current working directory.
--skip-cargo-toml
Skip Cargo.toml consistency checks.
This allows you to manage the ethers version without giving up on consistency checks.
An example would be if you use additional features of ethers like ws
, ipc
, or rustls
and get an ethers-providers
version mismatch.
--skip-build
Skips running forge build before generating binding.
This allows you to skip the default forge build
step that's executed first and instead generate bindings using the already existing artifacts.
--select-all
By default all contracts ending with Test
or Script
are excluded. This will explicitly generate bindings for all contracts. Conflicts with --select
and --skip
.
--select
regex+
Create bindings only for contracts whose names match the specified filter(s). Conflicts with --skip
.
--skip
regex+
Create bindings only for contracts whose names do not match the specified filter(s). Conflicts with --select
.
Common Options
-h
--help
Prints help information.
Cache Options
--force
Clear the cache and artifacts folder and recompile.
Linker Options
--libraries
libraries
Set pre-linked libraries.
The parameter must be in the format <remapped path to lib>:<library name>:<address>
, e.g. src/Contract.sol:Library:0x...
.
Can also be set in your configuration file as libraries = ["<path>:<lib name>:<address>"]
.
Compiler Options
--optimize
Activate the Solidity optimizer.
--optimizer-runs
runs
The number of optimizer runs.
--via-ir
Use the Yul intermediate representation compilation pipeline.
--revert-strings
How to treat revert and require reason strings.
--use
solc_version
Specify the solc version, or a path to a local solc, to build with.
Valid values are in the format x.y.z
, solc:x.y.z
or path/to/solc
.
--offline
Do not access the network. Missing solc versions will not be installed.
--no-auto-detect
Do not auto-detect solc.
--ignored-error-codes
error_codes
Ignore solc warnings by error code. The parameter is a comma-separated list of error codes.
--extra-output
selector
Extra output to include in the contract's artifact.
Example keys: abi
, storageLayout
, evm.assembly
, ewasm
, ir
, ir-optimized
, metadata
.
For a full description, see the Solidity docs.
--extra-output-files
selector
Extra output to write to separate files.
Example keys: abi
, storageLayout
, evm.assembly
, ewasm
, ir
, ir-optimized
, metadata
.
For a full description, see the Solidity docs.
--evm-version
version
The target EVM version.
Project Options
--build-info
Generate build info files.
--build-info-path
path
Output path to directory that build info files will be written to.
--root
path
The project's root path. By default, this is the root directory of the current git repository, or the current working directory.
-c
path
--contracts
path
The contracts source directory.
Environment: DAPP_SRC
--lib-paths
path
The path to the library folder.
-r
remappings
--remappings
remappings
The project's remappings.
The parameter is a comma-separated list of remappings in the format <source>=<dest>
.
--cache-path
path
The path to the compiler cache.
--config-path
file
Path to the config file.
--hh
--hardhat
This is a convenience flag, and is the same as passing --contracts contracts --lib-paths node-modules
.
-o
path
--out
path
The project's artifacts directory.
--silent
Suppress all output.