0

I am tring to get all holders of a particular contract through web3.py library.For RPC I am using infura.

the code is:

contract = web3.eth.contract(address=address,abi=abi)
name = contract.functions.name().call()
print(name)


def holdersEvent(_fromBlock, _toBlock):
    try:
        transferEvents = contract.events.Transfer.createFilter(fromBlock=_fromBlock, toBlock=_toBlock)
        for i in range(len(transferEvents.get_all_entries())):
            addressTo = transferEvents.get_all_entries()[i].args.to
            print(addressTo)
    except error:
        #holdersEvent(_fromBlock, _toBlock)
        print(_fromBlock," ",_toBlock)


latest = web3.eth.blockNumber
firstBlock = web3.eth.getTransactionReceipt(tx_hash).blockNumber
totalResult = latest - firstBlock

initial = firstBlock
if totalResult >2000:
    while totalResult>=2000:
        fromBlock = initial
        toBlock = initial +2000
        holdersEvent(fromBlock,toBlock)
        totalResult = totalResult -2000
        initial = toBlock
    if totalResult != 0:
        fromBlock = initial
        toBlock = initial + totalResult
        holdersEvent(fromBlock,toBlock)
else:
    holdersEvent(firstBlock,latest)

under this I am facing the error as

ValueError: {'code': -32000, 'message': 'filter not found'}

How do I resolve this?

1 Answer 1

0

Most public nodes do not support filters, pending blocks, etc.

To access those features for JSON-RPC you need to run your own node.

1
  • I found the solution I have to use WebSocket rather than HTTP
    – itbhad
    Jan 20, 2022 at 9:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.