### Setup Local Environment with Bash Source: https://github.com/apeworx/ape-addressbook/blob/main/CONTRIBUTING.md This snippet provides bash commands to clone the Ape Addressbook repository, set up a Python virtual environment, and install the project and its development dependencies. ```bash git clone https://github.com/ApeWorX/ape-addressbook.git cd ape-addressbook python3 -m venv venv source venv/bin/activate python setup.py install pip install -e .[dev] ``` -------------------------------- ### Install Ape Addressbook via Setuptools Source: https://github.com/apeworx/ape-addressbook/blob/main/README.md Installs the most up-to-date version of the ape-addressbook plugin by cloning the repository and using setuptools. Requires Git and Python 3.9-3.12. ```bash git clone https://github.com/ApeWorX/ape-addressbook.git cd ape-addressbookpython3 setup.py install ``` -------------------------------- ### Install Ape Addressbook via Pip Source: https://github.com/apeworx/ape-addressbook/blob/main/README.md Installs the latest release of the ape-addressbook plugin using pip. Ensure Python 3.9-3.12 is installed. ```bash pip install ape-addressbook ``` -------------------------------- ### Configure and Use Addressbook in Python Source: https://github.com/apeworx/ape-addressbook/blob/main/README.md Demonstrates how to add a shared account to the ape-config.yaml file and then access it within a Python script using the ape-addressbook plugin. ```yaml addressbook: shared_account: "0x2192f6112a026bce4047CeD2A16553Fd31E798B6" ``` ```python from ape_addressbook import addressbook address = addressbook["shared_account"] ``` -------------------------------- ### Install Pre-Commit Hooks with Bash Source: https://github.com/apeworx/ape-addressbook/blob/main/CONTRIBUTING.md This snippet shows how to install and enable pre-commit hooks using pip and the pre-commit command-line tool. These hooks help maintain code quality and consistency. ```bash pip install pre-commit pre-commit install ``` -------------------------------- ### Iterate Over All Aliases in Address Registry Source: https://context7.com/apeworx/ape-addressbook/llms.txt Shows how to use the `addressbook.aliases` property to get an iterator over all registered alias names. This is useful for listing or iterating through all configured addresses in the registry. ```python from ape_addressbook import addressbook # Get all registered aliases as a list all_aliases = list(addressbook.aliases) print(all_aliases) # Output: ['dao_multisig', 'team_wallet', 'treasury', 'uniswap_router'] # Iterate over all aliases for alias in addressbook.aliases: address = addressbook[alias] print(f"{alias}: {address}") # Output: # dao_multisig: 0xBc8563cb0EedBd1b95CCaFd0c156e2Daf5E18c29 # team_wallet: 0x1234567890123456789012345678901234567890 # treasury: 0x2192f6112a026bce4047CeD2A16553Fd31E798B6 # uniswap_router: 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D ``` -------------------------------- ### Access Address Registry using Aliases Source: https://context7.com/apeworx/ape-addressbook/llms.txt Demonstrates how to access the address registry using the `addressbook` singleton. It shows retrieving addresses by alias, checking for alias existence, and handling cases where an alias is not found. ```python from ape_addressbook import addressbook # Access an address by its alias (returns AddressType) treasury_address = addressbook["treasury"] print(treasury_address) # Output: 0x2192f6112a026bce4047CeD2A16553Fd31E798B6 # Check if an alias exists in the addressbook if "dao_multisig" in addressbook: dao_address = addressbook["dao_multisig"] print(f"DAO Multisig: {dao_address}") # Handle missing aliases gracefully try: unknown = addressbook["nonexistent_alias"] except IndexError as e: print(f"Error: {e}") # Output: Error: Alias 'nonexistent_alias' not in addressbook. ``` -------------------------------- ### Deploy Contract with Treasury Address (Python) Source: https://context7.com/apeworx/ape-addressbook/llms.txt Demonstrates how to deploy a contract and pass a treasury address obtained from the addressbook to its constructor. This highlights the direct usage of addressbook entries in contract interactions. ```python treasury = addressbook["treasury"] contract = me.deploy(MyContract, treasury) # Pass treasury address to constructor ``` -------------------------------- ### Address Conversion and Alias Validation (Python) Source: https://context7.com/apeworx/ape-addressbook/llms.txt Shows how to use Ape's conversion system to resolve addressbook aliases to actual addresses and how to check if a string is a valid addressbook alias using the AddressBookConverter. This enables seamless alias usage across the framework. ```python from ape import convert from ape.types import AddressType from ape_addressbook import addressbook # The converter automatically resolves aliases to addresses # when using ape's convert function resolved = convert("treasury", AddressType) print(resolved) # Check if a string is a valid addressbook alias from ape_addressbook.converters import AddressBookConverter converter = AddressBookConverter() print(converter.is_convertible("treasury")) # True print(converter.is_convertible("0x1234...")) # False (not an alias) print(converter.is_convertible("unknown")) # False (alias not in addressbook) ``` -------------------------------- ### Access Full Address Dictionary Registry Source: https://context7.com/apeworx/ape-addressbook/llms.txt Demonstrates accessing the complete address registry using `addressbook.registry`. This property returns a dictionary mapping all aliases to their corresponding addresses, sorted alphabetically. ```python from ape_addressbook import addressbook # Get the full registry dictionary registry = addressbook.registry print(registry) # Output: { # 'dao_multisig': '0xBc8563cb0EedBd1b95CCaFd0c156e2Daf5E18c29', # 'team_wallet': '0x1234567890123456789012345678901234567890', # 'treasury': '0x2192f6112a026bce4047CeD2A16553Fd31E798B6', # 'uniswap_router': '0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D' # } # Use registry for batch operations for alias, address in registry.items(): print(f"Alias '{alias}' points to {address}") ``` -------------------------------- ### Send Transactions Using Address Aliases Source: https://context7.com/apeworx/ape-addressbook/llms.txt Demonstrates how to use addressbook aliases directly within Ape account transactions. This feature allows sending funds to named addresses without hard-coding them in scripts, improving readability and maintainability. ```python from ape import accounts from ape_addressbook import addressbook # Load your account me = accounts.load("my_account") # Get recipient address from addressbook recipient = addressbook["team_wallet"] # Send transaction using the resolved address receipt = me.transfer(recipient, "1.5 ether") print(f"Transaction hash: {receipt.txn_hash}") print(f"Sent to: {recipient}") ``` -------------------------------- ### Access Addressbook Configuration Object Source: https://context7.com/apeworx/ape-addressbook/llms.txt Explains how to access the `AddressBookConfig` object via `addressbook.config`. This object holds the raw configuration entries directly from `ape-config.yaml`, allowing direct access to configuration data. ```python from ape_addressbook import addressbook # Access the config object config = addressbook.config print(f"Number of configured addresses: {len(config)}") # Output: Number of configured addresses: 4 # Access config entries directly print(config["treasury"]) # Output: 0x2192f6112a026bce4047CeD2A16553Fd31E798B6 # Get all config data as dictionary config_data = config.model_dump() print(config_data) ``` -------------------------------- ### Automatic Address Checksum Validation (YAML & Python) Source: https://context7.com/apeworx/ape-addressbook/llms.txt Illustrates how the plugin automatically validates and checksums EVM addresses defined in the `ape-config.yaml` file, supporting both lowercase and integer formats. The corresponding Python snippet shows how these addresses are accessed in a checksummed format. ```yaml # ape-config.yaml - addresses are automatically checksummed addressbook: # Lowercase address - will be checksummed automatically my_address: "0xbc8563cb0eedbd1b95ccafd0c156e2daf5e18c29" # Integer format - also supported another_address: 0xbc8563cb0eedbd1b95ccafd0c156e2daf5e18c29 ``` ```python from ape_addressbook import addressbook # Both entries are properly checksummed when accessed address = addressbook["my_address"] print(address) # The validation ensures consistency across all address formats int_address = addressbook["another_address"] print(int_address) ``` -------------------------------- ### Configure Address Aliases in ape-config.yaml Source: https://context7.com/apeworx/ape-addressbook/llms.txt Defines address aliases within the `ape-config.yaml` file. These aliases serve as human-readable names for blockchain addresses, creating a reusable registry for your project. ```yaml # ape-config.yaml addressbook: # Define addresses with human-readable aliases treasury: "0x2192f6112a026bce4047CeD2A16553Fd31E798B6" dao_multisig: "0xbc8563cb0eedbd1b95ccafd0c156e2daf5e18c29" uniswap_router: "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D" team_wallet: "0x1234567890123456789012345678901234567890" ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.