Network

class moccasin.config.Network(name: str, url: str | None = None, chain_id: int | None = None, is_fork: bool = False, block_identifier: int | str = 'safe', is_zksync: bool = False, default_account_name: str | None = None, unsafe_password_file: ~pathlib.Path | None = None, save_abi_path: str | None = None, explorer_uri: str | None = None, explorer_api_key: str | None = None, explorer_type: str | None = None, named_contracts: dict[str, ~moccasin.named_contract.NamedContract] = <factory>, prompt_live: bool = True, save_to_db: bool = True, live_or_staging: bool = True, db_path: str | ~pathlib.Path = ':memory:', extra_data: dict[str, ~typing.Any] = <factory>, _network_env: NetworkEnv | Env | ZksyncEnv | None = None)

Bases: object

Represents a Moccasin network configuration from the moccasin.toml file settings.

This class allows for flexible network configuration across different blockchain environments, supporting both local and remote networks, including special cases like forked networks.

Variables:
  • name (str) – Unique identifier for the network

  • url (str | None) – Network endpoint URL

  • chain_id (int | None) – Unique identifier for the blockchain network

  • is_fork (bool) – Indicates if the network is a forked instance

  • block_identifier (int | str) – Block identifier for the network

  • is_zksync (bool) – Indicates if the network is a zkSync network

  • default_account_name (str | None) – Default mox wallet account name to use for the network

  • unsafe_password_file (Path | None) – Path to the unsafe password file related to default_account_name

  • save_abi_path (str | None) – Path to save the ABI

  • explorer_uri (str | None) – URI of the explorer

  • explorer_api_key (str | None) – API key for the explorer

  • explorer_type (str | None) – Type of the explorer (“blockscout”, “etherscan”, “zksyncexplorer”)

  • named_contracts (dict[str, NamedContract]) – Dictionary of named contracts

  • prompt_live (bool) – A flag that will prompt you before sending a transaction, it defaults to true for “non-testing” networks

  • save_to_db (bool) – Indicates if the network should save the deployment to the database, it defaults to true for “non-testing” networks

  • live_or_staging (bool) – Indicates if the network is live or staging, defaults to true for non-local, non-forked networks

  • db_path (str | Path) – Path to the database

  • extra_data (dict[str, Any]) – Extra data for the network

  • _network_env (_AnyEnv | None) – Network environment

name: str
url: str | None = None
chain_id: int | None = None
is_fork: bool = False
block_identifier: int | str = 'safe'
is_zksync: bool = False
default_account_name: str | None = None
unsafe_password_file: Path | None = None
save_abi_path: str | None = None
explorer_uri: str | None = None
explorer_api_key: str | None = None
explorer_type: str | None = None
named_contracts: dict[str, NamedContract]
prompt_live: bool = True
save_to_db: bool = True
live_or_staging: bool = True
db_path: str | Path = ':memory:'
extra_data: dict[str, Any]
moccasin_verify(contract: VyperContract | ZksyncContract) VerificationResult

Verifies a contract using your moccasin.toml config.

Parameters:

contract (VyperContract | ZksyncContract) – The contract to verify

Returns:

The verification result of the contract

Return type:

VerificationResult

is_matching_boa() bool

Checks if the current network is the active network in boa.

This is a good way to test if you’ve overriden boa as the “active” network.

Returns:

True if the current network is the active network in boa

Return type:

bool

get_verifier_class() Any

Returns the verifier class based on the explorer type.

Returns:

The verifier class

Return type:

Any

get_default_account() MoccasinAccount | Any

Returns an ‘account-like’ object.

Returns:

An ‘account-like’ object

Return type:

MoccasinAccount | Any

set_kwargs(**kwargs)

Sets the kwargs.

Parameters:

kwargs (dict) – The kwargs

create_and_set_or_set_boa_env(**kwargs) NetworkEnv | Env | ZksyncEnv

Creates and sets the boa environment.

Parameters:

kwargs (dict) – The kwargs

Returns:

The boa environment

Return type:

_AnyEnv

get_deployments_unchecked(contract_name: str | None = None, limit: int | None = None, chain_id: int | str | None = None, config_or_db_path: Config | Path | str | None = None) list[Deployment]

Get deployments from the database without an initialized config.

This method does not check if the deployments integrity is valid. It is the responsibility of the caller to ensure that the deployments are valid.

Parameters:
  • contract_name (str | None) – The contract name

  • chain_id (int | str | None) – The chain ID

  • limit (int | None) – The limit

  • config_or_db_path (Union[Config, Path, str, None]) – The config or db path

Returns:

The deployments

Return type:

list[Deployment]

get_deployments_checked(contract_name: str | None = None, limit: int | None = None, chain_id: int | str | None = None, config_or_db_path: Config | Path | str | None = None) list[Deployment]

Get deployments from the database without an initialized config.

This method does check if the deployments integrity is valid. If not, it won’t be returned.

Parameters:
  • contract_name (str | None) – The contract name

  • chain_id (int | str | None) – The chain ID

  • limit (int | None) – The limit

  • config_or_db_path (Union[Config, Path, str, None]) – The config or db path

Returns:

The deployments

Return type:

list[Deployment]

has_matching_integrity(deployment: Deployment, contract_name: str | None, config: Config | None = None) bool

Check if the deployment has a matching integrity with the config and contract name.

Parameters:
  • deployment (Deployment) – The deployment

  • contract_name (str | None) – The contract name

  • config (Union[Config, None]) – The config

Returns:

True if the deployment has a matching integrity, False otherwise

Return type:

bool

get_deployer_from_contract_name(config: Config, contract_name: str) VyperDeployer | ZksyncDeployer

Returns the Vyper deployer for the contract name.

