You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Etherscan以外的链上使用Slither分析合约地址?

解决Slither分析BaseScan/PolygonScan/BSCScan合约时的"Unknown language: unknown"错误

使用Slither分析Etherscan上的合约地址时,直接执行slither <address>即可正常工作,但分析BaseScan、PolygonScan、BSCScan等其他链的合约地址时,即使合约有公开源代码,也会触发以下错误:

Source code not available, try to fetch the bytecode only
Traceback (most recent call last):
  File "/home/box/.local/bin/slither", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/box/.local/lib/python3.12/site-packages/slither/__main__.py", line 753, in main
    main_impl(all_detector_classes=detectors, all_printer_classes=printers)
  File "/home/box/.local/lib/python3.12/site-packages/slither/__main__.py", line 859, in main_impl
    ) = process_all(filename, args, detector_classes, printer_classes)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/box/.local/lib/python3.12/site-packages/slither/__main__.py", line 107, in process_all
    ) = process_single(compilation, args, detector_classes, printer_classes)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/box/.local/lib/python3.12/site-packages/slither/__main__.py", line 80, in process_single
    slither = Slither(target, ast_format=ast, **vars(args))
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/box/.local/lib/python3.12/site-packages/slither/slither.py", line 141, in __init__
    compilation_unit_slither = SlitherCompilationUnit(self, compilation_unit)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/box/.local/lib/python3.12/site-packages/slither/core/compilation_unit.py", line 55, in __init__
    self._language = Language.from_str(crytic_compilation_unit.compiler_version.compiler)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/box/.local/lib/python3.12/site-packages/slither/core/compilation_unit.py", line 45, in from_str
    raise ValueError(f"Unknown language: {label}")
ValueError: Unknown language: unknown

解决方案

方法1:使用--chain参数指定目标链(推荐)

如果你的Slither是v0.9.0及以上版本,可直接用--chain参数指定对应链,同时提供区块浏览器的API密钥:

  • Base链合约分析命令:
slither 0x92E20C3534535db17D4c7c622538eB0930544230 --chain base --etherscan-api-key YOUR_API_KEY
  • Polygon链:
slither <合约地址> --chain polygon --etherscan-api-key YOUR_API_KEY
  • BSC链:
slither <合约地址> --chain bsc --etherscan-api-key YOUR_API_KEY

方法2:手动指定API端点和链ID

若Slither版本不支持--chain参数,可手动指定对应区块浏览器的API地址和链ID:

  • Base链:
slither 0x92E20C3534535db17D4c7c622538eB0930544230 --etherscan-api-url https://api.basescan.org/api --chain-id 8453 --etherscan-api-key YOUR_API_KEY
  • Polygon链:
slither <合约地址> --etherscan-api-url https://api.polygonscan.com/api --chain-id 137 --etherscan-api-key YOUR_API_KEY
  • BSC链:
slither <合约地址> --etherscan-api-url https://api.bscscan.com/api --chain-id 56 --etherscan-api-key YOUR_API_KEY

额外注意事项

  1. 升级Slither:确保使用最新版本,避免旧版本缺少参数支持:
pip install --upgrade slither-analyzer
  1. 获取API密钥:需在对应的区块浏览器注册账号并申请API密钥,免费额度足够日常分析使用。

内容的提问来源于stack exchange,提问作者WiseHipoppotamus

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.24 20:00:20