Package: eclair-cli
Eclair CLI ToolDescriptionEclair 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 runeclair wrapon 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.InstallationEclair can be installed via pip:pipinstalleclairUsageInitialize a ProjectTo initialize a new project, use theinitcommand:eclairinitDuring 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 islocalhost:7545).The preferred Deployer address.The tool will automatically create necessary directories and a configuration file in JSON format.Generate Python Library WrappersTo generate Python library wrappers from your Solidity files, simply run Eclair with no arguments:eclairwrapThis will process Solidity files found in thecontractsdirectory of your project, generate an ABI for each contract, and then generate a Python class for each ABI in thewrappersdirectory.ConfigurationEclair's behavior can be customized via theeclair.config.jsonfile 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: MITpragma solidity^0.8.6;contractHelloWorld{stringpublicgreet="Hello, World!";functionsayHello()publicviewreturns(stringmemory){returngreet;}}Will generate the following Python wrapper:importosimportjsonfromtypingimportDict,Tuplefromweb3importWeb3defDeployer(w3):os.system("npx hardhat compile")private_key='your_private_key'account=w3.eth.account.from_key(private_key)withopen('path_to_abi_file','r')asfile: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}classcontract_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_keydefcall_function(self,function_name:str,*args)->Dict:function=getattr(self.contract.functions,function_name)(*args)returnfunction.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),})defexecute_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)ifreceipt['status']==0:raiseException('Transaction failed')elifreceipt['status']==1:return{'txHash':tx_hash.hex(),'returns':receipt,'isSuccess':receipt['status']==1,}else:raiseException('Unknown error')defexecute_transaction_greet(self)->(str):returnself.execute_transaction('greet')defexecute_transaction_sayHello(self)->(str):returnself.execute_transaction('sayHello')ContributingContributions 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 fileLicenseEclair is released under the MIT License. See the LICENSE file for more details.ContactIf 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 accessedhere