ether-wallet


Nameether-wallet JSON
Version 1.0.0 PyPI version JSON
download
home_pagehttps://github.com/blnkoff/ether-wallet
SummaryThe package, containing wrapper over EVM operations for interacting through Wallet entities.
upload_time2023-11-03 16:25:15
maintainer
docs_urlNone
authorAlexey
requires_python>=3.11
license
keywords ethereum wallet ether wallet
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Ether Wallet

[![Croco Logo](logo.png)](https://t.me/crocofactory)


The package, containing wrapper over EVM operations for interacting through Wallet entities.

- **[Telegram channel](https://t.me/crocofactory)**
- **[Overview](#quick-overview)**
- **[Bug reports](https://github.com/blnkoff/ether-wallet/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
   
Ether Wallet's source code is made available under the [Apache 2.0 license](LICENSE)

##  Quick start
You can quickly use supported networks as RPC:  

| Network         | Native Token | Testnet  |
|-----------------|--------------|----------|
| Arbitrum Goerli | AGOR         | ✅        |
| Arbitrum        | ETH          | ❌        |
| BSC             | BNB          | ❌        |
| tBSC            | tBNB         | ✅        |
| Ethereum        | ETH          | ❌        |
| Goerli          | GETH         | ✅        |
| Sepolia         | SETH         | ❌        |
| Optimism        | ETH          | ❌        |
| Optimism Goerli | OGOR         | ✅        |
| Polygon         | MATIC        | ❌        |
| Mumbai          | MATIC        | ✅        |
| zkSync          | ETH          | ❌        |



For specifying network you only need to pass network's name.
```python
from ether_wallet import Wallet
arb_wallet = Wallet('your_private_key', 'Arbitrum')
```

If you use unsupported network, you can specify it using type NetworkInfo
```python
from ether_wallet import Wallet, NetworkInfo

network_info = NetworkInfo(
    network='Custom',
    rpc='https://custom.publicnode.com',
    token='CUSTOM'
)
custom_wallet = Wallet('your_private_key', network_info)
```

Ether Wallet also asynchronous approach
```python
from ether_wallet 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 Wallet:

- **[approve](#approve)**
- **[build_and_transact](#build_and_transact)**
- **[build_transaction_params](#build_transaction_params)**
- **[create](#create)**
- **[estimate_gas](#estimate_gas)**
- **[get_balance](#get_balance)**
- **[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_wallet import Wallet
arb_wallet = Wallet('your_private_key', 'Arbitrum')
provider = arb_wallet.provider

stargate_router = '0x8731d54E9D02c286767d56ac03e8037C07e01e98'
usdt = '0xdAC17F958D2ee523a2206206994597C13D831ec7'
usdt_amount = provider.to_wei(0.001, 'ether')

arb_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_wallet import Wallet
from web3.contract import Contract
arb_wallet = Wallet('your_private_key', 'Arbitrum')
provider = arb_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(...) 
arb_wallet.build_and_transact(closure, eth_amount)
```

<h3 id="build_transaction_params">build_transaction_params</h3>
You can use build_transaction_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
async def build_transaction_params(
        self,
        value: TokenAmount,
        gas: Optional[int] = None,
        gas_price: Optional[Wei] = None
) -> TxParams:
    """
    Returns transaction's params
    :param value: A quantity of network currency to be paid in Wei units
    :param gas: A quantity of gas to be spent
    :param gas_price: A price of gas in Wei units
    :return: TxParams
    """
    provider = self.provider

    tx_params = {
        'from': self.public_key,
        'chainId': self.__chain_id,
        'nonce': self.nonce,
        'value': value,
        'gas': gas if gas else Wei(250_000),
        'gasPrice': gas_price if gas_price else await provider.eth.gas_price,
    }
    return tx_params
```

<h3 id="create">create</h3>
You can use that, when you want to create all-new wallet

```python
from ether_wallet 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_wallet import Wallet
from web3.contract import Contract
arb_wallet = Wallet('your_private_key', 'Arbitrum')
provider = arb_wallet.provider

stargate_router = '0x8731d54E9D02c286767d56ac03e8037C07e01e98'
stargate_abi = [...]
eth_amount = provider.to_wei(0.001, 'ether')

stargate = Contract(stargate_router, stargate_abi)
params = arb_wallet.build_transaction_params(eth_amount)
tx_data = stargate.functions.swapETH(...).buildTransaction(params)
gas = arb_wallet.estimate_gas(tx_data)
tx_data['gas'] = gas
```

<h3 id="get_balance">get_balance</h3>
You can get the balance of your wallet at any moment.

```python
from ether_wallet import Wallet
arb_wallet = Wallet('your_private_key', 'Arbitrum')
balance = arb_wallet.get_balance()
```

<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_wallet import Wallet
arb_wallet = Wallet('your_private_key', 'Arbitrum')
assert arb_wallet.is_native_token('eTh')
```

Or you can pass zero-address meaning address of network's native token.
```python
from ether_wallet import Wallet, ZERO_ADDRESS
arb_wallet = Wallet('your_private_key', 'Arbitrum')
assert arb_wallet.is_native_token(ZERO_ADDRESS)
```

<h3 id="transact">transact</h3>
After building transaction you can perform it, passing transaction data to transact

```python
from ether_wallet import Wallet
from web3.contract import Contract
arb_wallet = Wallet('your_private_key', 'Arbitrum')
provider = arb_wallet.provider

stargate_router = '0x8731d54E9D02c286767d56ac03e8037C07e01e98'
stargate_abi = [...]
eth_amount = provider.to_wei(0.001, 'ether')

stargate = Contract(stargate_router, stargate_abi)
params = arb_wallet.build_transaction_params(eth_amount)
tx_data = stargate.functions.swapETH(...).buildTransaction(params)
gas = arb_wallet.estimate_gas(tx_data)
tx_data['gas'] = gas

arb_wallet.transact(tx_data)
```

<h3 id="transfer">transfer</h3>
You can transfer tokens to another wallet

```python
from ether_wallet import Wallet
arb_wallet = Wallet('your_private_key', 'Arbitrum')
provider = arb_wallet.provider

recipient = '0xe977Fa8D8AE7D3D6e28c17A868EF04bD301c583f'
usdt = '0xdAC17F958D2ee523a2206206994597C13D831ec7'
usdt_amount = provider.to_wei(0.001, 'ether')

arb_wallet.transfer(usdt, recipient, usdt_amount)
```

# Installing Ether Wallet
        
To install the package from GitHub you can use:

```shell
pip install git+https://github.com/blnkoff/ether-wallet.git
```


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/blnkoff/ether-wallet",
    "name": "ether-wallet",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": "",
    "keywords": "ethereum wallet,ether wallet",
    "author": "Alexey",
    "author_email": "Alexey <abelenkov2006@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/9a/d0/c1d209631aec8dc11ab961f2afb82cb348cc0162a990f887fdafc920130c/ether-wallet-1.0.0.tar.gz",
    "platform": null,
    "description": "# Ether Wallet\n\n[![Croco Logo](logo.png)](https://t.me/crocofactory)\n\n\nThe package, containing wrapper over EVM operations for interacting through Wallet entities.\n\n- **[Telegram channel](https://t.me/crocofactory)**\n- **[Overview](#quick-overview)**\n- **[Bug reports](https://github.com/blnkoff/ether-wallet/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   \nEther Wallet's source code is made available under the [Apache 2.0 license](LICENSE)\n\n##  Quick start\nYou can quickly use supported networks as RPC:  \n\n| Network         | Native Token | Testnet  |\n|-----------------|--------------|----------|\n| Arbitrum Goerli | AGOR         | \u2705        |\n| Arbitrum        | ETH          | \u274c        |\n| BSC             | BNB          | \u274c        |\n| tBSC            | tBNB         | \u2705        |\n| Ethereum        | ETH          | \u274c        |\n| Goerli          | GETH         | \u2705        |\n| Sepolia         | SETH         | \u274c        |\n| Optimism        | ETH          | \u274c        |\n| Optimism Goerli | OGOR         | \u2705        |\n| Polygon         | MATIC        | \u274c        |\n| Mumbai          | MATIC        | \u2705        |\n| zkSync          | ETH          | \u274c        |\n\n\n\nFor specifying network you only need to pass network's name.\n```python\nfrom ether_wallet import Wallet\narb_wallet = Wallet('your_private_key', 'Arbitrum')\n```\n\nIf you use unsupported network, you can specify it using type NetworkInfo\n```python\nfrom ether_wallet import Wallet, NetworkInfo\n\nnetwork_info = NetworkInfo(\n    network='Custom',\n    rpc='https://custom.publicnode.com',\n    token='CUSTOM'\n)\ncustom_wallet = Wallet('your_private_key', network_info)\n```\n\nEther Wallet also asynchronous approach\n```python\nfrom ether_wallet 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 Wallet:\n\n- **[approve](#approve)**\n- **[build_and_transact](#build_and_transact)**\n- **[build_transaction_params](#build_transaction_params)**\n- **[create](#create)**\n- **[estimate_gas](#estimate_gas)**\n- **[get_balance](#get_balance)**\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```python\nfrom ether_wallet import Wallet\narb_wallet = Wallet('your_private_key', 'Arbitrum')\nprovider = arb_wallet.provider\n\nstargate_router = '0x8731d54E9D02c286767d56ac03e8037C07e01e98'\nusdt = '0xdAC17F958D2ee523a2206206994597C13D831ec7'\nusdt_amount = provider.to_wei(0.001, 'ether')\n\narb_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_wallet import Wallet\nfrom web3.contract import Contract\narb_wallet = Wallet('your_private_key', 'Arbitrum')\nprovider = arb_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(...) \narb_wallet.build_and_transact(closure, eth_amount)\n```\n\n<h3 id=\"build_transaction_params\">build_transaction_params</h3>\nYou can use build_transaction_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\nasync def build_transaction_params(\n        self,\n        value: TokenAmount,\n        gas: Optional[int] = None,\n        gas_price: Optional[Wei] = None\n) -> TxParams:\n    \"\"\"\n    Returns transaction's params\n    :param value: A quantity of network currency to be paid in Wei units\n    :param gas: A quantity of gas to be spent\n    :param gas_price: A price of gas in Wei units\n    :return: TxParams\n    \"\"\"\n    provider = self.provider\n\n    tx_params = {\n        'from': self.public_key,\n        'chainId': self.__chain_id,\n        'nonce': self.nonce,\n        'value': value,\n        'gas': gas if gas else Wei(250_000),\n        'gasPrice': gas_price if gas_price else await provider.eth.gas_price,\n    }\n    return tx_params\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_wallet 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_wallet import Wallet\nfrom web3.contract import Contract\narb_wallet = Wallet('your_private_key', 'Arbitrum')\nprovider = arb_wallet.provider\n\nstargate_router = '0x8731d54E9D02c286767d56ac03e8037C07e01e98'\nstargate_abi = [...]\neth_amount = provider.to_wei(0.001, 'ether')\n\nstargate = Contract(stargate_router, stargate_abi)\nparams = arb_wallet.build_transaction_params(eth_amount)\ntx_data = stargate.functions.swapETH(...).buildTransaction(params)\ngas = arb_wallet.estimate_gas(tx_data)\ntx_data['gas'] = gas\n```\n\n<h3 id=\"get_balance\">get_balance</h3>\nYou can get the balance of your wallet at any moment.\n\n```python\nfrom ether_wallet import Wallet\narb_wallet = Wallet('your_private_key', 'Arbitrum')\nbalance = arb_wallet.get_balance()\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_wallet import Wallet\narb_wallet = Wallet('your_private_key', 'Arbitrum')\nassert arb_wallet.is_native_token('eTh')\n```\n\nOr you can pass zero-address meaning address of network's native token.\n```python\nfrom ether_wallet import Wallet, ZERO_ADDRESS\narb_wallet = Wallet('your_private_key', 'Arbitrum')\nassert arb_wallet.is_native_token(ZERO_ADDRESS)\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_wallet import Wallet\nfrom web3.contract import Contract\narb_wallet = Wallet('your_private_key', 'Arbitrum')\nprovider = arb_wallet.provider\n\nstargate_router = '0x8731d54E9D02c286767d56ac03e8037C07e01e98'\nstargate_abi = [...]\neth_amount = provider.to_wei(0.001, 'ether')\n\nstargate = Contract(stargate_router, stargate_abi)\nparams = arb_wallet.build_transaction_params(eth_amount)\ntx_data = stargate.functions.swapETH(...).buildTransaction(params)\ngas = arb_wallet.estimate_gas(tx_data)\ntx_data['gas'] = gas\n\narb_wallet.transact(tx_data)\n```\n\n<h3 id=\"transfer\">transfer</h3>\nYou can transfer tokens to another wallet\n\n```python\nfrom ether_wallet import Wallet\narb_wallet = Wallet('your_private_key', 'Arbitrum')\nprovider = arb_wallet.provider\n\nrecipient = '0xe977Fa8D8AE7D3D6e28c17A868EF04bD301c583f'\nusdt = '0xdAC17F958D2ee523a2206206994597C13D831ec7'\nusdt_amount = provider.to_wei(0.001, 'ether')\n\narb_wallet.transfer(usdt, recipient, usdt_amount)\n```\n\n# Installing Ether Wallet\n        \nTo install the package from GitHub you can use:\n\n```shell\npip install git+https://github.com/blnkoff/ether-wallet.git\n```\n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "The package, containing wrapper over EVM operations for interacting through Wallet entities.",
    "version": "1.0.0",
    "project_urls": {
        "Homepage": "https://github.com/blnkoff/ether-wallet",
        "source": "https://github.com/blnkoff/ether-wallet"
    },
    "split_keywords": [
        "ethereum wallet",
        "ether wallet"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "08de8c65f48c86a281eb8e9f15ef6ba13b19ac5d60ccde44f6c5a19b55ecab44",
                "md5": "41fbe07d37b897cce484f37bfc2b7b82",
                "sha256": "0680f7af48d9952bbc2904970dcdbb03e4acfd13e465eafb1c7517aa7507997a"
            },
            "downloads": -1,
            "filename": "ether_wallet-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "41fbe07d37b897cce484f37bfc2b7b82",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 13823,
            "upload_time": "2023-11-03T16:25:13",
            "upload_time_iso_8601": "2023-11-03T16:25:13.015462Z",
            "url": "https://files.pythonhosted.org/packages/08/de/8c65f48c86a281eb8e9f15ef6ba13b19ac5d60ccde44f6c5a19b55ecab44/ether_wallet-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9ad0c1d209631aec8dc11ab961f2afb82cb348cc0162a990f887fdafc920130c",
                "md5": "98526748f2d02e6c2ea3e51795afb459",
                "sha256": "2f60e895c86594f1f0e83416bdc57b8b00f281e0a3e408628a63e3d413f79736"
            },
            "downloads": -1,
            "filename": "ether-wallet-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "98526748f2d02e6c2ea3e51795afb459",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 15397,
            "upload_time": "2023-11-03T16:25:15",
            "upload_time_iso_8601": "2023-11-03T16:25:15.056226Z",
            "url": "https://files.pythonhosted.org/packages/9a/d0/c1d209631aec8dc11ab961f2afb82cb348cc0162a990f887fdafc920130c/ether-wallet-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-03 16:25:15",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "blnkoff",
    "github_project": "ether-wallet",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "ether-wallet"
}
        
Elapsed time: 0.67458s