Crate solc

Source
Available on crate feature solc only.
Expand description

§ethers-solc

Utilities for working with native solc and compiling projects.

Warning

This crate is deprecated in favor of foundry-compilers (foundry-rs/compilers). See #2667 for more information.

To also compile contracts during cargo build (so that ethers abigen! can pull in updated abi automatically) you can configure a ethers_solc::Project in your build.rs file

First add ethers-solc to your cargo build-dependencies.

Once you compiled the project, you can configure cargo change detection with rerun_if_sources_changed, so that cargo will execute the build.rs file if a contract in the sources directory has changed

[build-dependencies]
ethers-solc = { git = "https://github.com/gakonst/ethers-rs" }
use ethers_solc::{Project, ProjectPathsConfig};

fn main() {
    // configure the project with all its paths, solc, cache etc.
    let project = Project::builder()
        .paths(ProjectPathsConfig::hardhat(env!("CARGO_MANIFEST_DIR")).unwrap())
        .build()
        .unwrap();
    let output = project.compile().unwrap();

    // Tell Cargo that if a source file changes, to rerun this build script.
    project.rerun_if_sources_changed();
}

Modules§

artifacts
Solc artifact types
buildinfo
Represents an entire build
cache
Support for compiling contracts
contracts
error
hh
Hardhat support
info
Commonly used identifiers for contracts in the compiled output
many
output
The output of a compiled project
project
Manages compiling of a Project
remappings
report
Subscribe to events in the compiler pipeline
resolver
Resolution of the entire dependency graph for a project.
sourcemap
sources
utils
Utility functions

Structs§

AggregatedCompilerOutput
The aggregated output of (multiple) compile jobs
AllowedLibPaths
Helper struct for serializing --allow-paths arguments to Solc
ArtifactFile
Represents an artifact file representing a crate::Contract
ArtifactId
Represents unique artifact metadata for identifying artifacts on output
Artifacts
Represents a set of Artifacts
CompilerInput
Input type solc expects
CompilerOutput
Output type solc produces
ConfigurableArtifacts
An Artifact implementation that can be configured to include additional content and emit additional files
ConfigurableContractArtifact
Represents the Artifact that ConfigurableArtifacts emits.
ExtraOutputFiles
Determines what to emit as additional file
ExtraOutputValues
Determines the additional values to include in the contract’s artifact file
Graph
Represents a fully-resolved solidity dependency graph. Each node in the graph is a file and edges represent dependencies between them. See also https://docs.soliditylang.org/en/latest/layout-of-source-files.html?highlight=import#importing-other-source-files
HardhatArtifact
A hardhat artifact
HardhatArtifacts
Hardhat style artifacts handler
MinimalCombinedArtifacts
An Artifact implementation that uses a compact representation
MinimalCombinedArtifactsHardhatFallback
An Artifacts handler implementation that works the same as MinimalCombinedArtifacts but also supports reading hardhat artifacts if an initial attempt to deserialize an artifact failed
OutputContext
Additional context to use during ArtifactOutput::on_output()
Project
Represents a project workspace and handles solc compiling of all contracts in that workspace.
ProjectBuilder
ProjectCompileOutput
Contains a mixture of already compiled/cached artifacts and the input set of sources that still need to be compiled.
ProjectPaths
This is a subset of ProjectPathsConfig that contains all relevant folders in the project
ProjectPathsConfig
Where to find all files or where to write them
Solc
Abstraction over solc command line utility
SolcConfig
The config to use when compiling the contracts
TestFileFilter
An FileFilter that matches all solidity files that end with .t.sol

Enums§

EvmVersion
EVM versions.
PathStyle
SolcVersion
A Solc version is either installed (available locally) or can be downloaded, from the remote endpoint

Constants§

BERLIN_SOLC
Berlin support https://blog.soliditylang.org/2021/06/10/solidity-0.8.5-release-announcement/
BYZANTIUM_SOLC
Support for configuring the EVM version https://blog.soliditylang.org/2018/03/08/solidity-0.4.21-release-announcement/
CONSTANTINOPLE_SOLC
Bug fix for configuring the EVM version with Constantinople https://blog.soliditylang.org/2018/03/08/solidity-0.4.21-release-announcement/
ISTANBUL_SOLC
Istanbul support https://blog.soliditylang.org/2019/12/09/solidity-0.5.14-release-announcement/
LONDON_SOLC
London support https://blog.soliditylang.org/2021/08/11/solidity-0.8.7-release-announcement/
PARIS_SOLC
Paris support https://blog.soliditylang.org/2023/02/01/solidity-0.8.18-release-announcement/
PETERSBURG_SOLC
Petersburg support https://blog.soliditylang.org/2019/03/05/solidity-0.5.5-release-announcement/
SHANGHAI_SOLC
Shanghai support https://blog.soliditylang.org/2023/05/10/solidity-0.8.20-release-announcement/
SOLC
The name of the solc binary on the system

Statics§

RELEASESsvm-solc and non-WebAssembly
A list of upstream Solc releases, used to check which version we should download. The boolean value marks whether there was an error accessing the release list
SUPPORTS_BASE_PATH
SUPPORTS_INCLUDE_PATH

Traits§

Artifact
A trait representation for a crate::Contract artifact
ArtifactOutput
Handler invoked with the output of solc
FileFilter
A predicate property that determines whether a file satisfies a certain condition