pub struct StandardJsonInput {
pub language: Language,
pub sources: BTreeMap<String, Source>,
pub settings: Settings,
}Expand description
Represents the Solidity compiler’s Standard JSON StandardJsonInput object used by
solc --standard-json.
This struct mirrors the compiler’s JSON schema:
languageselects the source language (for exampleSolidityorYul).sourcesmaps logical file names toSourceentries (either literal content or a list of URLs). SeeSourcefor details oncontentvsurls.settingsconfigures the compiler (optimizer, output selection, model checker, metadata, etc.).
The struct is serialized using camelCase fields to match the compiler’s
expected keys. Use the builder-style helpers (StandardJsonInput::new, add_source,
add_source_urls, model_checker) for common workflows. For advanced
configuration modify input.settings directly.
Example:
use solc::StandardJsonInput;
let input = StandardJsonInput::new()
.add_source("Counter.sol", "contract Counter { uint x; }");
let json = serde_json::to_string(&input).unwrap();For a complete description of available settings and outputSelection
values consult the Solidity documentation for the Standard JSON
Input/Output interface.
Fields§
§language: LanguageThe source language for the provided sources map.
This is serialized to the compiler-expected string (for example
"Solidity" or "Yul"). It defaults to Language::Solidity via
StandardJsonInput::new() and controls how the compiler interprets the provided
source files (regular Solidity source files, pre-parsed ASTs, or EVM
assembly).
sources: BTreeMap<String, Source>A mapping from logical filenames to Source entries.
The keys are the virtual/global names used by the compiler and by
outputSelection (for example "src/Contract.sol"). Each value is a
Source that either embeds literal content or specifies urls to
fetch the source (optionally validated with a keccak256 hash).
Use StandardJsonInput::add_source or StandardJsonInput::add_source_urls to populate this
map in a safe, builder-style manner.
settings: SettingsTop-level compiler settings that control optimization, outputs,
EVM target, metadata, libraries, model checking and debugging behavior.
Most fields are optional and will be omitted from serialized JSON if
left as None. Set only the options you need such as enabling the
optimizer, setting evmVersion, populating outputSelection, or providing
library addresses in libraries to request linked artifacts.
Implementations§
Source§impl StandardJsonInput
impl StandardJsonInput
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new, empty StandardJsonInput with sensible defaults:
languagedefaults toLanguage::Solidity.sourcesis empty.settingsusesSettings::default().
The methods on StandardJsonInput return Self to enable builder-style chaining.
Sourcepub fn add_source(
self,
name: impl Into<String>,
content: impl Into<String>,
) -> Self
pub fn add_source( self, name: impl Into<String>, content: impl Into<String>, ) -> Self
Add a source by literal content.
name is the logical filename used by the compiler (for example
"MyContract.sol"). If a source with the same name already exists it
will be replaced. The resulting JSON contains { "content": "..." }.
Sourcepub fn add_source_urls(
self,
name: impl Into<String>,
urls: Vec<String>,
hash: Option<String>,
) -> Self
pub fn add_source_urls( self, name: impl Into<String>, urls: Vec<String>, hash: Option<String>, ) -> Self
Add a source that should be fetched from one or more urls (for example
IPFS or bzzr addresses). Optionally provide the keccak256 hash to
validate downloaded content.
The serialized JSON will be { "urls": [...], "keccak256": "0x..." }.
Sourcepub fn model_checker(self, settings: ModelCheckerSettings) -> Self
pub fn model_checker(self, settings: ModelCheckerSettings) -> Self
Set the modelChecker section of settings (builder-style).
Trait Implementations§
Source§impl Clone for StandardJsonInput
impl Clone for StandardJsonInput
Source§fn clone(&self) -> StandardJsonInput
fn clone(&self) -> StandardJsonInput
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more