### Install ledgereth with pip (System Python) Source: https://github.com/mikeshultz/ledger-eth-lib/blob/master/docs/install.rst Install the ledgereth Python library using pip. This command installs the package for the current user. ```bash $ pip install --user ledgereth ``` -------------------------------- ### Install ledgereth via pip Source: https://github.com/mikeshultz/ledger-eth-lib/blob/master/docs/index.rst Use this command to install the library in your Python environment. ```bash pip install ledgereth ``` -------------------------------- ### Install pip and venv on Ubuntu Source: https://github.com/mikeshultz/ledger-eth-lib/blob/master/docs/install.rst Install the necessary package management tools for Python on Ubuntu systems. The python3-venv package is optional but recommended. ```bash $ apt install python3-venv python3-pip ``` -------------------------------- ### Install ledgereth with pip (Virtual Environment) Source: https://github.com/mikeshultz/ledger-eth-lib/blob/master/docs/install.rst Install the ledgereth Python library within a virtual environment. This is a recommended approach for managing project dependencies. ```bash python -m venv ~/virtualenvs/ledgereth source ~/virtualenvs/ledgereth/bin/activate pip install ledgereth ``` -------------------------------- ### Install Development Tools on Arch Linux Source: https://github.com/mikeshultz/ledger-eth-lib/blob/master/docs/install.rst Install essential development tools and Python on Arch Linux. This ensures you have the necessary build tools for Python dependencies. ```bash $ pacman -S base-devel python ``` -------------------------------- ### Install Development Tools on REHL/CentOS Source: https://github.com/mikeshultz/ledger-eth-lib/blob/master/docs/install.rst Install the 'Development Tools' group and the python3-devel package on REHL/CentOS systems. These are required for compiling certain Python dependencies. ```bash $ dnf groupinstall "Development Tools" $ dnf install python3-devel ``` -------------------------------- ### Get Ledger Device Vendor and Product ID Source: https://github.com/mikeshultz/ledger-eth-lib/blob/master/docs/install.rst Use this command to find the vendor and product ID for your Ledger device, which is necessary for creating udev rules. ```bash $ lsusb | grep Ledger Bus 001 Device 010: ID 2c97:1015 Ledger Nano S ``` -------------------------------- ### Accounts API Source: https://github.com/mikeshultz/ledger-eth-lib/blob/master/docs/accounts.rst Functions to get details on the accounts derived from the Ledger's private key. ```APIDOC ## Accounts API ### Description Functions to get details on the accounts derived from the Ledger's private key. ### Module `ledgereth.accounts` ### Functions This module exposes various functions for account management. Please refer to the specific function documentation for details on parameters and return values. ``` -------------------------------- ### Initialize Ledger accounts in Python Source: https://context7.com/mikeshultz/ledger-eth-lib/llms.txt Configure environment settings programmatically and retrieve accounts using the ledgereth library. ```python import os os.environ["LEDGER_LEGACY_ACCOUNTS"] = "1" os.environ["MAX_ACCOUNTS_FETCH"] = "20" from ledgereth import get_accounts, find_account # Now uses legacy derivation path accounts = get_accounts() print(accounts[0].path) # 44'/60'/0'/0 # find_account will search up to 20 accounts account = find_account("0x...") ``` -------------------------------- ### Build and Serve Docs Locally Source: https://github.com/mikeshultz/ledger-eth-lib/blob/master/DEVELOPMENT.md Use sphinx-autobuild to automatically rebuild documentation and reload the local web server upon file changes. Visit http://127.0.0.1:8000 to view the docs. ```bash sphinx-autobuild --watch ledgereth/ docs/ build/docs/ ``` -------------------------------- ### Execute CLI Commands Source: https://github.com/mikeshultz/ledger-eth-lib/blob/master/docs/cli.rst General syntax for running ledgereth commands via the Python module. ```bash python -m ledgereth [command] ``` -------------------------------- ### Configure Ledger environment variables Source: https://context7.com/mikeshultz/ledger-eth-lib/llms.txt Set environment variables to enable legacy derivation paths and increase account search depth. ```bash # Use legacy Ledger Chrome app derivation path (44'/60'/0'/x) # instead of modern Ledger Live path (44'/60'/x'/0/0) export LEDGER_LEGACY_ACCOUNTS=1 # Increase the account search depth for find_account() export MAX_ACCOUNTS_FETCH=20 ``` -------------------------------- ### List Ledger Accounts via CLI Source: https://context7.com/mikeshultz/ledger-eth-lib/llms.txt Uses the `ledgereth accounts` command to list accounts from a connected Ledger device. Specify the count with `-c` or a specific derivation path. ```bash # List default accounts (3) python -m ledgereth accounts # Output: # Account 0: 44'/60'/0'/0/0 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 # Account 1: 44'/60'/1'/0/0 0x8C8d35429F74ec245F8Ef2f4Fd1e551cFF97d650 # Account 2: 44'/60'/2'/0/0 0x98e503f35D0a019cB0a251aD243a4cCFCF371F46 # List more accounts python -m ledgereth accounts -c 10 # Get account at specific path python -m ledgereth accounts "44'/60'/5'/0/0" # Output: Account 44'/60'/5'/0/0 0x... ``` -------------------------------- ### Retrieve Account by Path Source: https://context7.com/mikeshultz/ledger-eth-lib/llms.txt Accesses a specific account using a custom BIP-44 derivation path string. ```python from ledgereth import get_account_by_path # Get account at a specific derivation path account = get_account_by_path("44'/60'/0'/0/0") print(f"Address: {account.address}") # Output: Address: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 # Access a different account index account = get_account_by_path("44'/60'/5'/0/0") print(f"Path: {account.path}") print(f"Address: {account.address}") ``` -------------------------------- ### Create and Sign Transaction Source: https://github.com/mikeshultz/ledger-eth-lib/blob/master/docs/cli.rst Send a transaction by specifying the sender, recipient, value, nonce, gas price, and chain ID. ```bash python -m ledgereth send FROM_ADDRESS TO_ADDRESS VALUE_WEI -n NONCE -p GAS_PRICE_WEI -c CHAIN_ID ``` -------------------------------- ### Retrieve Accounts Source: https://github.com/mikeshultz/ledger-eth-lib/blob/master/docs/cli.rst List accounts available on the connected Ledger device. ```bash python -m ledgereth accounts ``` -------------------------------- ### Sign Legacy and EIP-1559 Transactions Source: https://context7.com/mikeshultz/ledger-eth-lib/llms.txt Demonstrates signing both legacy and EIP-1559 type 2 transactions with a specified sender path. Ensure the correct transaction object is used for each type. ```python tx = Transaction( nonce=0, gas_price=20000000000, gas_limit=21000, destination=bytes.fromhex("70997970C51812dc3A010C7d01b50e0d17dc79C8"), amount=1000000000000000000, data=b"", chain_id=1 ) signed = sign_transaction(tx, sender_path="44'/60'/0'/0/0") print(f"v: {signed.v}, r: {signed.r}, s: {signed.s}") print(f"Raw: {signed.rawTransaction}") tx = Type2Transaction( chain_id=1, nonce=1, max_priority_fee_per_gas=2000000000, max_fee_per_gas=30000000000, gas_limit=21000, destination=bytes.fromhex("70997970C51812dc3A010C7d01b50e0d17dc79C8"), amount=500000000000000000, data=b"" ) signed = sign_transaction(tx, sender_path="44'/60'/0'/0/0") print(f"Raw Type 2 tx: {signed.rawTransaction}") ``` -------------------------------- ### Lint Project Code Source: https://github.com/mikeshultz/ledger-eth-lib/blob/master/DEVELOPMENT.md Run the project's linting script to ensure code quality and style consistency. ```bash python setup.py lint ``` -------------------------------- ### Create Udev Rule for Ledger Device Access Source: https://github.com/mikeshultz/ledger-eth-lib/blob/master/docs/install.rst Add this rule to a udev configuration file (e.g., /etc/udev/rules.d/20-hw1.rules) to grant your user permissions to access the Ledger device. Replace '' with your actual username. ```udev SUBSYSTEMS=="usb", ATTRS{idVendor}=="2c97", ATTRS{idProduct}=="1015", MODE="0660", TAG+="uaccess", TAG+="udev-acl" OWNER="" ``` -------------------------------- ### Encode and Sign EIP-712 Typed Data with Ledger Source: https://context7.com/mikeshultz/ledger-eth-lib/llms.txt Demonstrates how to encode EIP-712 typed data and sign it using a Ledger device via the ledger-eth-lib. Requires the `encode_typed_data` and `sign_typed_data_draft` functions. ```python typed_data = { "types": { "EIP712Domain": [ {"name": "name", "type": "string"}, {"name": "version", "type": "string"}, {"name": "chainId", "type": "uint256"}, {"name": "verifyingContract", "type": "address"} ], "Mail": [ {"name": "from", "type": "address"}, {"name": "to", "type": "address"}, {"name": "contents", "type": "string"} ] }, "primaryType": "Mail", "domain": { "name": "Ether Mail", "version": "1", "chainId": 1, "verifyingContract": "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC" }, "message": { "from": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", "to": "0x70997970C51812dc3A010C7d01b50e0d17dc79C8", "contents": "Hello!" } } signable = encode_typed_data(full_message=typed_data) domain_hash = signable.header message_hash = signable.body signed = sign_typed_data_draft( domain_hash=domain_hash, message_hash=message_hash, sender_path="44'/60'/0'/0/0" ) print(f"Signature: {signed.signature}") print(f"Domain hash: {signed.domain_hash.hex()}") print(f"Message hash: {signed.message_hash.hex()}") ``` -------------------------------- ### Retrieve Ledger Accounts Source: https://context7.com/mikeshultz/ledger-eth-lib/llms.txt Fetches multiple accounts using BIP-44 derivation paths. Set the LEDGER_LEGACY_ACCOUNTS environment variable to toggle between modern and legacy derivation schemes. ```python from ledgereth import get_accounts # Get default number of accounts (3) accounts = get_accounts() for account in accounts: print(f"Path: {account.path}") print(f"Address: {account.address}") # Output: # Path: 44'/60'/0'/0/0 # Address: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 # Get more accounts accounts = get_accounts(count=10) print(f"Found {len(accounts)} accounts") ``` -------------------------------- ### Create EIP-2930 Transaction Source: https://context7.com/mikeshultz/ledger-eth-lib/llms.txt Instantiates an EIP-2930 (Type 1) transaction, which uses legacy gas pricing but supports access lists for gas optimization. Requires `chain_id`, `gas_price`, and `access_list`. ```python from ledgereth.objects import Type1Transaction # Create an EIP-2930 transaction with access list tx = Type1Transaction( chain_id=1, nonce=3, gas_price=20000000000, # 20 Gwei gas_limit=50000, destination=bytes.fromhex("70997970C51812dc3A010C7d01b50e0d17dc79C8"), amount=0, data=b"\xa9\x05\x9c\xbb...", # Contract calldata access_list=[ (bytes.fromhex("ContractAddress..."), [0, 1]) ] ) print(f"Transaction Type: {tx.transaction_type}") # TransactionType.EIP_2930 ``` -------------------------------- ### Create and Access Legacy Transaction Properties Source: https://context7.com/mikeshultz/ledger-eth-lib/llms.txt Instantiates a legacy Ethereum transaction object and demonstrates accessing its properties. The `to_dict` and `to_rpc_dict` methods are available for serialization. ```python from ledgereth.objects import Transaction # Create a legacy transaction tx = Transaction( nonce=5, gas_price=25000000000, # 25 Gwei gas_limit=21000, destination=bytes.fromhex("70997970C51812dc3A010C7d01b50e0d17dc79C8"), amount=100000000000000000, # 0.1 ETH data=b"", chain_id=1 ) # Access transaction properties print(f"Nonce: {tx.nonce}") print(f"Gas Price: {tx.gas_price}") print(f"Transaction Type: {tx.transaction_type}") # TransactionType.LEGACY # Convert to dictionary tx_dict = tx.to_dict() rpc_dict = tx.to_rpc_dict() # web3.py/JSON-RPC compatible format ``` -------------------------------- ### Find Account by Address Source: https://context7.com/mikeshultz/ledger-eth-lib/llms.txt Searches for an account on the device by its Ethereum address. Returns None if the account is not found within the specified search depth. ```python from ledgereth import find_account # Find an account by address address = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266" account = find_account(address) if account: print(f"Found account at path: {account.path}") print(f"Address: {account.address}") else: print("Account not found on this Ledger device") # Search deeper in the derivation path account = find_account(address, count=20) ``` -------------------------------- ### get_accounts Source: https://context7.com/mikeshultz/ledger-eth-lib/llms.txt Retrieves multiple accounts from the Ledger device using BIP-44 derivation paths. ```APIDOC ## get_accounts ### Description Retrieves multiple accounts from the Ledger device using BIP-44 derivation paths. By default, it fetches 3 accounts using the modern Ledger Live derivation path. ### Parameters #### Query Parameters - **count** (int) - Optional - Number of accounts to retrieve (default: 3) ### Response - **accounts** (list) - A list of account objects containing path and address properties. ``` -------------------------------- ### Sign EIP-712 Typed Data via CLI Source: https://context7.com/mikeshultz/ledger-eth-lib/llms.txt Uses the `ledgereth signtyped` command to sign EIP-712 typed data using pre-computed domain and message hashes with a specified account. ```bash python -m ledgereth signtyped \ 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 \ 0x1234567890abcdef... \ 0xfedcba0987654321... # Output: # Signing typed data with account 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 # Domain hash: 0x1234567890abcdef... # Message hash: 0xfedcba0987654321... # Signature: 0xabcd... ``` -------------------------------- ### Create and Sign Transactions Source: https://context7.com/mikeshultz/ledger-eth-lib/llms.txt Signs transactions in a single operation, supporting legacy, EIP-2930, and EIP-1559 transaction types. ```python from ledgereth import create_transaction # Create and sign a legacy transaction signed_tx = create_transaction( destination="0x70997970C51812dc3A010C7d01b50e0d17dc79C8", amount=1000000000000000000, # 1 ETH in wei gas=21000, gas_price=20000000000, # 20 Gwei nonce=0, chain_id=1, # Mainnet sender_path="44'/60'/0'/0/0" ) print(f"Raw transaction: {signed_tx.rawTransaction}") # Create and sign an EIP-1559 Type 2 transaction signed_tx = create_transaction( destination="0x70997970C51812dc3A010C7d01b50e0d17dc79C8", amount=500000000000000000, # 0.5 ETH gas=21000, max_fee_per_gas=30000000000, # 30 Gwei max_priority_fee_per_gas=2000000000, # 2 Gwei nonce=1, chain_id=1, sender_path="44'/60'/0'/0/0" ) print(f"Raw transaction: {signed_tx.rawTransaction}") # Transaction with data (contract interaction) signed_tx = create_transaction( destination="0xContractAddress...", amount=0, gas=100000, max_fee_per_gas=25000000000, max_priority_fee_per_gas=1000000000, nonce=2, chain_id=1, data="0xa9059cbb...", # ERC-20 transfer calldata sender_path="44'/60'/0'/0/0" ) ``` -------------------------------- ### Send ETH Transaction via CLI Source: https://context7.com/mikeshultz/ledger-eth-lib/llms.txt Uses the `ledgereth send` command to create and sign a transaction for sending ETH. Outputs the raw signed transaction hex. Supports both legacy and EIP-1559 transaction types. ```bash # Send legacy transaction python -m ledgereth send \ 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 \ 0x70997970C51812dc3A010C7d01b50e0d17dc79C8 \ 1000000000000000000 \ --nonce 0 \ --gasprice 20000000000 \ --gas 21000 \ --chainid 1 # Send EIP-1559 transaction python -m ledgereth send \ 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 \ 0x70997970C51812dc3A010C7d01b50e0d17dc79C8 \ 500000000000000000 \ --nonce 1 \ --max-fee 30000000000 \ --priority-fee 2000000000 \ --gas 21000 \ --chainid 1 # Output: Signed Raw Transaction: 0x02f86c... ``` -------------------------------- ### get_account_by_path Source: https://context7.com/mikeshultz/ledger-eth-lib/llms.txt Retrieves a specific account using a custom BIP-44 derivation path. ```APIDOC ## get_account_by_path ### Description Retrieves a specific account using a custom BIP-44 derivation path. ### Parameters #### Path Parameters - **path** (string) - Required - The BIP-44 derivation path (e.g., "44'/60'/0'/0/0") ### Response - **account** (object) - An account object containing the path and address. ``` -------------------------------- ### Integrate LedgerSignerMiddleware with Web3.py Source: https://context7.com/mikeshultz/ledger-eth-lib/llms.txt Adds LedgerSignerMiddleware to the Web3.py middleware onion to automatically route signing operations to a connected Ledger device. This middleware handles `eth_accounts`, `eth_sendTransaction`, `eth_sign`, and `eth_signTypedData`. ```python from web3 import Web3 from ledgereth.web3 import LedgerSignerMiddleware w3 = Web3(Web3.HTTPProvider("http://localhost:8545")) w3.middleware_onion.add(LedgerSignerMiddleware) accounts = w3.eth.accounts print(f"Ledger accounts: {accounts}") tx_hash = w3.eth.send_transaction({ "from": accounts[0], "to": "0x70997970C51812dc3A010C7d01b50e0d17dc79C8", "value": w3.to_wei(0.1, "ether"), "gas": 21000, "maxFeePerGas": w3.to_wei(30, "gwei"), "maxPriorityFeePerGas": w3.to_wei(2, "gwei") }) print(f"Transaction hash: {tx_hash.hex()}") signature = w3.eth.sign(accounts[0], text="Hello from Ledger!") print(f"Signature: {signature.hex()}") typed_data = { "types": {...}, "primaryType": "Mail", "domain": {...}, "message": {...} } signature = w3.eth.sign_typed_data(accounts[0], typed_data) ``` -------------------------------- ### Sign Typed Data (EIP-712 Draft) Source: https://context7.com/mikeshultz/ledger-eth-lib/llms.txt Signs EIP-712 typed structured data. This function requires pre-computed domain and message hashes. Note that the EIP-712 implementation is in draft status and may change. ```python from ledgereth import sign_typed_data_draft from eth_account.messages import encode_typed_data ``` -------------------------------- ### Type1Transaction (EIP-2930) Source: https://context7.com/mikeshultz/ledger-eth-lib/llms.txt Creates an unsigned EIP-2930 transaction with access lists. Uses legacy gas pricing but supports access lists for gas optimization. ```APIDOC ## Type1Transaction (EIP-2930) ### Description Creates an unsigned EIP-2930 transaction with access lists. Uses legacy gas pricing but supports access lists for gas optimization. ### Method N/A (Object Construction) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```python from ledgereth.objects import Type1Transaction # Create an EIP-2930 transaction with access list tx = Type1Transaction( chain_id=1, nonce=3, gas_price=20000000000, # 20 Gwei gas_limit=50000, destination=bytes.fromhex("70997970C51812dc3A010C7d01b50e0d17dc79C8"), amount=0, data=b"\xa9\x05\x9c\xbb...", # Contract calldata access_list=[ (bytes.fromhex("ContractAddress..."), [0, 1]) ] ) print(f"Transaction Type: {tx.transaction_type}") # TransactionType.EIP_2930 ``` ### Response #### Success Response (200) N/A (Object Construction) #### Response Example N/A ``` -------------------------------- ### Sign Pre-constructed Transactions Source: https://context7.com/mikeshultz/ledger-eth-lib/llms.txt Signs a pre-constructed transaction object, providing more control over the transaction construction process. ```python from ledgereth import sign_transaction from ledgereth.objects import Transaction, Type2Transaction ``` -------------------------------- ### Sign a Message Source: https://github.com/mikeshultz/ledger-eth-lib/blob/master/docs/cli.rst Sign a string message using the specified signer address. ```bash python -m ledgereth sign SIGNER_ADDRESS "I'm a little teapot" ``` -------------------------------- ### Sign Text Message via CLI Source: https://context7.com/mikeshultz/ledger-eth-lib/llms.txt Uses the `ledgereth sign` command to sign a text message using EIP-191 personal message signing with a specified account. ```bash python -m ledgereth sign \ 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 \ "Hello, Ethereum!" # Output: # Signing "Hello, Ethereum!" with 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 # Signature: 0x1234...abcd ``` -------------------------------- ### Reload Udev Rules Source: https://github.com/mikeshultz/ledger-eth-lib/blob/master/docs/install.rst After creating or modifying udev rules, reload them to apply the changes. This command ensures the system recognizes the new rules. ```bash $ udevadm control --reload-rules $ udevadm trigger ``` -------------------------------- ### Transaction Signing API Source: https://github.com/mikeshultz/ledger-eth-lib/blob/master/docs/transaction_signing.rst Provides functions for creating and signing Ethereum transactions. ```APIDOC ## Transaction Signing API ### Description Functions to create and sign transactions. ### Module `ledgereth.transactions` ### Members This module provides the following members for transaction signing: - `create_signed_transaction` - `sign_transaction` - `sign_message` - `verify_signature` ``` -------------------------------- ### create_transaction Source: https://context7.com/mikeshultz/ledger-eth-lib/llms.txt Creates and signs a transaction in a single operation, supporting legacy, Type 1, and Type 2 transactions. ```APIDOC ## create_transaction ### Description Creates and signs a transaction in a single operation. Supports legacy transactions, Type 1 (access lists), and Type 2 (EIP-1559) transactions. ### Parameters #### Request Body - **destination** (string) - Required - Recipient address - **amount** (int) - Required - Amount in wei - **gas** (int) - Required - Gas limit - **gas_price** (int) - Optional - Gas price for legacy transactions - **max_fee_per_gas** (int) - Optional - Max fee for EIP-1559 - **max_priority_fee_per_gas** (int) - Optional - Priority fee for EIP-1559 - **nonce** (int) - Required - Transaction nonce - **chain_id** (int) - Required - Network chain ID - **sender_path** (string) - Required - BIP-44 derivation path of the sender - **data** (string) - Optional - Contract interaction calldata ### Response - **signed_tx** (object) - Object containing the rawTransaction string. ``` -------------------------------- ### Create EIP-1559 Transaction Source: https://context7.com/mikeshultz/ledger-eth-lib/llms.txt Constructs an EIP-1559 (Type 2) transaction, including optional access lists for gas optimization. This type uses `max_priority_fee_per_gas` and `max_fee_per_gas`. ```python from ledgereth.objects import Type2Transaction # Create an EIP-1559 transaction tx = Type2Transaction( chain_id=1, nonce=10, max_priority_fee_per_gas=2000000000, # 2 Gwei tip max_fee_per_gas=50000000000, # 50 Gwei max gas_limit=21000, destination=bytes.fromhex("70997970C51812dc3A010C7d01b50e0d17dc79C8"), amount=1000000000000000000, # 1 ETH data=b"", access_list=[] # Optional access list ) # Access transaction properties print(f"Transaction Type: {tx.transaction_type}") # TransactionType.EIP_1559 print(f"Max Fee: {tx.max_fee_per_gas}") print(f"Priority Fee: {tx.max_priority_fee_per_gas}") # With access list for gas optimization tx_with_access = Type2Transaction( chain_id=1, nonce=11, max_priority_fee_per_gas=2000000000, max_fee_per_gas=50000000000, gas_limit=50000, destination=bytes.fromhex("ContractAddress..."), amount=0, data=b"\xa9\x05\x9c\xbb...", # Contract calldata access_list=[ (bytes.fromhex("ContractAddress..."), [0, 1, 2]) # (address, storage_keys) ] ) ``` -------------------------------- ### Transaction (Legacy) Source: https://context7.com/mikeshultz/ledger-eth-lib/llms.txt Creates an unsigned legacy or EIP-155 transaction. Chain ID is required to protect against replay attacks and must be a 32-bit integer for legacy transactions. ```APIDOC ## Transaction (Legacy) ### Description Creates an unsigned legacy or EIP-155 transaction. Chain ID is required to protect against replay attacks and must be a 32-bit integer for legacy transactions. ### Method N/A (Object Construction) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```python from ledgereth.objects import Transaction # Create a legacy transaction tx = Transaction( nonce=5, gas_price=25000000000, # 25 Gwei gas_limit=21000, destination=bytes.fromhex("70997970C51812dc3A010C7d01b50e0d17dc79C8"), amount=100000000000000000, # 0.1 ETH data=b"", chain_id=1 ) # Access transaction properties print(f"Nonce: {tx.nonce}") print(f"Gas Price: {tx.gas_price}") print(f"Transaction Type: {tx.transaction_type}") # TransactionType.LEGACY # Convert to dictionary tx_dict = tx.to_dict() rpc_dict = tx.to_rpc_dict() # web3.py/JSON-RPC compatible format ``` ### Response #### Success Response (200) N/A (Object Construction) #### Response Example N/A ``` -------------------------------- ### find_account Source: https://context7.com/mikeshultz/ledger-eth-lib/llms.txt Searches for an account by its Ethereum address on the connected Ledger device. ```APIDOC ## find_account ### Description Searches for an account by its Ethereum address on the connected Ledger device. Returns None if the account is not found within the search depth. ### Parameters #### Query Parameters - **address** (string) - Required - The Ethereum address to search for - **count** (int) - Optional - Search depth (default: 5) ### Response - **account** (object|None) - The found account object or None if not found. ``` -------------------------------- ### Type2Transaction (EIP-1559) Source: https://context7.com/mikeshultz/ledger-eth-lib/llms.txt Creates an unsigned EIP-1559 transaction with max fee and priority fee parameters. Supports access lists for gas optimization. ```APIDOC ## Type2Transaction (EIP-1559) ### Description Creates an unsigned EIP-1559 transaction with max fee and priority fee parameters. Supports access lists for gas optimization. ### Method N/A (Object Construction) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```python from ledgereth.objects import Type2Transaction # Create an EIP-1559 transaction tx = Type2Transaction( chain_id=1, nonce=10, max_priority_fee_per_gas=2000000000, # 2 Gwei tip max_fee_per_gas=50000000000, # 50 Gwei max gas_limit=21000, destination=bytes.fromhex("70997970C51812dc3A010C7d01b50e0d17dc79C8"), amount=1000000000000000000, # 1 ETH data=b"", access_list=[] # Optional access list ) # Access transaction properties print(f"Transaction Type: {tx.transaction_type}") # TransactionType.EIP_1559 print(f"Max Fee: {tx.max_fee_per_gas}") print(f"Priority Fee: {tx.max_priority_fee_per_gas}") # With access list for gas optimization tx_with_access = Type2Transaction( chain_id=1, nonce=11, max_priority_fee_per_gas=2000000000, max_fee_per_gas=50000000000, gas_limit=50000, destination=bytes.fromhex("ContractAddress..."), amount=0, data=b"\xa9\x05\x9c\xbb...", # Contract calldata access_list=[ (bytes.fromhex("ContractAddress..."), [0, 1, 2]) # (address, storage_keys) ] ) ``` ### Response #### Success Response (200) N/A (Object Construction) #### Response Example N/A ``` -------------------------------- ### sign_typed_data_draft Source: https://context7.com/mikeshultz/ledger-eth-lib/llms.txt Signs EIP-712 typed structured data. Requires pre-computed domain hash and message hash. Note: EIP-712 implementation is in draft status and APIs may change. ```APIDOC ## sign_typed_data_draft ### Description Signs EIP-712 typed structured data. Requires pre-computed domain hash and message hash. Note: EIP-712 implementation is in draft status and APIs may change. ### Method POST (Assumed, as it's a signing operation) ### Endpoint N/A (Library function) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```python from ledgereth import sign_typed_data_draft from eth_account.messages import encode_typed_data # Example usage (requires eth_account for encoding) # domain_data = { # "name": "Ether", # "version": "1", # "chainId": 1, # "verifyingContract": "0xCcCCccccCCCCcCCCCCCcCcCccCc কোম্পCCcccccccC" # } # message_data = { # "types": { # "EIP712Domain": [ # {"name": "name", "type": "string"}, # {"name": "version", "type": "string"}, # {"name": "chainId", "type": "uint256"}, # {"name": "verifyingContract", "type": "address"} # ], # "Person": [ # {"name": "name", "type": "string"}, # {"name": "wallet", "type": "address"} # ], # "Mail": [ # {"name": "from", "type": "Person"}, # {"name": "to", "type": "Person"}, # {"name": "contents", "type": "string"} # ] # }, # "primaryType": "Mail", # "message": { # "from": { # "name": "Cow", # "wallet": "0xCD2a3d9F93851f78146a1AD1a3447403C71a387F" # }, # "to": { # "name": "Bob", # "wallet": "0xb137435733496666666666666666666666666666" # }, # "contents": "Hello, world" # } # } # encoded_data = encode_typed_data(message_data) # signed = sign_typed_data_draft(encoded_data, sender_path="44'/60'/0'/0/0") ``` ### Response #### Success Response (200) N/A (Specific response structure depends on the encoding and signing process, not fully detailed in the provided text.) #### Response Example N/A ``` -------------------------------- ### Sign Typed Data Source: https://github.com/mikeshultz/ledger-eth-lib/blob/master/docs/cli.rst Sign typed data using domain and message hashes, as required by the Ledger Ethereum app. ```bash python -m ledgereth signtyped SIGNER_ADDRESS DOMAIN_HASH MESSAGE_HASH ``` -------------------------------- ### Sign Text Message with EIP-191 Source: https://context7.com/mikeshultz/ledger-eth-lib/llms.txt Signs a text message using EIP-191 personal message signing. The Ledger device automatically prefixes the message. Ensure the correct `sender_path` is provided. ```python from ledgereth import sign_message # Sign a simple text message signed = sign_message( message="Hello, Ethereum!", sender_path="44'/60'/0'/0/0" ) print(f"Message: {signed.message}") print(f"Signature: {signed.signature}") print(f"v: {signed.v}, r: {signed.r}, s: {signed.s}") # Output: # Message: b'Hello, Ethereum!' # Signature: 0x1234...abcd # Sign bytes directly signed = sign_message( message=b"Raw bytes message", sender_path="44'/60'/0'/0/0" ) ``` -------------------------------- ### sign_message Source: https://context7.com/mikeshultz/ledger-eth-lib/llms.txt Signs a text message using EIP-191 personal message signing. The Ledger device automatically prefixes the message with `\x19Ethereum Signed Message:\n{length}`. ```APIDOC ## sign_message ### Description Signs a text message using EIP-191 personal message signing. The Ledger device automatically prefixes the message with `\x19Ethereum Signed Message:\n{length}`. ### Method POST (Assumed, as it's a signing operation) ### Endpoint N/A (Library function) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```python from ledgereth import sign_message # Sign a simple text message signed = sign_message( message="Hello, Ethereum!", sender_path="44'/60'/0'/0/0" ) print(f"Message: {signed.message}") print(f"Signature: {signed.signature}") print(f"v: {signed.v}, r: {signed.r}, s: {signed.s}") # Output: # Message: b'Hello, Ethereum!' # Signature: 0x1234...abcd # Sign bytes directly signed = sign_message( message=b"Raw bytes message", sender_path="44'/60'/0'/0/0" ) ``` ### Response #### Success Response (200) - **message** (bytes) - The original message signed. - **signature** (str) - The signature in hexadecimal format. - **v** (int) - The recovery ID. - **r** (int) - The r component of the signature. - **s** (int) - The s component of the signature. #### Response Example ```json { "message": "b'Hello, Ethereum!'", "signature": "0x1234...abcd", "v": 27, "r": 12345, "s": 67890 } ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.