Questions tagged [web3py]

Web3.py is a library for interacting with EVM based blockchains and smart contracts in Python.

For more information see Web3.py documentation.

Web3.py is maintained by Ethereum Foundation.

578 questions
6
votes
1 answer

How to calculate Uniswap v3 pool's Total Value Locked (TVL) on chain?

I want to calculate the total value locked in a particular pool in Uniswap v3. I can't use the subgraph API for this. I can get current liquidity / in range liquidity using uniswapV3pool contract function: in_range_liquidity =…
AtiqGauri
  • 1,483
  • 13
  • 26
6
votes
1 answer

Difference between sendTransaction and sendRawTransaction in web3.py

What are the practical differences between these web3.py methods for sending a transaction? w3.eth.sendTransaction({}) w3.eth.sendRawTransaction(signed_txn.rawTransaction)
TimRicta
  • 135
  • 1
  • 2
  • 8
5
votes
3 answers

cytoolz/dicttoolz.c:19:10: fatal error: Python.h: No such file or directory

cytoolz/dicttoolz.c:19:10: fatal error: Python.h: No such file or directory 19 | #include "Python.h" | ^~~~~~~~~~ compilation terminated. error: command 'gcc' failed with exit status 1 …
t_k
  • 121
  • 2
  • 8
5
votes
0 answers

Decode input data for a contract creation transaction

So I have successfully used the function decode_function_input(txn.input) to decode the input data for most transactions except for contract creation input data. Is there a simple and straightforward way to achieve this for contract creation using…
BJonas88
  • 283
  • 4
  • 15
5
votes
1 answer

How to use AsyncHTTPProvider in web3py?

I am trying to use the AsyncHTTPProvider in a project, and here is my test code: import asyncio from web3 import Web3 import asyncio async def main(): w3 = Web3(Web3.AsyncHTTPProvider("http://127.0.0.1:8545")) coinbase = await…
Ramgos
  • 181
  • 1
  • 6
5
votes
1 answer

Check if wallet is approved to spend token

I was wondering if there's a way to check if a token is already approved for spending. I'm not asking how to approve the token for spending, I've figured that part out via reference: How to approve a token for spending on (Uniswap router contract).…
BJonas88
  • 283
  • 4
  • 15
5
votes
1 answer

How can I swap BNB into another crypto currency using web3?

I would like to use web3 to exchange BNB into other tokens via Pancakeswap, so I came across this code which seems to be correct: import time import config as config from web3 import Web3 PancakeABI =…
5
votes
1 answer

How to approve a token for spending on (Uniswap router contract)

Im trying to approve and later on swap my tokens on uniswap via web3py code. I am also using infura, not my own node. However, on both the swap and the approve I run into solidityErrors. The problem is that web3 does not recognize my account even…
randoTrack
  • 83
  • 1
  • 3
  • 6
5
votes
1 answer

Listening to Uniswap contract events using web3.py and infura.io

I want to use web3.py and infura.io to listen for Uniswap factory events however I am not too sure where to go about doing so. Here is a link: https://uniswap.org/docs/v2/smart-contracts/factory/ More specifically I want to listen for the…
creed
  • 1,409
  • 1
  • 9
  • 18
5
votes
2 answers

Error passing string as parameter (Solidity)

I did a smart contract to vote, but I a, having troubles with one of my functions ("results"). Here comes the smart contract: pragma solidity ^0.5.7; contract Voting{ struct Option{ string name; uint256 votes; } …
4
votes
1 answer

Ethereum raw contract interaction using web3 python

I'm looking for an example of a raw json/body of a contract interaction before it is signed and passed to web3py / web3js / ethers We are using AWS KMS for our wallet setup. There are some automated actions that this wallet is supposed to take. The…
Benzy
  • 855
  • 7
  • 16
4
votes
3 answers

What's the efficient way to acess the BSC node mempool content?

I'm currently writing some program to monitor the mempool of a bsc node. As my BSC node is a charged by request count, I'm trying to explore the best way to save the time and cost. Here's some plan I found: Use service of mempool explorer.…
Yu Wan
  • 63
  • 2
  • 5
4
votes
4 answers

PYPY venv pip ERROR: ModuleNotFoundError: No module named 'pip._vendor.six'

I created venv according to pypy install site: System-Product-Name:~# virtualenv -p "/home/x/pypy3.8-v7.3.7-linux64/bin/pypy" ve created virtual environment PyPy3.8.12.final.0-64 in 102ms Success. Following step 2 (activation) worked as well...…
t_k
  • 121
  • 2
  • 8
4
votes
1 answer

Sending entire Ethereum address balance in post EIP-1559 world

I'm trying to figure out how to send an entire address balance in a post EIP-1559 transaction (essentially emptying the wallet). Before the London fork, I could get the actual value as Total balance - (gasPrice * gas), but now it's impossible to…
Proto Ukr
  • 492
  • 4
  • 13
4
votes
1 answer

Get Avalanche block data by block hash with web3.py

How do I get block data by block hash? I'm interested in getting block timestamp for each new block. from web3 import Web3 avalanche_url = 'https://api.avax.network/ext/bc/C/rpc' provider = Web3(Web3.HTTPProvider(avalanche_url)) new_block_filter =…
MikkoP
  • 4,864
  • 16
  • 58
  • 106
1
2
3
38 39