Eclair CLI Tool
Description
Eclair is a Command Line Interface (CLI) tool designed to streamline the creation of library wrappers for Blockchain Business Logic code. With Eclair, you can initialize a new project and run eclair wrap on it to generate Python library wrappers for your contracts. And since it dependes on the ABI, it can be used with any language that can generate an ABI.
Installation
Eclair can be installed via pip:
pip install eclair
Usage
Initialize a Project
To initialize a new project, use the init command:
eclair init
During initialization, you will be asked to specify:
-
The directory where you want to instantiate the project (default is the current directory).
-
The preferred RPC endpoint (default is
localhost:7545). -
The preferred Deployer address.
The tool will automatically create necessary directories and a configuration file in JSON format.
Generate Python Library Wrappers
To generate Python library wrappers from your Solidity files, simply run Eclair with no arguments:
eclair wrap
This will process Solidity files found in the contracts directory of your project, generate an ABI for each contract, and then generate a Python class for each ABI in the wrappers directory.
Configuration
Eclair's behavior can be customized via the eclair.config.json file in your project directory. This file is created when you initialize a project and includes a number of settings:
-
run_compile: Whether to compile the Solidity files before processing (default istrue). -
constructor_args: Arguments to be passed to the contract constructor when deploying. -
network_name: Network to deploy to (e.g.,http://example.com). -
private_key: Your private key for signing transactions. -
abi_path: Path to the ABI file for the contract. -
from_address: Your address (will be used as the sender of transactions). -
gas: Gas limit for transactions. -
gas_price: Gas price for transactions. -
nonce: Nonce for transactions. -
output_directory: Directory to output the Python wrapper classes to (default iswrappers).
Example
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.6;
contract HelloWorld {
string public greet = "Hello, World!";
function sayHello() public view returns (string memory) {
return greet;
}
}
Will generate the following Python wrapper:
import os
import json
from typing import Dict, Tuple
from web3 import Web3
def Deployer(w3):
os.system("npx hardhat compile")
private_key = 'your_private_key'
account = w3.eth.account.from_key(private_key)
with open('path_to_abi_file', 'r') as file:
contract_dump = json.load(file)
abi = contract_dump['abi']
bytecode = contract_dump['bytecode']
contract = w3.eth.contract(abi=abi, bytecode=bytecode)
deploy_txn = contract.constructor([]).buildTransaction({
'from': 'your_address',
'gas': 200000,
'gasPrice': 1000000000,
'nonce': 0
})
signed_txn = account.sign_transaction(deploy_txn)
deployment_receipt = w3.eth.send_raw_transaction(signed_txn.rawTransaction)
deployment_receipt = w3.eth.wait_for_transaction_receipt(deployment_receipt)
contract_address = deployment_receipt['contractAddress']
return {
'contract_address': contract_address,
'abi' : abi
}
class contract_HelloWorld_class:
def __init__(self, rpc='http://example.com', private_key='your_private_key'):
self.w3 = Web3(Web3.HTTPProvider('http://example.com'))
self.deployed = Deployer(self.w3)
self.contract_address = self.deployed['contract_address']
self.abi = self.deployed['abi']
self.contract = self.w3.eth.contract(address=self.contract_address, abi=self.abi)
self.private_key = private_key
def call_function(self, function_name: str, *args) -> Dict:
function = getattr(self.contract.functions, function_name)(*args)
return function.call(
{
'from': self.w3.eth.default_account,
'gas': {},
'gasPrice': self.w3.eth.gas_price,
'nonce': self.w3.eth.get_transaction_count(self.w3.eth.default_account),
}
)
def execute_transaction(self, function_name: str, *args) -> Dict:
base_fee = self.w3.eth.gas_price * {}
function = getattr(self.contract.functions, function_name)(*args)
transaction = function.build_transaction({
'from': self.w3.eth.default_account,
'gas': {},
'gasPrice': self.w3.eth.gas_price,
'nonce': self.w3.eth.get_transaction_count(self.w3.eth.default_account),
})
signed_transaction = self.w3.eth.account.sign_transaction(
transaction, private_key=self.private_key)
tx_hash = self.w3.eth.send_raw_transaction(
signed_transaction.rawTransaction)
self.w3.eth.wait_for_transaction_receipt(tx_hash)
receipt = self.w3.eth.get_transaction_receipt(tx_hash)
if receipt['status'] == 0:
raise Exception('Transaction failed')
elif receipt['status'] == 1:
return {
'txHash': tx_hash.hex(),
'returns': receipt,
'isSuccess': receipt['status'] == 1,
}
else:
raise Exception('Unknown error')
def execute_transaction_greet(self) -> (str):
return self.execute_transaction('greet')
def execute_transaction_sayHello(self) -> (str):
return self.execute_transaction('sayHello')
Contributing
Contributions to Eclair are welcome! Please read our contributing guidelines for how to proceed.
Todos
- [] Support Rust
- [] Support JavaScript
- [] Write extensive tests
- [] Allow for rudiementary test generation
- [] Allow for advanced wrapper customisation from config file
License
Eclair is released under the MIT License. See the LICENSE file for more details.
Contact
If you have any issues or feature requests, please open an issue on the Eclair GitHub page. For other inquiries, you can reach out ioc.exchange/@formalcurryfication ~!
MIT License can be accessed here
Metadata
Release files for eclair-cli 1.0.5
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 |
|---|---|---|---|---|
| eclair-cli-1.0.5.tar.gz | 8.2 kB | Without provenance | Details for eclair-cli-1.0.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| eclair_cli-1.0.5-py3-none-any.whl | Python 3 | none | any | Details for eclair_cli-1.0.5-py3-none-any.whl |
Total release size: 17.5 kB
Release files / eclair-cli-1.0.5.tar.gz
| Download URL | eclair-cli-1.0.5.tar.gz |
|---|---|
| Size | 8.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1ec5d0d494c882bf89d2312cf641dd03d4c2cb7c6f14affb095fd1d3ba73954f
|
|
BLAKE2b-256 checksum How to use checksums |
009bf669e9322b4fd7eac8cc41708112638045b31f838b87e85af73d69774eb8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.4
|
Release files / eclair_cli-1.0.5-py3-none-any.whl
| Download URL | eclair_cli-1.0.5-py3-none-any.whl |
|---|---|
| Size | 9.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
414503cf8c9e898b488ec5cbcf5439c686991f421b9ccd5fe0183bf42ee3eaaf
|
|
BLAKE2b-256 checksum How to use checksums |
0f3d2fcfde9f700d646ec3dfa762ee0272ed49c259210689347700e5fa4388c5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.4
|
Security for eclair-cli 1.0.5
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.