foundrycli.py (
🔥
,
🐍
)
foundrycli.py is a Python library I've made for personal use; now open source.
It lets you access forge and cast CLIs from Python scripts and correctly handles the output, with some handy features:
Features
Run any command as if you were using the terminal
# Get VB's address
vitalik = foundry_cli('cast resolve-name "vitalik.eth"')
Use in scripts with composable commands
# Calculate VB's $$$ in stables
for coin in stables:
sum += foundry_cli(f'cast call {coin} "balanceOf(address)(uint256)" {vitalik}')
Access anything, effortlessly
# Get the hash of the 100th transaction from the latest block
foundry_cli('cast block latest')["transactions"][100]
Automatic output conversion: str, int, Decimal, dict, JSON (str)
- Whole numbers will be returned as
intand decimal asDecimal, for max precision - Multiple values, such as
deployer,deployedTo,transactionHashwill be returned asdict - JSON will be converted to
dictfor superior UX
Coverage
-
forge(forge createonly) -
cast(100%837209b)
Instructions
Clone repository
git clone https://github.com/ZeroEkkusu/foundrycli.py
Install library
pip install dist/foundrycli-0.1.0-py3-none-any.whl
Usage
Import foundry_cli in your script
from foundrycli import foundry_cli
Pass command and force_string_output (if you want to disable conversion)
balance = foundry_cli('cast balance "vitalik.eth"')
Compose commands instead of hardcoding them
ens_name = "vitalik.eth"
balance = foundry_cli(f'cast balance {ens_name}')