question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JSONDecodeError when importing contract object from BSCscan

See original GitHub issue

Environment information

  • brownie Version: 1.14.6
  • ganache-cli Version: n/a
  • solc Version: n/a
  • Python Version: 3.8.5
  • OS: ubuntu 20.04 on windows wsl2

What was wrong?

when I try to import a contract with Contract.from_explorer(contract_address) I get JSONDecodeError: Expecting value: line 2 column 1 (char 1)

  • full output of the error you received
>>>poocoin = Contract.from_explorer('0xb27adaffb9fea1801459a1a81b17218288c097cc')
Fetching source of 0xB27ADAfFB9fEa1801459a1a81B17218288c097cc from bscscan.com...
  File "<console>", line 1, in <module>
  File "brownie/network/contract.py", line 1090, in from_explorer
    data = _fetch_from_explorer(address, "getsourcecode", silent)
  File "brownie/network/contract.py", line 1891, in _fetch_from_explorer
    data = response.json()
  File "requests/models.py", line 900, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/lib/python3/dist-packages/simplejson/__init__.py", line 518, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3/dist-packages/simplejson/decoder.py", line 370, in decode
    obj, end = self.raw_decode(s)
  File "/usr/lib/python3/dist-packages/simplejson/decoder.py", line 400, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
JSONDecodeError: Expecting value: line 2 column 1 (char 1)

this same command works fine on ethereum mainnet for example:

>>> uniswap = Contract.from_explorer('0x1f9840a85d5af5bf1d1762f925bdaddc4201f984')
Fetching source of 0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984 from api.etherscan.io...
>>>

How can it be fixed?

most likely an issue with the json formatting response from bscscan

Fill this in if you know how the bug could be fixed.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
sabotagebeatscommented, May 18, 2021

This fixed the issue for me:

brownie networks modify binance explorer="https://api.bscscan.com/api"

previously I was using the wrong explorer address https://bscscan.com/

0reactions
sabotagebeatscommented, May 18, 2021

Looks like I’m still having the issue.

File "<console>", line 1, in <module>
  File "brownie/network/contract.py", line 452, in publish_source
    data = response.json()
  File "requests/models.py", line 900, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/lib/python3/dist-packages/simplejson/__init__.py", line 518, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3/dist-packages/simplejson/decoder.py", line 370, in decode
    obj, end = self.raw_decode(s)
  File "/usr/lib/python3/dist-packages/simplejson/decoder.py", line 400, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
JSONDecodeError: Expecting value: line 2 column 1 (char 1)
poocoin = Contract.from_explorer('0xb27adaffb9fea1801459a1a81b17218288c097cc')
Fetching source of 0xB27ADAfFB9fEa1801459a1a81B17218288c097cc from bscscan.com...
  File "<console>", line 1, in <module>
  File "brownie/network/contract.py", line 1090, in from_explorer
    data = _fetch_from_explorer(address, "getsourcecode", silent)
  File "brownie/network/contract.py", line 1891, in _fetch_from_explorer
    data = response.json()
  File "requests/models.py", line 900, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/lib/python3/dist-packages/simplejson/__init__.py", line 518, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3/dist-packages/simplejson/decoder.py", line 370, in decode
    obj, end = self.raw_decode(s)
  File "/usr/lib/python3/dist-packages/simplejson/decoder.py", line 400, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
JSONDecodeError: Expecting value: line 2 column 1 (char 1)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Nomad Exiles: PRIDE Token | Address ... - BscScan
The Contract Address 0x085d15db9c7cd3df188422f88ec41ec573d691b9 page allows ... import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol"; ...
Read more >
Address 0x15f2fefcf313d397f9933c1cb7590ab925d5cb59
The Contract Address 0x15f2fefcf313d397f9933c1cb7590ab925d5cb59 page allows users to view ... import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; ...
Read more >
Address 0x6261d8e873b9a7be666d0aa07357bc9d6bcc7feb
The Contract Address 0x6261d8e873b9a7be666d0aa07357bc9d6bcc7feb page allows users to view the source code, transactions, balances, ...
Read more >
StarSharks: SEA Token - BscScan
The Contract Address 0x26193C7fa4354AE49eC53eA2cEBC513dc39A10aa page allows users to view the source code, transactions, balances, and analytics for the ...
Read more >
Address 0x35ebb629b6e65cb7705b5e0695982d206898f195
The Contract Address 0x35ebb629b6e65cb7705b5e0695982d206898f195 page allows ... import "@openzeppelin/contracts-upgradeable/math/SafeMathUpgradeable.sol"; ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found