{"id":15292328,"url":"https://github.com/crocofactory/ether","last_synced_at":"2025-05-07T05:06:25.809Z","repository":{"id":257804792,"uuid":"864985160","full_name":"CrocoFactory/ether","owner":"CrocoFactory","description":"The python package for interacting with Ethereum.","archived":false,"fork":false,"pushed_at":"2024-12-31T16:45:54.000Z","size":81,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-05-07T05:06:20.199Z","etag":null,"topics":["blockchain","crypto","ethereum","ethereum-python","ethereum-wallet","pyether","python","web3","web3py"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/pyether/","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/CrocoFactory.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-09-29T17:29:39.000Z","updated_at":"2025-03-25T00:39:23.000Z","dependencies_parsed_at":null,"dependency_job_id":"780e2474-a773-4561-b82c-57d467f2b7a2","html_url":"https://github.com/CrocoFactory/ether","commit_stats":{"total_commits":3,"total_committers":1,"mean_commits":3.0,"dds":0.0,"last_synced_commit":"141617be997758b4a1ef6c55b1524f5ca7c9e2c9"},"previous_names":["crocofactory/ether"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CrocoFactory%2Fether","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CrocoFactory%2Fether/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CrocoFactory%2Fether/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CrocoFactory%2Fether/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CrocoFactory","download_url":"https://codeload.github.com/CrocoFactory/ether/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252817010,"owners_count":21808705,"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":["blockchain","crypto","ethereum","ethereum-python","ethereum-wallet","pyether","python","web3","web3py"],"created_at":"2024-09-30T16:17:24.089Z","updated_at":"2025-05-07T05:06:25.792Z","avatar_url":"https://github.com/CrocoFactory.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ether\n\u003ca href=\"https://pypi.org/project/pyether/\"\u003e\n\u003ch1 align=\"center\"\u003e\n\u003cimg alt=\"Logo Banner\" src=\"https://raw.githubusercontent.com/CrocoFactory/.github/main/branding/ether/bookmark.svg\" width=\"300\"\u003e\n\u003c/h1\u003e\u003cbr\u003e\n\u003c/a\u003e\n\n*The python package for interacting with Ethereum.*\n\n[![Python versions](https://img.shields.io/pypi/pyversions/pyether?color=%234F8EE9)](https://pypi.org/project/pyether/)\n[![PyPi Version](https://img.shields.io/pypi/v/pyether?color=%234F8EE9)](https://pypi.org/project/pyether/)\n\n---\n\n**Documentation:** [https://ether.crocofactory.dev](https://ether.crocofactory.dev)\n\n**Source code:** [https://github.com/CrocoFactory/ether](https://github.com/CrocoFactory/ether)\n\n---\n         \n\n`ether` is a Python library designed to interact with the Ethereum blockchain, providing a simple and intuitive way to work with Ethereum accounts, transactions, smart contracts, and tokens. It is a wrapper around the popular `web3.py` library, making Ethereum interaction easier for developers.\n\nWith `ether`, you can:\n\n- 🔑 **Manage Accounts**: Easily generate wallet objects using your private key and interact with various Ethereum networks (e.g., Arbitrum, Polygon, BSC).  \n- 💰 **Check balances**: Retrieve the balance of your Ethereum account and manage funds across different chains.  \n- 🚀 **Make transactions**: Transfer Ether and ERC-20 tokens seamlessly between Ethereum accounts.  \n- 💥 **Smart contracts**: Call functions and send transactions to Ethereum smart contracts, enabling interaction with DeFi protocols and decentralized applications (dApps).  \n- 🔗 **Easily integrate chains**: Seamlessly add and interact with custom Ethereum networks by name or through a `Network` object, making it simple to connect with various blockchain environments.     \n- ⚡ **Asynchronous support**: Perform network calls asynchronously, ideal for working in applications that require non-blocking behavior.\n       \n\n...and much more. Unlock a wide range of functionalities to simplify Ethereum development, enhance your dApp experience, and seamlessly integrate blockchain operations into your projects.\n\n\nTable of Contents:\n\n1. [Quick Overview](#quick-overview)\n2. [First Transaction](#first-transaction)\n2. [Comparison](#comparison)\n4. [Installing](#installing)\n\n## Quick Overview\n\nEach Ethereum account has the associated:\n\n- **Public Key** 🔑 (32 bytes, 66 characters): synonym for account address. You use it when you want to share payment details. \n- **Private Key** 🔐 (20 bytes, 42 characters): key required for making (signing) transactions. It's like a **password**, but stronger. You should not \n  share it with others. \n\nYou can make transactions in different networks (chains), like:\n\n- Arbitrum\n- Base\n- BSC\n- Ethereum\n- Optimism\n- Polygon\n- zkSync\n\nThey can differ from each other by some criteria, like native token and average transaction fees (gas ⛽). To interact with \nsome chain, you have to connect to its RPC. \n\n\n## First Transaction\n\nBefore making transactions, you need to create an object, associated with your Ethereum account. This object is called `Wallet`.\n```python\nfrom ether import Wallet\nmy_wallet = Wallet('0xPrivateKey', 'Arbitrum')\n```\n\nThe first argument is private key. The second is network, represented as `Network` object or network's name, if you use one of \nthe built-innetworks.\n\nExample with `Network` instance:\n\n```python\nfrom ether import Wallet, Network\n\nnetwork = Network(\n  name='BOB', \n  rpc='https://bob.drpc.org', \n  token='ETH', \n  explorer='https://explorer.gobob.xyz'\n)\n\ncustom_wallet = Wallet('0xPrivateKey', network)\n```\n\nFurthermore, `ether` supports asynchronous approach:\n\n```python\nfrom ether import AsyncWallet\n\nasync def validate_balance():\n    async_wallet = AsyncWallet('0xPrivateKey', 'Arbitrum')\n    balance = await async_wallet.get_balance()\n    assert balance \u003e 0.1\n```\n\nOnce your wallet is created, you can perform transactions easily. Let's start with a simple Ethereum transfer from your \nwallet to another address.\n\n```python\nfrom ether import Wallet\n\n# Create a wallet instance\nwallet = Wallet('0xPrivateKey', 'Ethereum')\n\n# Define the recipient address and amount to send\nrecipient = '0xRecipientAddressHere'\namount_in_wei = 10 ** 18  # 1 Ether (in Wei units)\n\n# Perform the transfer\nparams = wallet.build_tx_params(amount_in_wei, recipient)\ntx_hash = wallet.transact(params)\n\nprint(f\"Transaction sent! Hash: {params.hex()}\")\n```\n\n### Contract Calls\n\nInteracting with smart contracts is seamless with `ether`. \n\n```python\nfrom ether import Wallet\n\n# Initialize the wallet object with your private key and network (e.g., Arbitrum)\nwallet = Wallet('0xPrivateKey', 'Arbitrum')\n\n# Access the provider associated with the wallet\nprovider = wallet.provider\n\n# Define the ABI (Application Binary Interface) of the smart contract and the contract address\nstargate_abi = [...]  \nstargate_router = '0x8731d54E9D02c286767d56ac03e8037C07e01e98'  # Contract address (Stargate Router)\n\n# Create a contract instance using the ABI and contract address\nstargate = wallet.provider.eth.contract(address=stargate_router, abi=stargate_abi)\n\nusdt = '0xUsdtAddress'  \neth_amount = provider.to_wei(0.001, 'ether')  # 0.001 Ether to Wei\n\n# Prepare the contract function call to swap ETH for USDT using the smart contract's function\nclosure = stargate.functions.swapETH(eth_amount, usdt)\n\n# Build the transaction and send it\nwallet.build_and_transact(closure, eth_amount)\n```\n\n### Sending Tokens \n\nTo send ERC-20 tokens, use the `transfer` method with the token contract address and recipient details:\n\n```python\nfrom ether import Wallet\n\nwallet = Wallet('0xPrivateKey', 'Ethereum')\n\n# Token details\ntoken_address = '0xTokenAddressHere'\ntoken = wallet.get_token(token_address)\n\n# Recipient and amount\nrecipient = '0xRecipientAddressHere'\namount = 100 * 10 ** token.decimals  # Sending 100 USDT\n\n# Perform the token transfer\ntransaction_hash = wallet.transfer(token, recipient, amount)\n\nprint(f\"Token transfer sent! Hash: {transaction_hash.hex()}\")\n```\n\n### Approving Tokens\n\nIf you plan to interact with DeFi protocols, you might need to approve a contract to spend your tokens:\n\n```python\n# Contract address (e.g., a DeFi protocol)\ncontract_address = '0xContractAddressHere'\namount_to_approve = 1000 * 10 ** token.decimals\n\n# Approve the contract to spend tokens\napproval_tx_hash = wallet.approve(token, contract_address, amount_to_approve)\n\nprint(f\"Approval transaction sent! Hash: {approval_tx_hash.hex()}\")\n```\n\n### Utility Functions\n\n- `get_balance(from_wei=False)`: Retrieves the account balance. Use `from_wei=True` to get the balance in Ether units.\n\n    ```python\n    balance = wallet.get_balance(from_wei=True)\n    print(f\"Current balance: {balance} ETH\")\n    ```\n\n- `estimate_gas(tx_params)`: Estimates the gas required for a transaction.\n\n    ```python\n    estimated_gas = wallet.estimate_gas({\n        'to': recipient,\n        'value': amount_in_wei\n    })\n    print(f\"Estimated gas: {estimated_gas}\")\n    ```      \n\nBy following these examples, you can start interacting with Ethereum and tokens using `ether`. For further details, explore the full documentation linked above.\n                \n## Comparison\n\n`ether` simplifies many Ethereum-related tasks by abstracting common operations and reducing the amount of boilerplate\ncode required in `web3.py`.\n\n### `web3.py`\n\nTo send Ether using `web3.py`, you would need to build the transaction manually, estimate gas, and sign it:\n\n```python\nfrom web3 import Web3\n\n# Initialize Web3 instance\nw3 = Web3(Web3.HTTPProvider('https://mainnet.infura.io/...'))\n\n# Sender and recipient details\nsender_address = '0xSenderAddressHere'\nrecipient_address = '0xRecipientAddressHere'\nprivate_key = '0xPrivateKey'\n\n# Get nonce (transaction count)\nnonce = w3.eth.get_transaction_count(sender_address)\n\n# Prepare transaction details\ntx = {\n    'to': recipient_address,\n    'value': w3.to_wei(0.1, 'ether'),  # Sending 0.1 Ether\n    'gas': 2000000,\n    'gasPrice': w3.to_wei('20', 'gwei'),\n    'nonce': nonce,\n}\n\n# Sign the transaction\nsigned_tx = w3.eth.account.sign_transaction(tx, private_key)\n\n# Send the transaction\ntx_hash = w3.eth.send_raw_transaction(signed_tx.rawTransaction)\n\nprint(f\"Transaction sent! Hash: {tx_hash.hex()}\")\n```\n\n### `ether`\n\nWith `ether`, the same operation is simplified to 2 method calls:\n\n```python\nfrom ether import Wallet\n\n# Create a wallet instance\nwallet = Wallet('0xPrivateKey', 'Ethereum')\n\n# Define recipient and amount\nrecipient = '0xRecipientAddressHere'\namount_in_wei = 10 ** 18  # 1 Ether (in Wei)\n\n# Build transaction params and send the transaction\nparams = wallet.build_tx_params(amount_in_wei, recipient)\ntx_hash = wallet.transact(params)\n\nprint(f\"Transaction sent! Hash: {tx_hash.hex()}\")\n```\n\n\n## Installing\nTo install `ether` from PyPi, you can use that:\n\n```shell\npip install pyether\n```\n\nTo install `ether` from GitHub, use that:\n\n```shell\npip install git+https://github.com/CrocoFactory/ether.git\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrocofactory%2Fether","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcrocofactory%2Fether","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrocofactory%2Fether/lists"}