Useful web3 constant
Project description
web3-constant
Install
pip install web3-constant
Connect to Web3
from web3 import Web3
from web3constant.Fantom.Url import FTM_RPC
w3 = Web3(Web3.HTTPProvider(FTM_RPC))
if w3.isConnected():
print("Web3 is connected.")
Listen to a topic
from web3 import Web3
from web3constant.Fantom.Url import FTM_RPC
from web3constant.topics import PAIR_SYNC
w3 = Web3(Web3.HTTPProvider(FTM_RPC))
prev_block_num = w3.eth.get_block_number()
while(True):
current_block = w3.eth.get_block_number()
if (prev_block_num == current_block):
continue
topic_d = {
'fromBlock': prev_block_num,
'topics': [PAIR_SYNC]
}
logs = w3.eth.get_logs(topic_d)
for l in logs:
print(l)
Create contract
from web3 import Web3
from web3constant.Fantom.Url import FTM_RPC
from web3constant.Fantom.Dex import SPOOKY_SWAP_FACTORY_ADDRESS
from web3constant.abi.UniswapV2 import SPOOKY_SWAP_FACTORY_ABI, UNISWAP_V2_PAIR_ABI
w3 = Web3(Web3.HTTPProvider(FTM_RPC))
# create factory contract
spooky_swap_factory_contract = w3.eth.contract(
address=SPOOKY_SWAP_FACTORY_ADDRESS, abi=SPOOKY_SWAP_FACTORY_ABI
)
# get pair address for factory contract
pair_address = spooky_swap_factory_contract.functions.allPairs(0).call()
print("pair contract address:", pair_address)
# create pair contract
pair_contract = w3.eth.contract(address=pair_address, abi=UNISWAP_V2_PAIR_ABI)
# get token0, token1
token0 = pair_contract.functions.token0().call()
token1 = pair_contract.functions.token1().call()
# get reserves
r0, r1, timestamp = pair_contract.functions.getReserves().call()
# print
print("token0:", token0)
print("token0 reserves:", r0)
print("token1:", token1)
print("token1 reserves:", r1)
print("sync timestamp:", timestamp)
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
web3-constant-0.0.6.tar.gz
(4.5 kB
view details)
Built Distribution
File details
Details for the file web3-constant-0.0.6.tar.gz
.
File metadata
- Download URL: web3-constant-0.0.6.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 63c4d78c2f399711a23c01d9dfc1f81706e2d4db9851bed1fe45a883bf597f95 |
|
MD5 | 869755c42f41d27a2aab68ac8afe99e1 |
|
BLAKE2b-256 | 5e782c8dbc2dc63c97d81c208ef66613b6cc746adf7e4f93c40930b6473cd8cb |
File details
Details for the file web3_constant-0.0.6-py3-none-any.whl
.
File metadata
- Download URL: web3_constant-0.0.6-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3820273585eb26c6187b72e85e1018b74b4e735cd003ed01bc5139bad571275b |
|
MD5 | 71bf34853bd0feeac0689abd0fc5a26b |
|
BLAKE2b-256 | 3ab18cbdc812b89e569e558b262480e896ffcd8216296841c8d49e0b46468830 |