Skip to main content

EVM blockchain plugin for elizaOS - Python implementation with web3.py

Project description

elizaOS EVM Plugin - Python

Python implementation of the EVM blockchain plugin for elizaOS.

Features

  • Multi-chain Support: Interact with Ethereum, Base, Arbitrum, Optimism, Polygon, and more
  • Wallet Management: Secure private key handling with web3.py
  • Token Operations: Native and ERC20 token transfers
  • Swaps: Token swaps via LiFi aggregator
  • Bridges: Cross-chain token bridges via LiFi
  • Strong Typing: Full Pydantic validation with fail-fast semantics

Installation

pip install elizaos-plugin-evm

Or with Poetry:

poetry add elizaos-plugin-evm

Quick Start

import asyncio
from elizaos_plugin_evm import (
    EVMWalletProvider,
    SupportedChain,
    TransferParams,
    execute_transfer,
)

async def main():
    # Initialize provider with private key
    provider = EVMWalletProvider("your_private_key")

    # Get wallet address
    print(f"Address: {provider.address}")

    # Get balance on mainnet
    balance = await provider.get_balance(SupportedChain.MAINNET)
    print(f"Balance: {balance.native_balance} ETH")

    # Transfer tokens
    params = TransferParams(
        from_chain=SupportedChain.SEPOLIA,
        to_address="0x1234567890123456789012345678901234567890",
        amount="0.01",
    )
    tx_hash = await execute_transfer(provider, params)
    print(f"Transaction: {tx_hash}")

asyncio.run(main())

Supported Chains

Chain ID Native Token
Ethereum Mainnet 1 ETH
Sepolia 11155111 ETH
Base 8453 ETH
Base Sepolia 84532 ETH
Arbitrum 42161 ETH
Optimism 10 ETH
Polygon 137 MATIC
Avalanche 43114 AVAX
BSC 56 BNB
Gnosis 100 xDAI
Fantom 250 FTM
Linea 59144 ETH
Scroll 534352 ETH
zkSync Era 324 ETH

API Reference

EVMWalletProvider

The main class for interacting with EVM chains.

from elizaos_plugin_evm import EVMWalletProvider, SupportedChain

# Initialize
provider = EVMWalletProvider(private_key="0x...")

# Get address
address = provider.address

# Get balance
balance = await provider.get_balance(SupportedChain.MAINNET)

# Get token balance
token_balance = await provider.get_token_balance(
    chain=SupportedChain.MAINNET,
    token_address="0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",  # USDC
)

# Send transaction
tx_hash = await provider.send_transaction(
    chain=SupportedChain.MAINNET,
    to="0x...",
    value=1000000000000000000,  # 1 ETH in wei
)

# Wait for confirmation
await provider.wait_for_transaction(SupportedChain.MAINNET, tx_hash)

Actions

Transfer

from elizaos_plugin_evm import TransferParams, execute_transfer

params = TransferParams(
    from_chain=SupportedChain.MAINNET,
    to_address="0x...",
    amount="1.5",
    token="0x...",  # Optional: ERC20 token address
)
tx_hash = await execute_transfer(provider, params)

Swap

from elizaos_plugin_evm import SwapParams, execute_swap

params = SwapParams(
    chain=SupportedChain.MAINNET,
    from_token="0x0000000000000000000000000000000000000000",  # ETH
    to_token="0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",  # USDC
    amount="1000000000000000000",  # 1 ETH
    slippage=0.01,  # 1%
)
tx_hash = await execute_swap(provider, params)

Bridge

from elizaos_plugin_evm import BridgeParams, execute_bridge

params = BridgeParams(
    from_chain=SupportedChain.MAINNET,
    to_chain=SupportedChain.BASE,
    from_token="0x0000000000000000000000000000000000000000",  # ETH
    to_token="0x0000000000000000000000000000000000000000",  # ETH
    amount="1000000000000000000",  # 1 ETH
)
status = await execute_bridge(provider, params)
print(f"Bridge complete: {status.dest_tx_hash}")

Type Validation

All parameters are validated using Pydantic with strict type checking:

from elizaos_plugin_evm import TransferParams, SupportedChain
from pydantic import ValidationError

# This will raise ValidationError
try:
    params = TransferParams(
        from_chain=SupportedChain.MAINNET,
        to_address="invalid_address",  # Invalid!
        amount="0",  # Invalid! Must be positive
    )
except ValidationError as e:
    print(e)

Error Handling

All errors are raised as EVMError with specific error codes:

from elizaos_plugin_evm import EVMError, EVMErrorCode

try:
    await execute_transfer(provider, params)
except EVMError as e:
    if e.code == EVMErrorCode.INSUFFICIENT_FUNDS:
        print("Not enough funds!")
    elif e.code == EVMErrorCode.ROUTE_NOT_FOUND:
        print("No swap route found")
    else:
        print(f"Error: {e.message}")

Testing

Run unit tests:

pytest tests/test_types.py -v

Run integration tests (requires funded wallet):

export EVM_PRIVATE_KEY="your_testnet_private_key"
pytest tests/test_integration.py -v

Development

# Install dev dependencies
pip install -e ".[dev]"

# Run linter
ruff check .

# Run type checker
mypy elizaos_plugin_evm

# Format code
ruff format .

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

elizaos_plugin_evm-2.0.0a5.tar.gz (26.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

elizaos_plugin_evm-2.0.0a5-py3-none-any.whl (23.0 kB view details)

Uploaded Python 3

File details

Details for the file elizaos_plugin_evm-2.0.0a5.tar.gz.

File metadata

  • Download URL: elizaos_plugin_evm-2.0.0a5.tar.gz
  • Upload date:
  • Size: 26.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for elizaos_plugin_evm-2.0.0a5.tar.gz
Algorithm Hash digest
SHA256 05f7368438ff5cd21c8c514fcc52b83901148b3af6ee65e7c739506df6ccff32
MD5 45f7d6c7450fc6f65225906a5be74f85
BLAKE2b-256 1991fdd614e3e5bfb0d611adadac8f10115052c06fa4cc43894fb8a79129154f

See more details on using hashes here.

File details

Details for the file elizaos_plugin_evm-2.0.0a5-py3-none-any.whl.

File metadata

File hashes

Hashes for elizaos_plugin_evm-2.0.0a5-py3-none-any.whl
Algorithm Hash digest
SHA256 b5d4755bac5e5a2c388bf015880268afa0774b0b90d1f2842c1d13a556976cb7
MD5 478888675db3bddc811fbc0ed9b97984
BLAKE2b-256 c4261e86309f05fdccc782c774070edbcc92de26fc8e2f7609020545e21df68c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page