banteg / multicall.py

aggregate results of multiple smart contract calls into one
MIT License
246 stars 106 forks source link

Could not discover provider #7

Closed arachmanto closed 2 years ago

arachmanto commented 3 years ago

I running your code and there was an error:

web3.exceptions.CannotHandleRequest: Could not discover provider while making request: method:eth_chainId params:()

Thank you

0xSullivan commented 3 years ago

I have same issue :(

DefiDebauchery commented 3 years ago

This library uses web3.py's Automatic Provider. You can set the environment variable WEB3_PROVIDER_URI (source) with an IPC, RPC, or Websocket address to connect to your endpoint.

You can also do it at runtime by adding the key/value to the os.environ structure.

os.environ["WEB3_PROVIDER_URI"] = '...'

Further, the Call and Multicall classes accept _w3 as a positional argument for passing an existing web3 instance (courtesy of PR https://github.com/banteg/multicall.py/pull/3), so if you want to set up your own connection, you can do that:

from web3 import Web3
from multicall import Call, Multicall

web3 = Web3(Web3.HTTPProvider('https://...'))
# etc

MKR_TOKEN = '0xaaf64bfcc32d0f15873a02163e7e500671a4ffcd'
MKR_WHALE = '0xdb33dfd3d61308c33c63209845dad3e6bfb2c674'
MKR_FISH = '0x2dfcedcb401557354d0cf174876ab17bfd6f4efd'

Call(MKR_TOKEN, ['balanceOf(address)(uint256)', MKR_WHALE], _w3 = web3)()
# or 
multi = Multicall([
    Call(MKR_TOKEN, ['balanceOf(address)(uint256)', MKR_WHALE], [['whale', from_wei]]),
    Call(MKR_TOKEN, ['balanceOf(address)(uint256)', MKR_FISH], [['fish', from_wei]]),
    Call(MKR_TOKEN, 'totalSupply()(uint256)', [['supply', from_wei]]),
], _w3 = web3)
multi()
007vasy commented 2 years ago

added help to my PRs readme