Skip to main content

Batteries-included client to interact with blockchains and smart contracts

Project description

Batteries-included client to interact with blockchains and smart contracts; used by web3cli and crabada.py.

Features

  • Easily create a client to interact with EVM-compatible chains
  • Interact with the most popular chains: Ethereum, Binance, Avalanche, Arbitrum One, zkSync Era, and more to come!
  • Subscribe to pending transactions in the mempool and new blocks.
  • Save gas by setting an upper limit on the base fee.
  • Need more flexibility? Use directly the underlying web3.py client.
  • Perform ERC20 operations, using the token name (e.g. USDC) instead of address.

Install

pip3 install -U web3client

Examples

Get the latest block on supported blockchains:

from web3factory.factory import make_client

eth_block = make_client("eth").get_latest_block() # Ethereum
bnb_block = make_client("bnb").get_latest_block() # BNB chain
avax_block = make_client("avax").get_latest_block() # Avalanche
arb_block = make_client("arb").get_latest_block() # Arbitrum
era_block = make_client("era").get_latest_block() # zkSync Era

Get the ETH and USDC balances of the Ethereum foundation:

from web3factory.factory import make_client, make_erc20_client

address = "0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae"
eth = make_client("eth").get_balance_in_eth(address)
usdc = make_erc20_client("USDC", "eth").balanceOf(address) / 10**6

Get the BNB and BUSD balances of Binance's hot wallet:

from web3factory.factory import make_client, make_erc20_client

address = "0x8894e0a0c962cb723c1976a4421c95949be2d4e3"
bnb = make_client("bnb").get_balance_in_eth(address)
busd = make_erc20_client("BUSD", "bnb").balanceOf(address) / 10**18

More examples

Please have a look at the tests folder or at the examples folder 🙂

Custom chains & contracts

The factory module only allows to interact with a small list of chains and contracts.

To interact with an arbitrary EVM chain or smart contract, instantiate a custom client using the BaseClient class.

For a more structured approach, use web3core, a sub-package of web3cli that comes with many preloaded chains, and allows to import chains and smart contracts dynamically.

It doesn't work 😡

Don't panic! Instead...

  1. Please check if your issue is listed in the Issues tab.
  2. If not, consider writing a new issue 🙂

Contributing

All contributions are welcome! To start improving web3client, please refer to our contribution guide.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

web3client-1.1.13.tar.gz (28.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

web3client-1.1.13-py3-none-any.whl (21.8 kB view details)

Uploaded Python 3

File details

Details for the file web3client-1.1.13.tar.gz.

File metadata

  • Download URL: web3client-1.1.13.tar.gz
  • Upload date:
  • Size: 28.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.7.0 CPython/3.10.9

File hashes

Hashes for web3client-1.1.13.tar.gz
Algorithm Hash digest
SHA256 dabae23a42fc997f3790f14359a9465251cd3dbd421853e6550000f598777a67
MD5 7168e7c57b5e7f68e4726f08144134d5
BLAKE2b-256 acd8febea3c64fb22c747f0c709e26537539ff50c5f803caae4ed53394c07c64

See more details on using hashes here.

File details

Details for the file web3client-1.1.13-py3-none-any.whl.

File metadata

  • Download URL: web3client-1.1.13-py3-none-any.whl
  • Upload date:
  • Size: 21.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.7.0 CPython/3.10.9

File hashes

Hashes for web3client-1.1.13-py3-none-any.whl
Algorithm Hash digest
SHA256 ca208ac3b2509a8a4dd0b7a9eb5a80e572d6921482c27aedca466580b6faf8d0
MD5 6e5c33f263849e2da855f776f29b52a7
BLAKE2b-256 47e9e6ea9c9abddf8157ba55b38b4c61281e202a7d4426385f0dec963c352fb2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page