web3-starter-py/web3-toolkit
2023-03-12 16:29:56 -07:00
..
abis 💾 2023-03-12 15:32:23 -07:00
scripts add quick tx scraper script 2023-03-12 16:29:56 -07:00
.env.example add quick tx scraper script 2023-03-12 16:29:56 -07:00
Makefile 💾 2023-03-12 15:32:23 -07:00
poetry.lock 💾 2023-03-12 15:32:23 -07:00
pyproject.toml 💾 2023-03-12 15:32:23 -07:00
README.md add quick tx scraper script 2023-03-12 16:29:56 -07:00

📚 web3-python-toolkit


👉 on-going development of a library and set of python scripts with my fav on-chain ops.



setting up

we use poetry to setup this package (config details at pyproject.toml).

installing:

brew install poetry
make install
cp .env.example .env
vim .env


scripts


get contracts deployed to mainnet and testnets

we leverage ethereumetl to extract this data.

  1. add info to .env
  2. run
cd scripts
poetry run python  get_contracts_deployed.py
  1. any output is saved to data/.

get reserve history by block for a pair of addresses

  1. add the pair abi to abis/
  2. run
cd scripts
poetry run python get_reserve_history_by_block.py

get deep block data

  1. add info to .env
  2. run
cd scripts
poetry run python get_deep_block_data.py

decode calldata

  1. add info to .env
  2. run
cd scripts
poetry run python decode_calldata.py

get token transfer events logs and wallet balances

  1. add info to .env
  2. run
cd scripts
poetry run python get_transfer_logs_and_wallets_balance_for_a_token.py

scrape transfer events for token data

  1. add info to .env
  2. run
cd scripts
poetry run python scrape_transfer_events.py


troubleshoot


if you see ethereum-etl not compatible to m1 run:
pip uninstall ethereum-etl 
pip install --no-binary ethereum-etl 


resources



relevant info


providers
  • providers are how libraries such as web3.py talk to the blockchain.
  • providers take JSON-RPC requests and return responses
  • the most common ways to connect to your node are:
    • IPC (uses local filesystem, fastest and most secure)
    • Websockets (works remotely, faster than HTTP)
    • HTTP (more nodes support it)

middleware
  • a web3.py instance can be configured via middleware (sitting between the web3 methods and the provider).
  • middlewares use an onion metaphor: each layer may affect both the request and response from the provider.
  • each middleware layer gets invoked before the request reaches the provider, and then processes the result after the provider returns, in reverse order.
  • we often use geth_poa_middleware, to run with geth's Proof-of-Authority (PoA) consensus. this adds support for more than 32 bytes in each block (the extraData field).