web3.py | python interface for interacting with the Ethereum | Cryptocurrency library

 by   ethereum Python Version: v3.11.1 License: MIT

kandi X-RAY | web3.py Summary

kandi X-RAY | web3.py Summary

web3.py is a Python library typically used in Blockchain, Cryptocurrency, Ethereum applications. web3.py has no bugs, it has no vulnerabilities, it has build file available, it has a Permissive License and it has medium support. You can install using 'pip install web3.py' or download it from GitHub, PyPI.

A Python library for interacting with Ethereum, inspired by web3.js.

            kandi-support Support

              web3.py has a medium active ecosystem.
              It has 4289 star(s) with 1514 fork(s). There are 117 watchers for this library.
              It had no major release in the last 12 months.
              There are 203 open issues and 1130 have been closed. On average issues are closed in 165 days. There are 33 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of web3.py is v3.11.1

            kandi-Quality Quality

              web3.py has 0 bugs and 0 code smells.

            kandi-Security Security

              web3.py has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              web3.py code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              web3.py is licensed under the MIT License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              web3.py releases are available to install and integrate.
              Deployable package is available in PyPI.
              Build file is available. You can build the component from source.
              Installation instructions are available. Examples and code snippets are not available.
              web3.py saves you 3211 person hours of effort in developing the same functionality from scratch.
              It has 6902 lines of code, 630 functions and 150 files.
              It has high code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi has reviewed web3.py and discovered the below as its top functions. This is intended to give you an instant insight into web3.py implemented functionality, and help decide if they suit your requirements.
            • Get event logs
            • Find an event that matches the ABI
            • Construct the filter parameters for an event
            • Construct filter params
            • Creates a middleware that returns the latest block - based cache
            • Generate a cache key for the given value
            • Check if the given method is a valid block number
            • Handle an OffchainLookup payload
            • Replace old key with new name
            • Sets the value of a key
            • Return a gas price strategy
            • Return an async contract factory
            • Create a local filter middleware
            • Constructs a middleware middleware for a given method
            • Set the value of a key
            • Fill default values for transaction defaults
            • Returns a Dependencies instance
            • Returns ipc
            • Insert an element into the queue
            • Returns a dict containing the deployed deployments
            • Create a Contracting checking factory
            • Setup a new name
            • Create a new name
            • Call the contract function
            • Calls the contract function
            • Constructs a middleware that returns a middleware that can be used to cache requests
            Get all kandi verified functions for this library.

            web3.py Key Features

            No Key Features are available at this moment for web3.py.

            web3.py Examples and Code Snippets

            Python usage,ERC-20 token example
            Pythondot img1Lines of Code : 60dot img1no licencesLicense : No License
            copy iconCopy
            import pytest
            from web3 import Web3, EthereumTesterProvider
            from eth_hentai.token import create_token
            def tester_provider():
                return EthereumTesterProvider()
            def eth_tester(tester_provider):
                return tester_p  
            Pythondot img2Lines of Code : 28dot img2License : Weak Copyleft (LGPL-3.0)
            copy iconCopy
            import json
            from solc import compile_source
            from web3 import Web3, HTTPProvider
            fr = open('CommunityController.sol')
            contract_source_code = fr.read()
            compiled_sol = compile_source(contract_source_code)
            contract_interface = compiled_sol['  
            Pythondot img3Lines of Code : 15dot img3License : Strong Copyleft (AGPL-3.0)
            copy iconCopy
            from skale import SkaleManager
            from skale.wallets import Web3Wallet
            from skale.utils.web3_utils import init_web3
            web3 = init_web3(ENDPOINT)
            wallet = Web3Wallet(private_key, web3)
            skale = Skale(ENDPOINT, ABI_FILEPATH, wallet)
            from skale import Skale  
            python sintax problem for solidity compilator
            Pythondot img4Lines of Code : 2dot img4License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            Compute the LP Address of a token pair using web3.py
            Pythondot img5Lines of Code : 9dot img5License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            pair_traded = [token_a, token_b] #token_a, token_b are the address's
            hexadem_1 = 0xff
            abiEncoded_1 = encode_abi_packed(['address', 'address'], (token_list[0], token_list[1] ))
            salt_ = w3.solidityKeccak(['bytes'], ['0x' 
            PIP failed to build package cytoolz
            Pythondot img6Lines of Code : 4dot img6License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            python -m pip install --user cython
            python -m pip install --user cytoolz
            python -m pip install --user eth-brownie
            PYPY venv pip ERROR: ModuleNotFoundError: No module named 'pip._vendor.six'
            Pythondot img7Lines of Code : 3dot img7License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            pypy3 -m venv /tmp/venv
            source /tmp/venv/bin/activate
            The transaction declared chain ID 5777, but the connected node is on 1337
            Pythondot img8Lines of Code : 9dot img8License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            transaction = 
             SimpleStorage.constructor().buildTransaction( {
                "gasPrice": w3.eth.gas_price, 
                "chainId": chain_id, 
                "from": my_address, 
                "nonce": nonce, 
            KeyError: 'name' abi error on web3 Python
            Pythondot img9Lines of Code : 10dot img9License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            def filter_by_name(name: str, contract_abi: ABI) -> List[Union[ABIFunction, ABIEvent]]:
                for abi in contract_abi:
                # ... rest ...
            {'stateMutability': 'payable', 't
            How to filter for ethereum address
            Pythondot img10Lines of Code : 25dot img10License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            async function checkBlock(address) {
                const block = await web3.eth.getBlock('latest');
                console.log(`Checking new block ${block.number}`);
                for (let txHash of block.transactions) {
                    const tx = await web3.eth.getTransaction

            Community Discussions


            Trying to run "brownie run .\scripts\deploy.py --network rinkeby" but getting a ValueError
            Asked 2022-Mar-01 at 18:15

            Hey guys I am trying to deploy my project on the rinkeby chain using infura, but I am getting a ValueError Here is my trackback:



            Answered 2021-Nov-28 at 10:14

            it appears your env variables are not set correctly, and it looks like in this case it's your WEB3_INFURA_PROJECT_ID.

            You can fix it by setting the variable in your .env file and adding dotenv: .env to your brownie-config.yaml.


            dotenv: .env .env:

            export WEB3_INFURA_PROJECT_ID=YOUR_PROJECT_ID_HERE Remember to save these files.

            Additionally, you should be on at least brownie version v1.14.6. You can find out what version you're on with:

            brownie --version

            Source https://stackoverflow.com/questions/70098080


            How to connect to already created ETH wallet using phrase and Web3.py?
            Asked 2022-Jan-19 at 18:21

            How to control my already created Ethereum wallet using passphrase and Python with Web3.py?



            Answered 2022-Jan-19 at 18:21

            You can export the private key from the wallet and import in Web3.py

            Some examples

            Source https://stackoverflow.com/questions/70751732


            How to get an unsigned transaction data from web3.py using contract interaction
            Asked 2022-Jan-04 at 20:08

            Currently I'm working on a project where I have the following flow:

            1. User wants to make a transaction, they choose chain and token.
            2. The contract (possibly proxy contract) and other data is retrieved from the database
            3. I compute the data key, value pair to be used in my front-end call to Metamask


            Answered 2022-Jan-04 at 20:08

            And as always, devs should read better:


            Source https://stackoverflow.com/questions/70583907


            Web3.py: ValueError when using pending filter
            Asked 2021-Dec-05 at 12:51

            I am trying to look up pending transactions in the BEP20 network using web3.py. As stated in in this stack overflow question, one option to do this is using the filter object. Here is a minimal example that should reproduce my problem:



            Answered 2021-Dec-05 at 12:51

            You are using a crappy Binance Smart Chain public node.

            It may or may not support your operations. Apparently it doesn't. We cannot do anything about it.

            Please write this question to the Binance support, as Ethereum community cannot help you with nodes run by private parties.

            Source https://stackoverflow.com/questions/70234159


            ValueError: Method eth_maxPriorityFeePerGas not supported, web3.py with ganache
            Asked 2021-Nov-24 at 23:22

            I'm running the following code with web3.py:



            Answered 2021-Nov-24 at 23:22

            This is an issue from a new edition of web3.py.

            You need to add gasPrice to your transaction, like so:

            Source https://stackoverflow.com/questions/70104101


            TypeError: 'type' object is not subscriptable web3.py
            Asked 2021-Nov-22 at 07:45

            Hey I am getting TypeError: 'type' object is not subscriptable when trying to print SimpleStorage.I am using env, my python version is 3.10.0 n the library is web3.py idk if this is enough this is my first q on stakeoverflow



            Answered 2021-Nov-22 at 07:36

            use () instead of []. Using [] treats it as a subscriptable object/container, meaning they contain other objects. Like strings, lists, tuples, and dictionaries.

            Source https://stackoverflow.com/questions/70062196


            Interacting with Ethereum smart contracts from Python
            Asked 2021-Jun-03 at 06:37

            What Python Ethereum client is meant for smart contract interaction ?
            (mostly ERC20 tokens methods balanceOf, transfer)

            I guess web3.py is older and low level close to JSON RPC.
            But newer Trinity in in alpha.

            The Trinity client is currently in an alpha release stage and is not suitable for mission critical production use cases.



            Answered 2021-Jun-03 at 06:35

            You do not need a "client", or run your own "node", you need a library and some API service provider.

            Try Brownie and Web3.py.

            For JSON-RPC API services check Ethereum nodes.

            Source https://stackoverflow.com/questions/67781988


            Error when deploying a smart contract with w3.eth.contract(): "The method eth_sendTransaction is not supported"
            Asked 2021-May-21 at 07:59

            I'm using Web3.py, and a permissioned Hyperledger Besu network.

            When trying to use w3.eth.contract(...) method to deploy a smart contract into the network, I get the following error:



            Answered 2021-May-11 at 08:17


            Python Web3 connect to Ankr Binance Smart Chain API, through user and password
            Asked 2021-May-10 at 10:38

            Maybe this is a dumb question but for web3.js there is the option to use another API service Ankr, instead of Infura. Ankr gives access to BSC network which has lower fees. I cannot seem to figure out how to connect to Ankr through python web3 as it requires authentication with a username and password. It returns false when I run the python code. I am not sure which keys I am suppose to use for web3.py, or possibly the syntax for the call is wrong, when I use the requests library everything works fine so it is not an issue with the address.



            Answered 2021-May-10 at 10:38

            You should save the headers on a Session object, and pass it as a parameter of HTTPProvider

            Source https://stackoverflow.com/questions/67336484


            Listening to Uniswap contract events using web3.py and infura.io
            Asked 2020-Dec-06 at 11:24

            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 PairCreated event.



            Answered 2020-Jun-25 at 08:22

            Here is rough guide

            1. Get ABI for Uniswap contract

            2. Create a web3.py contract object

            3. You can use web3.eth.getLogs() to query events over past block range

            4. You cannot query all events once, because there are so many events and Infura would time out. Instead you need to query events carefully over a block range slices.

            Here is some old code which may or may not work with the latest web3.py versions


            If you want a real time scanner you can listed to events over a WebSocket connection as they happen:


            Source https://stackoverflow.com/questions/62377210

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network


            No vulnerabilities reported

            Install web3.py

            Get started in 5 minutes or take a tour of the library.


            For additional guides, examples, and APIs, see the documentation.
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries

            Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link