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
The project is made by the Croco Factory team
evm-wallet's source code is made available under the MIT License
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.
from evm_wallet import Wallet
my_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='wss://custom.publicnode.com',
token='CUSTOM'
)
custom_wallet = Wallet('your_private_key', network_info)
Library supports 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
- approve
- build_and_transact
- build_tx_params
- create
- estimate_gas
- get_balance
- get_balance_of
- get_token
- get_explorer_url
- is_native_token
- transact
- transfer
When you want to spend non-native tokens, for instance USDT, you need to perform approving operation.
from evm_wallet 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)
from evm_wallet 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)
from evm_wallet import Wallet
my_wallet = Wallet('your_private_key', 'BSC')
my_wallet.build_tx_params(0)
{
"from": "0xe977Fa8D8AE7D3D6e28c17A868EF04bD301c583f",
"chainId": 56,
"nonce": 168,
"value": 0,
"gas": 250000,
"gasPrice": 1000000000
}
from evm_wallet import Wallet
wallet = Wallet.create('Arbitrum')
from evm_wallet 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)
from evm_wallet import Wallet
my_wallet = Wallet('your_private_key', 'Arbitrum')
balance = my_wallet.get_balance()
from evm_wallet 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)
from evm_wallet import Wallet
my_wallet = Wallet('your_private_key', 'Arbitrum')
usdt = my_wallet.get_token('0xdAC17F958D2ee523a2206206994597C13D831ec7')
print(usdt.decimals)
from evm_wallet 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))
You can use any case in a token's ticker.
from evm_wallet import Wallet
my_wallet = Wallet('your_private_key', 'Arbitrum')
assert my_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
my_wallet = Wallet('your_private_key', 'Arbitrum')
assert my_wallet.is_native_token(ZERO_ADDRESS)
from evm_wallet import Wallet
from web3.contract import Contract
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)
from evm_wallet 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)
To install the package from PyPi you can use:
pip install evm-wallet
To install the package from GitHub you can use:
pip install git+https://github.com/CrocoFactory/evm-wallet.git