{"id":14958573,"url":"https://github.com/naoki-maeda/py-contract-codegen","last_synced_at":"2025-10-24T14:32:10.577Z","repository":{"id":255352274,"uuid":"847285581","full_name":"naoki-maeda/py-contract-codegen","owner":"naoki-maeda","description":"A cli tool to generate Python code from EVM ABI.","archived":false,"fork":false,"pushed_at":"2025-01-21T00:12:13.000Z","size":218,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-31T02:30:04.662Z","etag":null,"topics":["ethereum","web3","web3py"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/py-contract-codegen/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/naoki-maeda.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-25T11:45:24.000Z","updated_at":"2025-01-21T00:12:13.000Z","dependencies_parsed_at":null,"dependency_job_id":"1d61fadb-2bcb-4421-8886-80aac922fc29","html_url":"https://github.com/naoki-maeda/py-contract-codegen","commit_stats":{"total_commits":41,"total_committers":2,"mean_commits":20.5,"dds":"0.46341463414634143","last_synced_commit":"b165c03cbf4584c3445d39ae1bed69c3236dae16"},"previous_names":["naoki-maeda/py-contract-codegen"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naoki-maeda%2Fpy-contract-codegen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naoki-maeda%2Fpy-contract-codegen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naoki-maeda%2Fpy-contract-codegen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naoki-maeda%2Fpy-contract-codegen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/naoki-maeda","download_url":"https://codeload.github.com/naoki-maeda/py-contract-codegen/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237990603,"owners_count":19398459,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ethereum","web3","web3py"],"created_at":"2024-09-24T13:17:26.069Z","updated_at":"2025-10-24T14:32:02.143Z","avatar_url":"https://github.com/naoki-maeda.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# py-contract-codegen\n\n`py-contract-codegen` is a command-line tool for generating Python code from Ethereum ABI.\n\n### Installation\n\n```sh\npip install py-contract-codegen\n```\n\n### Commands\n\n1. `gen`: Generate Python code from an Ethereum ABI file.\n2. `version`: Show the version of the code generator.\n\n### `gen` Command\n\nThe `gen` command is used to generate Python code from an Ethereum ABI.\n\n```\npy-contract-codegen gen [OPTIONS]\n```\n\n#### Options\n\n```\n╭─ Options ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮\n│ --abi-path                              PATH               Path to ABI file. If not provided, `--abi-stdin` or `--contract-address` must be set [default: None]                       │\n│ --abi-stdin           --no-abi-stdin                       ABI content from stdin [default: no-abi-stdin]                                                                             │\n│ --contract-address                      TEXT               Auto fetch abi from etherscan and generate code. Please set environment variable `ETHERSCAN_API_KEY` [default: None]       │\n│ --out-file                              PATH               Path to save file name the generated code. If not provided, prints to stdout [default: None]                               │\n│ --class-name                            TEXT               Contract Class Name to save the generated code. If not provided, use `GeneratedContract` [default: GeneratedContract]      │\n│ --target-lib                            [web3_v7|web3_v6]  Target library and version [default: web3_v7]                                                                              │\n│ --network                               [mainnet|sepolia]  Ethereum network for fetching ABI [default: mainnet]                                                                       │\n│ --help                                                     Show this message and exit.                                                                                                │\n╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯\n```\n\n### Command Examples\n\n#### Gen from ABI file\n\n```sh\npy-contract-codegen gen --abi-path {ABI_FILE_PATH} --out-file generated_contract.py\n```\n\n### Gen from stdin\n\n```sh\ncat {ABI_FILE_PATH} | py-contract-codegen gen --abi-stdin --out-file generated_contract.py\n```\n\n### Gen from Contract Address\n\nIt automatically generates code by fetching the ABI through [Etherscan](https://etherscan.io/) API.\n\nThe contract's source code needs to be verified on Etherscan.\n\nPlease set environment variable `ETHERSCAN_API_KEY`.\n\n```sh\npy-contract-codegen gen --contract-address {CONTRACT_ADDRESS} --out-file generated_contract.py\n```\n\n### Examples\n\nTo use the generated contract, you need to install [web3.py](https://github.com/ethereum/web3.py).\n\n[Here's an example](https://github.com/naoki-maeda/py-contract-codegen/tree/main/src/py_contract_codegen/generated) of a generated contract:\n\n### ERC20\n\n```py\nfrom web3 import Web3\nfrom eth_account import Account\n\nw3 = Web3(provider=Web3.HTTPProvider(\"{YOUR_PROVIDER_URL}\"))\nprivate_key = \"{YOUR_PRIVATE_KEY}\"\ncontract_address = w3.to_checksum_address(\"{YOUR_CONTRACT_ADDRESS}\")\nto_address = w3.to_checksum_address(\"{YOUR_TO_ADDRESS}\")\n\ncontract = GeneratedContract(contract_address=contract_address, web3=w3)\naccount = Account.from_key(private_key)\n\n# balanceOf\nbalance = contract.balanceOf(to_address)\n\n# transfer\ntransfer = contract.transfer(to_address, 1)\nnonce = w3.eth.get_transaction_count(account.address)\nbuild_tx = transfer.build_transaction({\"from\": account.address, \"nonce\": nonce})\nsigned_tx = account.sign_transaction(build_tx)\ntx_hash = w3.eth.send_raw_transaction(signed_tx.rawTransaction)\nw3.eth.wait_for_transaction_receipt(tx_hash)\n```\n\n### License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnaoki-maeda%2Fpy-contract-codegen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnaoki-maeda%2Fpy-contract-codegen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnaoki-maeda%2Fpy-contract-codegen/lists"}