No project description provided
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file enclave_py_sdk-0.1.3.tar.gz.
File metadata
- Download URL: enclave_py_sdk-0.1.3.tar.gz
- Upload date:
- Size: 9.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.0.1 CPython/3.12.4 Darwin/23.1.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f2f1a3c003478c5114e90fec7e4b8a5aee92dc6b4b505548f6913e65efd2b817
|
|
| MD5 |
d4186984e4eec0f908d176cb7db24200
|
|
| BLAKE2b-256 |
be6fc516601672e912ca07dfd52f8c79482a7ae0aa388a68c90e569dcaceadba
|
File details
Details for the file enclave_py_sdk-0.1.3-py3-none-any.whl.
File metadata
- Download URL: enclave_py_sdk-0.1.3-py3-none-any.whl
- Upload date:
- Size: 10.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.0.1 CPython/3.12.4 Darwin/23.1.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d5bf340d845135f7dbcc99183aec2ee701bfcc1faf2d54c392a4d7caca4ca884
|
|
| MD5 |
efcb59a062333662be3a431262335aee
|
|
| BLAKE2b-256 |
36eff2fcc93ec873b5a9ea104d8a972cde05fcf93a6ffd24bbfb79d776ea6c51
|