Name | pyether JSON |
Version |
0.2.1
JSON |
| download |
home_page | https://github.com/CrocoFactory/ether |
Summary | The web3.py operation wrapper, offering interaction through Wallet instances. |
upload_time | 2024-09-29 21:11:09 |
maintainer | None |
docs_url | None |
author | Alexey |
requires_python | <4.0,>=3.9 |
license | MIT |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# ether
<p align="center">
<img src="https://raw.githubusercontent.com/CrocoFactory/.github/main/branding/ether/bookmark.svg" height="80">
</p>
[![Python versions](https://img.shields.io/pypi/pyversions/pyether?color=%234F8EE9)](https://pypi.org/project/pyether/)
[![PyPi Version](https://img.shields.io/pypi/v/pyether?color=%234F8EE9)](https://pypi.org/project/pyether/)
The web3.py operation wrapper, offering interaction through Wallet instances.
- **[Overview](#quick-overview)**
- **[Bug reports](https://github.com/CrocoFactory/ether-py/issues)**
Web3.py suggests to interact with instance of Web3 as primary entity. We offer way to use Wallet entity, that is more
familiar, since we try to provide the similar to digital wallet apps' logic. We introduce:
- possibility to set and change current wallet's network by network's name
- swift and robust performing transactions
- quick performing useful functions of Web3.py
The project is made by the **[Croco Factory](https://github.com/CrocoFactory)** team
ether's source code is made available under the [MIT License](LICENSE)
## Quick start
You can quickly use supported networks as RPC:
| Network | Native Token | Testnet |
|------------------|--------------|---------|
| Arbitrum Goerli | ETH | ✅ |
| Arbitrum Sepolia | ETH | ✅ |
| Arbitrum | ETH | ❌ |
| Avalanche | AVAX | ❌ |
| Base | ETH | ❌ |
| Base Sepolia | ETH | ✅ |
| Base Goerli | ETH | ✅ |
| BSC | BNB | ❌ |
| BSC Testnet | BNB | ✅ |
| Ethereum | ETH | ❌ |
| Fantom | FTM | ❌ |
| Fantom Testnet | FTM | ✅ |
| Fuji | AVAX | ✅ |
| Goerli | ETH | ✅ |
| Linea | ETH | ❌ |
| Linea Goerli | ETH | ✅ |
| Linea Sepolia | ETH | ✅ |
| Mumbai | MATIC | ✅ |
| opBNB | BNB | ❌ |
| opBNB Testnet | BNB | ✅ |
| Optimism | ETH | ❌ |
| Optimism Sepolia | ETH | ✅ |
| Optimism Goerli | ETH | ✅ |
| Polygon | MATIC | ❌ |
| Sepolia | ETH | ❌ |
| Scroll | ETH | ❌ |
| zkSync | ETH | ❌ |
For specifying network you only need to pass network's name.
```python
from ether import Wallet
my_wallet = Wallet('your_private_key', 'Arbitrum')
```
If you use unsupported network, you can specify it using `Network` instance
```python
from ether import Wallet, Network
network_info = Network(
name='Custom',
rpc='wss://custom.publicnode.com',
token='CUSTOM'
)
custom_wallet = Wallet('your_private_key', network_info)
```
Library supports asynchronous approach
```python
from ether import AsyncWallet
async def validate_balance():
async_wallet = AsyncWallet('your_private_key', 'Arbitrum')
balance = await async_wallet.get_balance()
assert balance > 0.1
```
<h2 id="quick-overview">Quick overview</h2>
You can perform the following actions, using ether:
- **[approve](#approve)**
- **[build_and_transact](#build_and_transact)**
- **[build_tx_params](#build_tx_params)**
- **[create](#create)**
- **[estimate_gas](#estimate_gas)**
- **[get_balance](#get_balance)**
- **[get_balance_of](#get_balance_of)**
- **[get_token](#get_token)**
- **[get_explorer_url](#get_explorer_url)**
- **[is_native_token](#is_native_token)**
- **[transact](#transact)**
- **[transfer](#transfer)**
<h3 id="approve">approve</h3>
When you want to spend non-native tokens, for instance USDT, you need to perform approving operation.
```python
from ether import Wallet
my_wallet = Wallet('your_private_key', 'Arbitrum')
provider = my_wallet.provider
stargate_router = '0x8731d54E9D02c286767d56ac03e8037C07e01e98'
usdt = my_wallet.get_token('0xdAC17F958D2ee523a2206206994597C13D831ec7')
usdt_amount = provider.to_wei(0.001, 'ether')
my_wallet.approve(usdt, stargate_router, usdt_amount)
```
<h3 id="build_and_transact">build_and_transact</h3>
If you don't need to check estimated gas or directly use transact, you can call build_and_transact. It's based on getting
closure as argument. Closure is transaction's function, called with arguments. Notice that it has to be not built or
awaited
```python
from ether import Wallet
my_wallet = Wallet('your_private_key', 'Arbitrum')
provider = my_wallet.provider
stargate_abi = [...]
stargate_router = '0x8731d54E9D02c286767d56ac03e8037C07e01e98'
stargate = my_wallet.provider.eth.contract(stargate_router, abi=stargate_abi)
eth_amount = provider.to_wei(0.001, 'ether')
closure = stargate.functions.swapETH(...)
my_wallet.build_and_transact(closure, eth_amount)
```
<h3 id="build_tx_params">build_tx_params</h3>
You can use build_tx_params to quickly get dictionary of params for building transaction. Public key, chain id
and nonce are generated automatically. You also can also choose not to set a gas and the gas price
```python
from ether import Wallet
my_wallet = Wallet('your_private_key', 'BSC')
my_wallet.build_tx_params(0)
```
```json
{
"from": "0xe977Fa8D8AE7D3D6e28c17A868EF04bD301c583f",
"chainId": 56,
"nonce": 168,
"value": 0,
"gas": 250000,
"gasPrice": 1000000000
}
```
<h3 id="create">create</h3>
You can use that, when you want to create all-new wallet
```python
from ether import Wallet
wallet = Wallet.create('Arbitrum')
```
<h3 id="estimate_gas">estimate_gas</h3>
When you want to estimate an amount of gas to send a transaction, you can use estimate_gas
```python
from ether import Wallet
my_wallet = Wallet('your_private_key', 'Arbitrum')
provider = my_wallet.provider
stargate_router = '0x8731d54E9D02c286767d56ac03e8037C07e01e98'
stargate_abi = [...]
eth_amount = provider.to_wei(0.001, 'ether')
stargate = my_wallet.provider.eth.contract(stargate_router, abi=stargate_abi)
params = my_wallet.build_tx_params(eth_amount)
tx_params = stargate.functions.swapETH(...).buildTransaction(params)
gas = my_wallet.estimate_gas(tx_params)
tx_params['gas'] = gas
my_wallet.transact(tx_params)
```
<h3 id="get_balance">get_balance</h3>
You can get the balance of the native token of your wallet.
```python
from ether import Wallet
my_wallet = Wallet('your_private_key', 'Arbitrum')
balance = my_wallet.get_balance()
```
<h3 id="get_balance_of">get_balance_of</h3>
You can get the balance of specified token of your wallet
```python
from ether import Wallet
my_wallet = Wallet('your_private_key', 'Arbitrum')
usdt = my_wallet.get_token('0xdAC17F958D2ee523a2206206994597C13D831ec7')
balance = my_wallet.get_balance_of(usdt, convert=True)
print(balance)
```
<h3 id="get_token">get_token</h3>
You can get the `Token` instance, containing information about symbol and decimals. Also this function used for
another instance-methods of Wallet.
```python
from ether import Wallet
my_wallet = Wallet('your_private_key', 'Arbitrum')
usdt = my_wallet.get_token('0xdAC17F958D2ee523a2206206994597C13D831ec7')
print(usdt.decimals)
```
<h3 id="get_explorer_url">get_explorer_url</h3>
You can get entire wallet's list of transactions
```python
from ether import Wallet
from web3.contract import Contract
my_wallet = Wallet('your_private_key', 'Arbitrum')
provider = my_wallet.provider
stargate_router = '0x8731d54E9D02c286767d56ac03e8037C07e01e98'
stargate_abi = [...]
stargate = Contract(stargate_router, stargate_abi)
eth_amount = provider.to_wei(0.001, 'ether')
closure = stargate.functions.swapETH(...)
tx_hash = my_wallet.build_and_transact(closure, eth_amount)
print(my_wallet.get_explorer_url(tx_hash))
```
<h3 id="is_native_token">is_native_token</h3>
If you want to check, if the specific token is native token of network, you can use is_native_token.
You can use any case in a token's ticker.
```python
from ether import Wallet
my_wallet = Wallet('your_private_key', 'Arbitrum')
assert my_wallet.is_native_token('eTh')
```
<h3 id="transact">transact</h3>
After building transaction you can perform it, passing transaction data to transact
```python
from ether import Wallet
my_wallet = Wallet('your_private_key', 'Arbitrum')
provider = my_wallet.provider
stargate_router = '0x8731d54E9D02c286767d56ac03e8037C07e01e98'
stargate_abi = [...]
eth_amount = provider.to_wei(0.001, 'ether')
stargate = my_wallet.provider.eth.contract(stargate_router, abi=stargate_abi)
params = my_wallet.build_tx_params(eth_amount)
tx_data = stargate.functions.swapETH(...).buildTransaction(params)
gas = my_wallet.estimate_gas(tx_data)
tx_data['gas'] = gas
my_wallet.transact(tx_data)
```
<h3 id="transfer">transfer</h3>
You can transfer tokens to another wallet
```python
from ether import Wallet
my_wallet = Wallet('your_private_key', 'Arbitrum')
provider = my_wallet.provider
recipient = '0xe977Fa8D8AE7D3D6e28c17A868EF04bD301c583f'
usdt = my_wallet.get_token('0xdAC17F958D2ee523a2206206994597C13D831ec7')
usdt_amount = provider.to_wei(0.001, 'ether')
my_wallet.transfer(usdt, recipient, usdt_amount)
```
# Installing ether
To install the package from PyPi you can use:
```shell
pip install pyether
```
To install the package from GitHub you can use:
```shell
pip install git+https://github.com/CrocoFactory/ether.git
```
Raw data
{
"_id": null,
"home_page": "https://github.com/CrocoFactory/ether",
"name": "pyether",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.9",
"maintainer_email": null,
"keywords": null,
"author": "Alexey",
"author_email": "axbelenkov@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/2f/28/ce811c6c2834a81e7cdd79433d735825e9f68cba486a8966cf3b68e592ac/pyether-0.2.1.tar.gz",
"platform": null,
"description": "# ether\n\n<p align=\"center\">\n<img src=\"https://raw.githubusercontent.com/CrocoFactory/.github/main/branding/ether/bookmark.svg\" height=\"80\">\n</p>\n \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\nThe web3.py operation wrapper, offering interaction through Wallet instances.\n\n- **[Overview](#quick-overview)**\n- **[Bug reports](https://github.com/CrocoFactory/ether-py/issues)**\n\n\nWeb3.py suggests to interact with instance of Web3 as primary entity. We offer way to use Wallet entity, that is more \nfamiliar, since we try to provide the similar to digital wallet apps' logic. We introduce:\n \n- possibility to set and change current wallet's network by network's name\n- swift and robust performing transactions\n- quick performing useful functions of Web3.py\n\nThe project is made by the **[Croco Factory](https://github.com/CrocoFactory)** team\n \nether's source code is made available under the [MIT License](LICENSE)\n\n## Quick start\nYou can quickly use supported networks as RPC: \n\n| Network | Native Token | Testnet |\n|------------------|--------------|---------|\n| Arbitrum Goerli | ETH | \u2705 |\n| Arbitrum Sepolia | ETH | \u2705 |\n| Arbitrum | ETH | \u274c |\n| Avalanche | AVAX | \u274c |\n| Base | ETH | \u274c |\n| Base Sepolia | ETH | \u2705 |\n| Base Goerli | ETH | \u2705 |\n| BSC | BNB | \u274c |\n| BSC Testnet | BNB | \u2705 |\n| Ethereum | ETH | \u274c |\n| Fantom | FTM | \u274c |\n| Fantom Testnet | FTM | \u2705 |\n| Fuji | AVAX | \u2705 |\n| Goerli | ETH | \u2705 |\n| Linea | ETH | \u274c |\n| Linea Goerli | ETH | \u2705 |\n| Linea Sepolia | ETH | \u2705 |\n| Mumbai | MATIC | \u2705 |\n| opBNB | BNB | \u274c |\n| opBNB Testnet | BNB | \u2705 |\n| Optimism | ETH | \u274c |\n| Optimism Sepolia | ETH | \u2705 |\n| Optimism Goerli | ETH | \u2705 |\n| Polygon | MATIC | \u274c |\n| Sepolia | ETH | \u274c |\n| Scroll | ETH | \u274c |\n| zkSync | ETH | \u274c |\n\nFor specifying network you only need to pass network's name.\n```python\nfrom ether import Wallet\nmy_wallet = Wallet('your_private_key', 'Arbitrum')\n```\n\nIf you use unsupported network, you can specify it using `Network` instance\n```python\nfrom ether import Wallet, Network\n\nnetwork_info = Network(\n name='Custom',\n rpc='wss://custom.publicnode.com',\n token='CUSTOM'\n)\ncustom_wallet = Wallet('your_private_key', network_info)\n```\n\nLibrary supports asynchronous approach\n```python\nfrom ether import AsyncWallet\n\nasync def validate_balance():\n async_wallet = AsyncWallet('your_private_key', 'Arbitrum')\n balance = await async_wallet.get_balance()\n assert balance > 0.1\n```\n \n<h2 id=\"quick-overview\">Quick overview</h2> \nYou can perform the following actions, using ether:\n\n- **[approve](#approve)**\n- **[build_and_transact](#build_and_transact)**\n- **[build_tx_params](#build_tx_params)**\n- **[create](#create)**\n- **[estimate_gas](#estimate_gas)**\n- **[get_balance](#get_balance)**\n- **[get_balance_of](#get_balance_of)**\n- **[get_token](#get_token)**\n- **[get_explorer_url](#get_explorer_url)**\n- **[is_native_token](#is_native_token)**\n- **[transact](#transact)**\n- **[transfer](#transfer)**\n\n<h3 id=\"approve\">approve</h3>\n\nWhen you want to spend non-native tokens, for instance USDT, you need to perform approving operation.\n\n```python\nfrom ether import Wallet\nmy_wallet = Wallet('your_private_key', 'Arbitrum')\nprovider = my_wallet.provider\n\nstargate_router = '0x8731d54E9D02c286767d56ac03e8037C07e01e98'\nusdt = my_wallet.get_token('0xdAC17F958D2ee523a2206206994597C13D831ec7')\nusdt_amount = provider.to_wei(0.001, 'ether')\n\nmy_wallet.approve(usdt, stargate_router, usdt_amount)\n```\n\n<h3 id=\"build_and_transact\">build_and_transact</h3>\nIf you don't need to check estimated gas or directly use transact, you can call build_and_transact. It's based on getting\nclosure as argument. Closure is transaction's function, called with arguments. Notice that it has to be not built or \nawaited\n\n```python\nfrom ether import Wallet\nmy_wallet = Wallet('your_private_key', 'Arbitrum')\nprovider = my_wallet.provider\n\nstargate_abi = [...]\nstargate_router = '0x8731d54E9D02c286767d56ac03e8037C07e01e98'\nstargate = my_wallet.provider.eth.contract(stargate_router, abi=stargate_abi)\n\neth_amount = provider.to_wei(0.001, 'ether')\nclosure = stargate.functions.swapETH(...) \nmy_wallet.build_and_transact(closure, eth_amount)\n```\n\n<h3 id=\"build_tx_params\">build_tx_params</h3>\nYou can use build_tx_params to quickly get dictionary of params for building transaction. Public key, chain id \nand nonce are generated automatically. You also can also choose not to set a gas and the gas price\n\n```python\nfrom ether import Wallet\nmy_wallet = Wallet('your_private_key', 'BSC')\n\nmy_wallet.build_tx_params(0)\n```\n\n```json\n{\n \"from\": \"0xe977Fa8D8AE7D3D6e28c17A868EF04bD301c583f\", \n \"chainId\": 56, \n \"nonce\": 168, \n \"value\": 0, \n \"gas\": 250000, \n \"gasPrice\": 1000000000\n}\n```\n\n<h3 id=\"create\">create</h3>\nYou can use that, when you want to create all-new wallet\n\n```python\nfrom ether import Wallet\nwallet = Wallet.create('Arbitrum')\n```\n \n<h3 id=\"estimate_gas\">estimate_gas</h3>\nWhen you want to estimate an amount of gas to send a transaction, you can use estimate_gas\n\n```python\nfrom ether import Wallet\n\nmy_wallet = Wallet('your_private_key', 'Arbitrum')\nprovider = my_wallet.provider\n\nstargate_router = '0x8731d54E9D02c286767d56ac03e8037C07e01e98'\nstargate_abi = [...]\neth_amount = provider.to_wei(0.001, 'ether')\n\nstargate = my_wallet.provider.eth.contract(stargate_router, abi=stargate_abi)\nparams = my_wallet.build_tx_params(eth_amount)\ntx_params = stargate.functions.swapETH(...).buildTransaction(params)\ngas = my_wallet.estimate_gas(tx_params)\ntx_params['gas'] = gas\n\nmy_wallet.transact(tx_params)\n```\n\n<h3 id=\"get_balance\">get_balance</h3>\nYou can get the balance of the native token of your wallet.\n\n```python\nfrom ether import Wallet\nmy_wallet = Wallet('your_private_key', 'Arbitrum')\nbalance = my_wallet.get_balance()\n```\n\n<h3 id=\"get_balance_of\">get_balance_of</h3>\nYou can get the balance of specified token of your wallet\n\n```python\nfrom ether import Wallet\nmy_wallet = Wallet('your_private_key', 'Arbitrum')\n\nusdt = my_wallet.get_token('0xdAC17F958D2ee523a2206206994597C13D831ec7')\nbalance = my_wallet.get_balance_of(usdt, convert=True)\nprint(balance)\n```\n\n<h3 id=\"get_token\">get_token</h3>\nYou can get the `Token` instance, containing information about symbol and decimals. Also this function used for \nanother instance-methods of Wallet.\n\n```python\nfrom ether import Wallet\nmy_wallet = Wallet('your_private_key', 'Arbitrum')\nusdt = my_wallet.get_token('0xdAC17F958D2ee523a2206206994597C13D831ec7')\nprint(usdt.decimals)\n```\n \n<h3 id=\"get_explorer_url\">get_explorer_url</h3>\nYou can get entire wallet's list of transactions\n\n```python\nfrom ether import Wallet\nfrom web3.contract import Contract\nmy_wallet = Wallet('your_private_key', 'Arbitrum')\nprovider = my_wallet.provider\n\nstargate_router = '0x8731d54E9D02c286767d56ac03e8037C07e01e98'\nstargate_abi = [...]\nstargate = Contract(stargate_router, stargate_abi)\n\neth_amount = provider.to_wei(0.001, 'ether')\nclosure = stargate.functions.swapETH(...) \ntx_hash = my_wallet.build_and_transact(closure, eth_amount)\nprint(my_wallet.get_explorer_url(tx_hash))\n```\n\n<h3 id=\"is_native_token\">is_native_token</h3>\nIf you want to check, if the specific token is native token of network, you can use is_native_token.\n\nYou can use any case in a token's ticker.\n```python\nfrom ether import Wallet\nmy_wallet = Wallet('your_private_key', 'Arbitrum')\nassert my_wallet.is_native_token('eTh')\n```\n\n<h3 id=\"transact\">transact</h3>\nAfter building transaction you can perform it, passing transaction data to transact\n\n```python\nfrom ether import Wallet\n\nmy_wallet = Wallet('your_private_key', 'Arbitrum')\nprovider = my_wallet.provider\n\nstargate_router = '0x8731d54E9D02c286767d56ac03e8037C07e01e98'\nstargate_abi = [...]\neth_amount = provider.to_wei(0.001, 'ether')\n\nstargate = my_wallet.provider.eth.contract(stargate_router, abi=stargate_abi)\nparams = my_wallet.build_tx_params(eth_amount)\ntx_data = stargate.functions.swapETH(...).buildTransaction(params)\ngas = my_wallet.estimate_gas(tx_data)\ntx_data['gas'] = gas\n\nmy_wallet.transact(tx_data)\n```\n\n<h3 id=\"transfer\">transfer</h3>\nYou can transfer tokens to another wallet\n\n```python\nfrom ether import Wallet\nmy_wallet = Wallet('your_private_key', 'Arbitrum')\nprovider = my_wallet.provider\n\nrecipient = '0xe977Fa8D8AE7D3D6e28c17A868EF04bD301c583f'\nusdt = my_wallet.get_token('0xdAC17F958D2ee523a2206206994597C13D831ec7')\nusdt_amount = provider.to_wei(0.001, 'ether')\n\nmy_wallet.transfer(usdt, recipient, usdt_amount)\n```\n\n# Installing ether\n\nTo install the package from PyPi you can use:\n```shell\npip install pyether\n```\n \nTo install the package from GitHub you can use:\n\n```shell\npip install git+https://github.com/CrocoFactory/ether.git\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "The web3.py operation wrapper, offering interaction through Wallet instances.",
"version": "0.2.1",
"project_urls": {
"Homepage": "https://github.com/CrocoFactory/ether",
"Repository": "https://github.com/CrocoFactory/ether"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "83297c1d04b4abb41217ef8f760af39e8291c5b39ec9de62669524f56139a814",
"md5": "330ec909efab6916907181a5d93f3f65",
"sha256": "54463e5da91dfb6078b0d126d507f3a00e625acedd92e41e6548bf44234c0861"
},
"downloads": -1,
"filename": "pyether-0.2.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "330ec909efab6916907181a5d93f3f65",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.9",
"size": 14640,
"upload_time": "2024-09-29T21:11:07",
"upload_time_iso_8601": "2024-09-29T21:11:07.729999Z",
"url": "https://files.pythonhosted.org/packages/83/29/7c1d04b4abb41217ef8f760af39e8291c5b39ec9de62669524f56139a814/pyether-0.2.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "2f28ce811c6c2834a81e7cdd79433d735825e9f68cba486a8966cf3b68e592ac",
"md5": "f5125343712242086d8644e1fe48d971",
"sha256": "e487e7b8a1cac3d5f062930cb92e1766533f0bdb22d4adfc89583710ac56c7ec"
},
"downloads": -1,
"filename": "pyether-0.2.1.tar.gz",
"has_sig": false,
"md5_digest": "f5125343712242086d8644e1fe48d971",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.9",
"size": 12794,
"upload_time": "2024-09-29T21:11:09",
"upload_time_iso_8601": "2024-09-29T21:11:09.207102Z",
"url": "https://files.pythonhosted.org/packages/2f/28/ce811c6c2834a81e7cdd79433d735825e9f68cba486a8966cf3b68e592ac/pyether-0.2.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-29 21:11:09",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "CrocoFactory",
"github_project": "ether",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "pyether"
}