pub struct ContractBuilder {
pub runtime_crate_name: String,
pub visibility_modifier: Option<String>,
pub contract_mod_override: Option<String>,
pub contract_name_override: Option<String>,
pub networks: HashMap<String, Network>,
pub method_aliases: HashMap<String, String>,
pub event_derives: Vec<String>,
pub rustfmt: bool,
}
Expand description
Builder for generating contract code. Note that no code is generated until
the builder is finalized with generate
or output
.
Fields§
§runtime_crate_name: String
The runtime crate name to use.
visibility_modifier: Option<String>
The visibility modifier to use for the generated module and contract re-export.
contract_mod_override: Option<String>
Override the contract module name that contains the generated code.
contract_name_override: Option<String>
Override the contract name to use for the generated type.
networks: HashMap<String, Network>
Manually specified deployed contract address and transaction hash.
method_aliases: HashMap<String, String>
Manually specified contract method aliases.
event_derives: Vec<String>
Derives added to event structs and enums.
rustfmt: bool
Format generated code sing locally installed copy of rustfmt
.
Implementations§
Source§impl ContractBuilder
impl ContractBuilder
Sourcepub fn runtime_crate_name(self, name: impl Into<String>) -> Self
pub fn runtime_crate_name(self, name: impl Into<String>) -> Self
Sets the crate name for the runtime crate. This setting is usually only needed if the crate was renamed in the Cargo manifest.
Sourcepub fn visibility_modifier(self, vis: impl Into<String>) -> Self
pub fn visibility_modifier(self, vis: impl Into<String>) -> Self
Sets an optional visibility modifier for the generated module and contract re-export.
Sourcepub fn contract_mod_override(self, name: impl Into<String>) -> Self
pub fn contract_mod_override(self, name: impl Into<String>) -> Self
Sets the optional contract module name override.
Sourcepub fn contract_name_override(self, name: impl Into<String>) -> Self
pub fn contract_name_override(self, name: impl Into<String>) -> Self
Sets the optional contract name override. This setting is needed when using an artifact JSON source that does not provide a contract name such as Etherscan.
Sourcepub fn add_network(self, chain_id: impl Into<String>, network: Network) -> Self
pub fn add_network(self, chain_id: impl Into<String>, network: Network) -> Self
Adds a deployed address and deployment transaction hash or block of a contract for a given network. Note that manually specified deployments take precedence over deployments in the artifact.
This is useful for integration test scenarios where the address of a contract on the test node is deterministic, but the contract address is not in the artifact.
Sourcepub fn add_network_str(self, chain_id: impl Into<String>, address: &str) -> Self
pub fn add_network_str(self, chain_id: impl Into<String>, address: &str) -> Self
Adds a deployed address. Parses address from string.
See [add_deployment
] for more information.
§Panics
This method panics if the specified address string is invalid. See
parse_address
for more information on the address string format.
Sourcepub fn add_method_alias(
self,
signature: impl Into<String>,
alias: impl Into<String>,
) -> Self
pub fn add_method_alias( self, signature: impl Into<String>, alias: impl Into<String>, ) -> Self
Adds a solidity method alias to specify what the method name will be in Rust. For solidity methods without an alias, the snake cased method name will be used.
Sourcepub fn rustfmt(self, rustfmt: bool) -> Self
pub fn rustfmt(self, rustfmt: bool) -> Self
Specifies whether or not to format the code using a locally installed
copy of rustfmt
.
Note that in case rustfmt
does not exist or produces an error, the
un-formatted code will be used.
Sourcepub fn add_event_derive(self, derive: impl Into<String>) -> Self
pub fn add_event_derive(self, derive: impl Into<String>) -> Self
Adds a custom derive to the derives for event structs and enums.
This makes it possible to, for example, derive serde::Serialize
and
serde::Deserialize
for events.
§Examples
let builder = ContractBuilder::new()
.add_event_derive("serde::Serialize")
.add_event_derive("serde::Deserialize");
Sourcepub fn generate(self, contract: &Contract) -> Result<ContractBindings>
pub fn generate(self, contract: &Contract) -> Result<ContractBindings>
Generates the contract bindings.