Skip to main content

No project description provided

Project description

🧪 Experimental

Integrating with eth-account

Privy EVM wallets natively integrate with the Python eth-account library, allowing you to use the library's interfaces for signing messages, signing typed data, sending transactions, and more.

To integrate with eth-account, first install the library as a dependency:

pip install privy-eth-account

Then, use Privy's create_eth_account function to initialize an instance of an Account for an EVM server wallet. As parameters to this function, pass:

Parameter Type Description
client PrivyHTTPClient Instance of the Privy HTTP client for your app.
address str Ethereum address of the wallet.
wallet_id str ID of the wallet.

Here's an example showing how to integrate with eth-account:

from privy_eth_account import create_eth_account, PrivyHTTPClient
from eth_account.messages import encode_typed_data, encode_defunct

# Initialize your Privy client
client = PrivyHTTPClient(
    app_id="YOUR_APP_ID",
    app_secret="YOUR_APP_SECRET",
    authorization_key="YOUR_AUTHORIZATION_KEY"
)

# Create an account instance for a wallet
wallet_id = "insert-wallet-id"
wallet_address = "insert-wallet-address"
account = create_eth_account(client, wallet_address, wallet_id)

Once you created an account instance, you can use it to sign messages, sign transactions, and sign typed data:

Sign a message

# Signing a message (personal_sign)
message = encode_defunct(text="Hello, Privy!")
signed_message = account.sign_message(message)
print(f"Signed message: {signed_message}")

Sign a transaction

# Signing a transaction
transaction = {
    "to": "0x123...789",
    "value": 100,
    "chain_id": 8453
}
signed_tx = account.sign_transaction(transaction)
print(f"Signed transaction: {signed_tx}")

Signing EIP-712 Typed Data

# Example EIP-712 typed data
# Structure your typed data as a full message
full_message = {
    "domain": {
        "name": "My App",
        "version": "1",
        "chainId": 8453,
        "verifyingContract": "0xCc9c3D98163F4F6Af884e259132e15D6d27A5c57",
        "salt": "pepper"
    },
    "types": {
        'EIP712Domain': [
            {'name': 'name', 'type': 'string'},
            {'name': 'version', 'type': 'string'},
            {'name': 'chainId', 'type': 'uint256'},
            {'name': 'verifyingContract', 'type': 'address'},
            {'name': 'salt', 'type': 'string'}
        ],
        'Person': [
            {'name': 'name', 'type': 'string'},
            {'name': 'wallet', 'type': 'address'}
        ],
        'Mail': [
            {'name': 'from', 'type': 'Person'},
            {'name': 'to', 'type': 'Person'},
            {'name': 'contents', 'type': 'string'}
        ]
    },
    "message": {
        "from": {
            "name": "Alice",
            "wallet": "0x742d35Cc6634C0532925a3b844Bc454e4438f44e"
        },
        "to": {
            "name": "Bob",
            "wallet": "0xCc9c3D98163F4F6Af884e259132e15D6d27A5c57"
        },
        "contents": "Hello, Bob!"
    },
    "primaryType": "Mail"
}

# Sign the typed data using the full_message parameter
signed_typed_data = account.sign_typed_data(full_message=full_message)
print(f"Signed typed data: {signed_typed_data}")

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

privy_eth_account-0.1.0.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

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

privy_eth_account-0.1.0-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file privy_eth_account-0.1.0.tar.gz.

File metadata

  • Download URL: privy_eth_account-0.1.0.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.13.3 Darwin/24.1.0

File hashes

Hashes for privy_eth_account-0.1.0.tar.gz
Algorithm Hash digest
SHA256 aadcffff42497e2d87f3ffe225a9a0799876afe58f4c7b91d8e20795a1dbbd1e
MD5 9cebef266708c8f7412976d6da7f85bb
BLAKE2b-256 ef6724ec603ae8ddbd2ce0573cbf471b5f00f7fcd44818f79c6ff123ded357b8

See more details on using hashes here.

File details

Details for the file privy_eth_account-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: privy_eth_account-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.13.3 Darwin/24.1.0

File hashes

Hashes for privy_eth_account-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ff0d83dba811e423c3e504ca8d6f5dcd22931b7835c885f8e49c007139974d32
MD5 5e7a40e5c7807a8881afb488344d16c8
BLAKE2b-256 d78de30173ee459fa7b2f6ff93dfa48a2ba1d44b3d20b73e6c3240987ce9cd15

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