forge-bind - Generate Rust bindings for smart contracts.
forge bind
[options]
Generates Rust bindings for smart contracts using alloy.
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
.
-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 alloy version without giving up on consistency checks.
An example would be if you use additional features of alloy and get a 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.
--skip-extra-derives
Don't add any additional derives to generated bindings.
--alloy-version
version
Specify the alloy
version on Crates.
--alloy-rev
rev
Specify the alloy
revision on GitHub.
--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
.
{{#include common-options.md}}
{{#include core-build-options.md}}