Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Whynot63/web3-premium
Data Science friendly wrapper for web3py
https://github.com/Whynot63/web3-premium
Last synced: about 2 months ago
JSON representation
Data Science friendly wrapper for web3py
- Host: GitHub
- URL: https://github.com/Whynot63/web3-premium
- Owner: Whynot63
- License: mit
- Created: 2022-08-01T09:34:12.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-11-22T15:08:16.000Z (about 1 year ago)
- Last Synced: 2024-06-04T18:38:23.537Z (7 months ago)
- Language: Python
- Size: 28.3 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- On-Chain-Investigations-Tools-List - Smart Contract Wrapper
README
# web3-premium
Data Science friendly wrapper for web3py## Installation
```
python3 -m pip install web3_premium
```## Explorers wrapper
Usage: `..()`
List of modules and module actions you can get from explorer documentation (etherscan, for example: https://docs.etherscan.io/api-endpoints/accounts)```python
import timefrom web3_premium.explorer import etherscan
timestamp = int(time.time())
etherscan.block.getblocknobytime(timestamp=timestamp, closest="before")
```You can also add new explorer, which support etherscan/blockscout api format, for example:
```python
import timefrom web3_premium.explorer import Explorer
timestamp = int(time.time())
andromeda = Explorer("https://andromeda-explorer.metis.io/api")
andromeda.block.getblocknobytime(timestamp=timestamp, closest="before")
```## Web3 smart contracts wrapper
Basic example with pure web3:
```python
# We wanna to know, how many USDT at ethereum holds zero address (0x00000....) at 01.08.2022 (block 15253306)
from web3 import Web3BLOCK = 15253306
w3 = Web3(Web3.HTTPProvider("https://rpc.ankr.com/eth"))
usdt_abi = ... # some big json
usdt = w3.eth.contract(
Web3.toChecksumAddress("0xdaC17F958D2ee523a2206206994597C13D831ec7"), abi=usdt_abi
)
burnedUsdt = usdt.functions.balanceOf(
"0x0000000000000000000000000000000000000000"
).call(block_identifier=BLOCK)
```With web3-premium:
```python
# We wanna to know, how many USDT at ethereum holds zero address (0x00000....) at 01.08.2022 (block 15253306)
from web3_premium.chains import ethereum
from web3_premium.contract import ContractBLOCK = 15253306
usdt = Contract("0xdaC17F958D2ee523a2206206994597C13D831ec7", ethereum)
burnedUsdt = usdt.balanceOf("0x0000000000000000000000000000000000000000", block=BLOCK)
```## Custom node for predefined chains
You can set env variable for overriding default rpc (ankr). For example, for ethereum you should set `ETHEREUM_RPC=infura.com/....`