Skip to content

feat(address): add Vyper smart contract support and syntax highlighting#331

Open
AugustoL wants to merge 1 commit intoopenscan-explorer:devfrom
AugustoL:feat/vyper-support
Open

feat(address): add Vyper smart contract support and syntax highlighting#331
AugustoL wants to merge 1 commit intoopenscan-explorer:devfrom
AugustoL:feat/vyper-support

Conversation

@AugustoL
Copy link
Collaborator

Description

Add proper support for Vyper smart contracts across the explorer, including correct file extension detection, language identification, and syntax highlighting for source code display.

Closes #327

Related Issue

Closes #327

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Refactoring
  • Performance improvement
  • Other (please describe):

Changes Made

  • Fix .sol hardcoding in useEtherscan.ts: Detect Vyper contracts by checking if the compiler version starts with vyper: and use .vy extension accordingly
  • Add language field for Etherscan-verified contracts: Set language: "Vyper" or "Solidity" based on compiler version detection
  • New CodeBlock component: Reusable syntax-highlighted code display using Prism.js with support for Solidity, Vyper (Python grammar), and JSON
  • Syntax highlighting: Integrate Prism.js (prismjs) with a VS Code-inspired theme in code-highlight.css
  • Update ContractDetails and ContractInfoCard: Replace plain <pre> blocks with the new CodeBlock component for highlighted source display

Screenshots (if applicable)

N/A

Checklist

  • I have run npm run format:fix and npm run lint:fix
  • I have run npm run typecheck with no errors
  • I have run tests with npm run test:run
  • I have tested my changes locally
  • I have updated documentation if needed
  • My code follows the project's architecture patterns

Additional Notes

  • Vyper syntax highlighting uses Python grammar from Prism.js since Vyper has Python-like syntax
  • The CompilerVersion field from Etherscan API is used for language detection — Vyper compilers report versions prefixed with vyper:
  • All existing Solidity contract functionality remains unchanged

Detect Vyper contracts from Etherscan's CompilerVersion (vyper: prefix)
and Sourcify's compilation.language field. Use correct .vy file extension
instead of hardcoded .sol. Add CodeBlock component with Prism.js for
syntax highlighting of Solidity (.sol) and Vyper (.vy) source files.

Test with CRV token (Vyper, verified on Sourcify):
0xd533a949740bb3306d119cc777fa900ba034cd52
@github-actions
Copy link

🚀 Preview: https://pr-331--openscan.netlify.app
📝 Commit: 9f840888fbf284a8a512b1baf3ba5268cac6ac48

Copy link
Collaborator

@josealoha666 josealoha666 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall. The Vyper detection path in useEtherscan and the shared CodeBlock wiring make sense, and I don't see a blocker in the diff itself.

Not approving yet because the PR is currently in a merge-conflict state against dev and the E2E jobs are still pending. Once those are green and the branch is rebased, this should be in good shape.

return (
<pre className="source-file-code">
{/* biome-ignore lint/security/noDangerouslySetInnerHtml: Prism.highlight output is safe — it only tokenizes source code we control */}
<code className={`language-${lang}`} dangerouslySetInnerHTML={{ __html: highlighted }} />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Who are we trusting here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants