Enclave SDK Test Script
This script demonstrates how to interact with the Enclave SDK using Web3 to create a smart account, compute quotes, and submit transactions on the Optimism network.
Prerequisites
Before running the script, ensure you have the following:
- Python 3.x
- Required packages:
web3python-dotenveth-account
You can install the required packages using pip:
pip install web3 python-dotenv eth-account
Environment Variables
Create a .env file in the same directory as your script and set the following environment variables:
ALCHEMY_KEY=<your_alchemy_key>
ENCLAVE_KEY=<your_enclave_key>
PRIVATE_KEY=<your_private_key>
Usage
-
Create a new instance of Web3: Connect to the Optimism network using an Alchemy HTTP provider.
from web3 import Web3 import os w3 = Web3(Web3.HTTPProvider(f"https://opt-mainnet.g.alchemy.com/v2/{os.getenv('ALCHEMY_KEY')}"))
-
Create a new instance of Enclave: Initialize the Enclave client with your Enclave key.
from app import Enclave from dotenv import load_dotenv load_dotenv() client = Enclave(os.getenv("ENCLAVE_KEY"))
-
Generate a new Ethereum account: Use your private key to generate an Ethereum account.
eoa = w3.eth.account.from_key(os.getenv("PRIVATE_KEY"))
-
Create an Enclave Smart Contract Wallet: Create a smart account for the generated Ethereum account.
account = client.create_smart_account(eoa.address)
-
Get balance for the Enclave Account: Retrieve and display the balance of the smart account.
balance = client.get_smart_balance(account.wallet.scw_address) print('Smart Account Balance:', balance['netBalance'])
-
Compute a quote: Compute a transaction quote based on the user's willingness to spend.
quote = client.compute_quote(account.wallet.scw_address, network=10, amount=0.1 * 1e6, quote_type='AMOUNT_IN')
-
Define transaction details: Set up the recipient address and amount to transfer.
usdc_on_optimism = '0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85' recipient_address = '0x4E2ef45077FB15Ef5f0FfF9E86B38991aA4bAe5C' # Replace with the recipient's address credit_amount = int(quote['total_credit']) + int(quote['userWithdrawal'])
-
Build and sign the transaction: Build and sign the transaction using the user's Ethereum account.
transaction_details = [{ 'encodedData': usdc_contract.encode_abi("transfer", args=[recipient_address, credit_amount]), 'targetContractAddress': usdc_on_optimism, 'value': 0 }] order_data = {'amount': str(int(amount)), 'type': 'AMOUNT_IN'} built_txn = client.build_transaction(transaction_details, 10, account.wallet.scw_address, order_data, None, 1) signature = eoa.sign_message(encode_defunct(hexstr=built_txn.message_to_sign))
-
Submit the transaction: Submit the transaction to the network.
response = client.submit_transaction("0x" + signature.signature.hex(), user_op_serializable, 10, account.wallet.scw_address, 1) print('Transaction submitted successfully:', response)
Conclusion
This script serves as a basic example of how to use the Enclave SDK to interact with the Ethereum blockchain on the Optimism network. Make sure to replace the placeholder values in the environment variables with your actual keys before running the script.
Metadata
Release files for enclave-py-sdk 0.1.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| enclave_py_sdk-0.1.8.tar.gz | 9.5 kB | Without provenance | Details for enclave_py_sdk-0.1.8.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| enclave_py_sdk-0.1.8-py3-none-any.whl | Python 3 | none | any | Details for enclave_py_sdk-0.1.8-py3-none-any.whl |
Total release size: 20.6 kB
Release files / enclave_py_sdk-0.1.8.tar.gz
| Download URL | enclave_py_sdk-0.1.8.tar.gz |
|---|---|
| Size | 9.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
39ffd8049883a0c7be9a6bed43be61fc96926127e74ca7c78bdc9f50d6b2c65a
|
|
BLAKE2b-256 checksum How to use checksums |
8e5d86136266d242a3585fb2cd9c93246f22ca3b47e60a756f5b1cf26f15e43f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.0.1 CPython/3.12.4 Darwin/23.1.0
|
Release files / enclave_py_sdk-0.1.8-py3-none-any.whl
| Download URL | enclave_py_sdk-0.1.8-py3-none-any.whl |
|---|---|
| Size | 11.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1d57a2e247aebf5389c4e184d5107ab5e736205fa8c03ccbfe8b69d4f2cc36a4
|
|
BLAKE2b-256 checksum How to use checksums |
1fdaec1e231942e336db1d49cd9a74750bffeaade76f0920dab9356ec2a568ea
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.0.1 CPython/3.12.4 Darwin/23.1.0
|
Security for enclave-py-sdk 0.1.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.