banteg / multicall.py

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

403 Client Error when using Multicall on Avalanche Mainnet. #68

Closed adamxyzxyz closed 4 months ago

adamxyzxyz commented 1 year ago

Hello,

I am receiving the following error when attempting to use the avalanche public rpc on mainnet:

403 Client Error: Forbidden for url: https://api.avax.network/ext/bc/C/rpc [0]

I am using the example code as below:

from multicall import Call, Multicall
from web3 import Web3

TOKEN = '0x98e2060F672FD1656a07bc12D7253b5e41bF3876'
WHALE = '0x252332713864B50300d65580decD387cDD957C59'

def from_wei(value):
    return value / 1e18

w3 = Web3(Web3.HTTPProvider('https://api.avax.network/ext/bc/C/rpc'))

multi = Multicall(calls=[
    Call(TOKEN, ['balanceOf(address)(uint256)', WHALE], [('whale', from_wei)]),
], _w3=w3)

multi()
BobTheBuidler commented 1 year ago

Not entirely sure here, are you able to make calls to the same rpc using a different method?

adamxyzxyz commented 1 year ago

Yes, if I make calls normally, such as contract.functions.function().call(), there are no issues.

Similarly, this also works:

from multicall import Call, Multicall
from web3 import Web3

TOKEN = '0x98e2060F672FD1656a07bc12D7253b5e41bF3876'
WHALE = '0x252332713864B50300d65580decD387cDD957C59'

def from_wei(value):
    return value / 1e18

w3 = Web3(Web3.HTTPProvider('https://api.avax.network/ext/bc/C/rpc'))

calls=Call(TOKEN, ['balanceOf(address)(uint256)', WHALE], [('whale', from_wei)], _w3=w3)

print(calls())

@BobTheBuidler are you able to reproduce this error on your end? I do not receive the 403 error if I use other avalanche endpoints, but I would prefer to use their public one if possible.

adamxyzxyz commented 1 year ago

Hey @BobTheBuidler @banteg circling back on this

DefiDebauchery commented 1 year ago

The issue is that your TOKEN address is not a token on AVAX, and thus does not have a balanceOf method.

Changing your above code simply to reference a compatible token contract results in no error --

TOKEN = '0xd6070ae98b8069de6B494332d1A1a81B6179D960'
BobTheBuidler commented 1 year ago

@DefiDebauchery its a bit odd that the examples provided do work with a non-token address.

@adamxyzxyz j/w, was it just outputting a 0 or was it giving you a positive result?

BobTheBuidler commented 4 months ago

going to close this due to no activity. Feel free to reopen if this is still an issue.