The package, containing wrapper over EVM operations for interacting through Wallet entities
Project description
evm-wallet
The package, containing wrapper over EVM operations for interacting through Wallet entities.
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
evm-wallet's source code is made available under the MIT License
Quick start
You can quickly use supported networks as RPC:
Network | Native Token | Testnet |
---|---|---|
Arbitrum Goerli | AGOR | ✅ |
Arbitrum | ETH | ❌ |
Avalanche | AVAX | ❌ |
Base | ETH | ❌ |
Base Goerli | ETH | ✅ |
BSC | BNB | ❌ |
BSC Testnet | tBNB | ✅ |
Ethereum | ETH | ❌ |
Fantom | FTM | ❌ |
Fantom Testnet | FTM | ✅ |
Fuji | AVAX | ✅ |
Goerli | GETH | ✅ |
Linea | ETH | ❌ |
Linea Goerli | ETH | ✅ |
Mumbai | MATIC | ✅ |
opBNB | BNB | ❌ |
opBNB Testnet | BNB | ✅ |
Optimism | ETH | ❌ |
Optimism Goerli | OGOR | ✅ |
Polygon | MATIC | ❌ |
Sepolia | SETH | ❌ |
zkSync | ETH | ❌ |
For specifying network you only need to pass network's name.
from evm_wallet import Wallet
arb_wallet = Wallet('your_private_key', 'Arbitrum')
If you use unsupported network, you can specify it using type NetworkInfo
from evm_wallet import Wallet, NetworkInfo
network_info = NetworkInfo(
network='Custom',
rpc='https://custom.publicnode.com',
token='CUSTOM'
)
custom_wallet = Wallet('your_private_key', network_info)
evm-wallet also asynchronous approach
from evm_wallet import AsyncWallet
async def validate_balance():
async_wallet = AsyncWallet('your_private_key', 'Arbitrum')
balance = await async_wallet.get_balance()
assert balance > 0.1
Quick overview
You can perform the following actions, using evm-wallet:- approve
- build_and_transact
- build_transaction_params
- create
- estimate_gas
- get_balance
- get_explorer_url
- get_transactions
- is_native_token
- transact
- transfer
approve
When you want to spend non-native tokens, for instance USDT, you need to perform approving operation.
from evm_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)
build_and_transact
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 awaitedfrom evm_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)
build_transaction_params
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 priceasync 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
create
You can use that, when you want to create all-new walletfrom evm_wallet import Wallet
wallet = Wallet.create('Arbitrum')
estimate_gas
When you want to estimate an amount of gas to send a transaction, you can use estimate_gasfrom evm_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
get_balance
You can get the balance of your wallet at any moment.from evm_wallet import Wallet
arb_wallet = Wallet('your_private_key', 'Arbitrum')
balance = arb_wallet.get_balance()
get_explorer_url
You can get entire wallet's list of transactionsfrom evm_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(...)
tx_hash = arb_wallet.build_and_transact(closure, eth_amount)
print(arb_wallet.get_explorer_url(tx_hash))
get_transactions
You can get entire wallet's list of transactionsfrom evm_wallet import Wallet
arb_wallet = Wallet('your_private_key', 'Arbitrum')
transactions = arb_wallet.get_transactions()
is_native_token
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.
from evm_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.
from evm_wallet import Wallet, ZERO_ADDRESS
arb_wallet = Wallet('your_private_key', 'Arbitrum')
assert arb_wallet.is_native_token(ZERO_ADDRESS)
transact
After building transaction you can perform it, passing transaction data to transactfrom evm_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)
transfer
You can transfer tokens to another walletfrom evm_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 evm-wallet
To install the package from GitHub you can use:
pip install git+https://github.com/blnkoff/evm-wallet.git
To install the package from PyPi you can use:
pip install evm-wallet
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file evm_wallet-1.0.6.tar.gz
.
File metadata
- Download URL: evm_wallet-1.0.6.tar.gz
- Upload date:
- Size: 11.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a188cf8e21ef46813d512f6c3935d862779ebe9f22e7c3b3f162de652a37842f |
|
MD5 | d4a7d9857511f3fc156da0893437e52c |
|
BLAKE2b-256 | 62bff79c1cc601689f2f129418d801904e7bdb5faebc24ee14a02429c9d0a9d0 |
File details
Details for the file evm_wallet-1.0.6-py3-none-any.whl
.
File metadata
- Download URL: evm_wallet-1.0.6-py3-none-any.whl
- Upload date:
- Size: 11.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7bf932324adb512e5cade385ad752f5186dcf873d42e24ab6d6060660441b64c |
|
MD5 | a465949b06982ba01a3234c3228b0235 |
|
BLAKE2b-256 | bc612b0000cdc97bc2d93b04b4569d4f420c1ae72f40531ba6b8da3bc124d136 |