pytract
Smart contract Python API generator.
It works by interpreting smart contract ABI and generate corresponding Python API code.
Usage
Install from PyPI:
pip install pytract
Create Python API code for your brownie project:
usage: pytract process [-h] project_path
positional arguments:
project_path Path of the project to process
optional arguments:
-h, --help show this help message and exit
And you shall import all available contracts and programmatically.
If your project folder name is brownie_project then write:
from brownie_project.api import project_info, contracts
print(dir(contracts)) # list available contract classes
print(dir(project_info)) # list project info attributes
Note the difference of using it with brownie alone, you now have a fully portable python package, which you can write static typed code without the need for copying and pasting from brownie console.
You can view all generated API code under folder <your brownie project>/api.
Example generated contract API class is given below:
class Faucet(abi2api.ContractInstance):
_project = project_info.project
_contract_info = project_info.contracts_info["Faucet"]
_contract_name = "Faucet"
class Function(abi2api.FunctionBase):
def returnVars(
self,
):
"""
Function Type: pure
Inputs:
(No parameters)
Outputs:
(uint256, uint256, uint256)
"""
values = self._contract.returnVars()
return values
def withdraw(
self,
withdraw_amount,
_txparams: Optional[abi2api.TransactionParameters] = None,
):
"""
Function Type: nonpayable
Inputs:
withdraw_amount: uint256
Outputs:
(No parameters)
"""
values = self._contract.withdraw(
withdraw_amount, self.txparams_with_fallback(_txparams).dict()
)
return values
def __init__(
self,
contract: Union[Contract, ProjectContract],
issuer: Optional[Account] = None,
_txparams: Optional[abi2api.TransactionParameters] = None,
): # to create you need to either deploy or load contract by address
super().__init__(contract, issuer)
self.function = self.Function(contract, _txparams)
"""
Available functions of this smart contract.
"""
@classmethod
def deploy(cls, _txparams: abi2api.TransactionParameters):
"""
Inputs:
transaction_parameters: TransactionParameters
Output:
contract: Faucet
"""
args = []
parameters = _txparams.to_contract_deploy_parameters(args)
deployed_contract: ProjectContract = cls._contract_info.contract_container.deploy(*parameters.to_args()) # type: ignore
return cls(deployed_contract, _txparams.issuer, _txparams)
Roadmap
- Create a binding to smart contract and APIs for Brownie
- Create a simple pure Python transaction and smart contract platform without blockchain
- Create a TypeChain-like commandline tool for generating standalone package from a list of contract ABI files
Related projects
Stargazers
Metadata
Release files for pytract 0.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pytract-0.0.4.tar.gz | 15.4 kB | Details |
Release files / pytract-0.0.4.tar.gz
| Download URL | pytract-0.0.4.tar.gz |
|---|---|
| Size | 15.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
64e190b76853c8f82e2b31ad0e702b78fddd1eb90f715af9253da022487e259a
|
|
BLAKE2b-256 checksum How to use checksums |
99fec63524b3548c135ec3d3c3bb953b4616d67dbbfbf1be3c110464d85a8f6b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.9.19
|