StandardJsonInput

Struct StandardJsonInput 

Source
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:

  • language selects the source language (for example Solidity or Yul).
  • sources maps logical file names to Source entries (either literal content or a list of URLs). See Source for details on content vs urls.
  • settings configures 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: Language

The 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: Settings

Top-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

Source

pub fn new() -> Self

Create a new, empty StandardJsonInput with sensible defaults:

  • language defaults to Language::Solidity.
  • sources is empty.
  • settings uses Settings::default().

The methods on StandardJsonInput return Self to enable builder-style chaining.

Source

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": "..." }.

Source

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..." }.

Source

pub fn model_checker(self, settings: ModelCheckerSettings) -> Self

Set the modelChecker section of settings (builder-style).

Trait Implementations§

Source§

impl Clone for StandardJsonInput

Source§

fn clone(&self) -> StandardJsonInput

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for StandardJsonInput

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for StandardJsonInput

Source§

fn default() -> StandardJsonInput

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for StandardJsonInput

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for StandardJsonInput

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,