Parameters:
  • config (Config) – The config

  • contract_name (str) – The contract name

Returns:

The corresponding Vyper deployer

Return type:

VyperDeployer | ZksyncDeployer

get_latest_deployment_unchecked(contract_name: str | None = None, chain_id: int | str | None = None) Deployment | None

Returns the latest deployment of the contract.

It does not check if the deployment is valid.

Parameters:
  • contract_name (str | None) – The contract name

  • chain_id (int | str | None) – The chain ID

Returns:

The deployment or nothing

Return type:

Deployment | None

get_latest_contract_unchecked(contract_name: str | None = None, chain_id: int | str | None = None) ABIContract | None

Returns the latest contract of the contract.

It does not check if the deployment is valid.

Parameters:
  • contract_name (str | None) – The contract name

  • chain_id (int | str | None) – The chain ID

Returns:

The contract or nothing

Return type:

ABIContract | None

get_latest_deployment_checked(contract_name: str | None = None, chain_id: int | str | None = None) Deployment | None

Returns the latest deployment of the contract.

It does check if the deployment is valid.

Parameters:
  • contract_name (str | None) – The contract name

  • chain_id (int | str | None) – The chain ID

Returns:

The deployment or nothing

Return type:

Deployment | None

get_latest_contract_checked(contract_name: str | None = None, chain_id: int | str | None = None) ABIContract | None

Returns the latest contract of the contract.

It does check if the deployment is valid.

Parameters:
  • contract_name (str | None) – The contract name

  • chain_id (int | str | None) – The chain ID

Returns:

The contract or nothing

Return type:

ABIContract | None

manifest_contract(contract_name: str, force_deploy: bool = False, address: str | None = None, checked: bool = False) VyperContract | ZksyncContract | ABIContract

A wrapper around get_or_deploy_named that is more explicit about the contract being deployed.

Parameters:
  • contract_name (str) – The contract name

  • force_deploy (bool) – If True, will deploy the contract even if the contract has an address in the config file.

  • address (str | None) – The address of the contract

  • checked (bool) – If True, will check if the deployment is valid

Returns:

The contract

Return type:

VyperContract | ZksyncContract | ABIContract

instantiate_contract(*args, **kwargs) VyperContract | ZksyncContract | ABIContract

An alias for get_or_deploy_named.

Deprecated and will be removed in a future version, please use get_or_deploy_named.

get_or_deploy_contract(*args, **kwargs) VyperContract | ZksyncContract | ABIContract

A wrapper around get_or_deploy_named.

Deprecated and will be removed in a future version, please use get_or_deploy_named.

manifest_named_contract(*args, **kwargs) VyperContract | ZksyncContract | ABIContract

A wrapper around get_or_deploy_named that is more explicit about the contract being deployed.

get_or_deploy_named_contract(*args, **kwargs) VyperContract | ZksyncContract | ABIContract

A wrapper around get_or_deploy_named that is more explicit about the contract being deployed.

Deprecated and will be removed in a future version, please use get_or_deploy_named.

manifest_named(*args, **kwargs) VyperContract | ZksyncContract | ABIContract

A wrapper around get_or_deploy_named that is more explicit about the contract being deployed.

get_or_deploy_named(contract_name: str, force_deploy: bool = False, abi: str | Path | list | VyperDeployer | VyperContract | ZksyncContract | ZksyncDeployer | ABIContractFactory | ABIContract | None = None, abi_from_explorer: bool | None = None, deployer_script: str | Path | None = None, address: str | None = None) VyperContract | ZksyncContract | ABIContract

Returns or deploys a VyperContract, ZksyncContract, or ABIContract based on the name and address in the config file, or passed to this function.

The following arguments are mutually exclusive:
  • abi

  • abi_from_explorer

Parameters:
  • contract_name (str) – the contract name.

  • force_deploy (bool) – if True, will deploy the contract even if the contract has an address in the config file.

  • abi (str | Path | list | VyperDeployer | VyperContract | ZksyncDeployer | ZksyncContract | ABIContractFactory | ABIContract | None) – the ABI of the contract. Can be a list, string path to file, string of the ABI, VyperDeployer, VyperContract, ZksyncDeployer, ZksyncContract, ABIContractFactory, or ABIContract.

  • abi_from_explorer (bool | None) – if True, will fetch the ABI from the explorer.

  • deployer_script (str | Path | None) – If no address is given, this is the path to deploy the contract.

  • address (str | None) – If no address is given, this is the address to deploy the contract.

Returns:

The deployed contract instance, or a blank contract if the contract is not found.

Return type:

VyperContract | ZksyncContract | ABIContract

is_local_or_forked_network() bool

Checks if the network is:

  1. pyevm

  2. eravm

  3. A fork

Returns:

True if the network is local or forked, False otherwise.

Return type:

bool

has_explorer() bool

Check if explorer is set in network config.

Returns:

True if explorer is set, False otherwise

Return type:

bool

get_named_contract(contract_name: str) NamedContract | None

Returns the named contract with the given name.

Parameters:

contract_name (str) – the name of the contract.

Returns:

the named contract.

Return type:

NamedContract | None

get_named_contracts() dict

Returns a dictionary of named contracts.

Returns:

a dictionary of named contracts.

Return type:

dict

set_boa_eoa(account: MoccasinAccount)

Sets the boa.env.eoa to the given Moccasin account.

Parameters:

account (MoccasinAccount) – the account to set the boa.env.eoa to.

property alias: str
property identifier: str
static convert_deployment_to_contract(deployment: Deployment) ABIContract

Returns the ABIContract from the given deployment.

Parameters:

deployment (Deployment) – the deployment to convert

Returns:

the ABIContract at the given address

Return type:

ABIContract