brownie mainnet-fork issue when trying to interact with contract: 'ValueError: invalid literal for int() with base 16: '''

Viewed 327

I'm following the instructions here to interact with forked mainnet contracts using brownie. The three lines of code suggested are:

address = "0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419"
oracle = Contract.from_explorer(address)
oracle.latestAnswer()

However, when I run the second line, I get the following:

Fetching source of 0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419 from api.etherscan.io...
  File "<console>", line 1, in <module>
  File "brownie/network/contract.py", line 1162, in from_explorer
    if not _verify_deployed_code(
  File "brownie/network/contract.py", line 1765, in _verify_deployed_code
    idx = -(int(actual_bytecode[-4:], 16) + 2) * 2
ValueError: invalid literal for int() with base 16: ''

It seems as though the mainnet fork is accessible, but the contract itself is somehow corrupt. What am I doing wrong?

1 Answers

I have been doing this tutorial and just fixed this issue myself. I'm using a more up to date version for the random number generator, the VRFv2Consumer , than the tutorial.

In that version, the constructor gets passed a subscription ID, which I was passing as an integer from python. I got the exact same error as you. I think it's a mismatch with the types, because when I changed the subscription id in the sol file from uint64 to uint256, then recompiled, it fixed the issue.

Had to also convert the function call for the requestRandomWords which uses the subscription id, so I had to wrap that in uint64(s_subscriptionId) to change it back.

I'm not sure this will be your solution, but I don't have enough reputation points to just comment. Hopefully it may help, I'm happy to discuss it further if not.

Related