### Install Poetry for Python Virtual Environments Source: https://github.com/b1ue1nwh1te/poseidon/blob/main/README.md Install Poetry, a dependency management and packaging tool, which is recommended for creating isolated virtual environments to ensure a clean and stable execution environment for Poseidon projects. ```bash pip install -U poetry ``` -------------------------------- ### Clone Poseidon Template Repository for Project Setup Source: https://github.com/b1ue1nwh1te/poseidon/blob/main/README.md Clone the official Poseidon Template repository to your local machine. This template provides a pre-configured project structure for easier setup with Poetry. You can also fork the template to your own GitHub first. ```bash git clone git@github.com:B1ue1nWh1te/PoseidonTemplate.git ``` -------------------------------- ### Install Project Dependencies using Poetry Source: https://github.com/b1ue1nwh1te/poseidon/blob/main/README.md Navigate into the cloned Poseidon Template directory and use Poetry to install all project dependencies within a new virtual environment. This step sets up the isolated environment for your Poseidon project. ```bash cd PoseidonTemplate poetry install ``` -------------------------------- ### Install Poseidon Python Library via pip Source: https://github.com/b1ue1nwh1te/poseidon/blob/main/README.md This is the simplest method to install the Poseidon Python library using pip. Be aware that this approach might lead to issues if your local Python environment has dependency conflicts. ```bash pip install -U poseidon-python ``` -------------------------------- ### EVM Chain Interaction: Poseidon vs. web3.py Comparison Source: https://github.com/b1ue1nwh1te/poseidon/blob/main/README.md This example demonstrates common EVM chain operations, including account generation, message signing, sending basic transactions, deploying smart contracts, and interacting with contract functions. It highlights the simplified and concise API of Poseidon compared to the more verbose equivalent operations using web3.py. ```python from poseidon.evm import Chain, Account, Contract, Utils rpc_url = "https://" chain = Chain(rpc_url) address, private_key = Utils.generate_new_account() account = Account(chain, private_key) signature_data = account.sign_message_string("test") signed_message_data = Utils.recover_message_string("test", signature_data.signature_data.signature) account.send_transaction(to=ZERO_ADDRESS, data="0x", value=1) Utils.set_solidity_version("0.8.28") abi, bytecode = Utils.compile_solidity_contract("./Contract.sol", "Contract") tx_receipt = account.deploy_contract(abi, bytecode) contract: Contract = tx_receipt.contract contract.call_function("anyWriteFunction", "(param1)", "(param2)") contract.read_only_call_function("anyReadOnlyFunction", "(param1)", "(param2)") ``` ```python from web3 import Web3 from eth_account import Account as Web3Account from eth_account.messages import encode_defunct from solcx import compile_source, install_solc import json w3 = Web3(Web3.HTTPProvider("https://")) account = Web3Account.create() address = account.address private_key = account.key.hex() message = encode_defunct(text="test") signed_message = w3.eth.account.sign_message(message, private_key=private_key) recovered_address = w3.eth.account.recover_message(message, signature=signed_message.signature) transaction = { 'nonce': w3.eth.get_transaction_count(address), 'to': ZERO_ADDRESS, 'value': 1, 'gas': 21000, 'gasPrice': w3.eth.gas_price, 'data': '0x' } signed_txn = w3.eth.account.sign_transaction(transaction, private_key) tx_hash = w3.eth.send_raw_transaction(signed_txn.rawTransaction) tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash) install_solc('0.8.28') with open('./Contract.sol', 'r') as file: source = file.read() compiled_sol = compile_source(source) contract_interface = compiled_sol[':Contract'] bytecode = contract_interface['bin'] abi = contract_interface['abi'] contract = w3.eth.contract(abi=abi, bytecode=bytecode) transaction = contract.constructor().build_transaction({ 'from': address, 'nonce': w3.eth.get_transaction_count(address), 'gas': 2000000, 'gasPrice': w3.eth.gas_price }) signed_txn = w3.eth.account.sign_transaction(transaction, private_key) tx_hash = w3.eth.send_raw_transaction(signed_txn.rawTransaction) tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash) contract_instance = w3.eth.contract(address=tx_receipt.contractAddress, abi=abi) write_txn = contract_instance.functions.anyWriteFunction("(param1)", "(param2)").build_transaction({ 'from': address, 'nonce': w3.eth.get_transaction_count(address), 'gas': 200000, 'gasPrice': w3.eth.gas_price }) signed_txn = w3.eth.account.sign_transaction(write_txn, private_key) tx_hash = w3.eth.send_raw_transaction(signed_txn.rawTransaction) tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash) result = contract_instance.functions.anyReadOnlyFunction("(param1)", "(param2)").call() ``` -------------------------------- ### Execute Python Script within Poetry Virtual Environment Source: https://github.com/b1ue1nwh1te/poseidon/blob/main/README.md Activate the Poetry shell to enter the project's virtual environment, then execute your Python script (e.g., `main.py`). This ensures the script runs with the correct dependencies and environment settings. ```bash poetry shell python main.py ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.