Skip to content

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

Merged
AugustoL merged 2 commits intoopenscan-explorer:devfrom
AugustoL:feat/vyper-support
Mar 20, 2026
Merged

feat(address): add Vyper smart contract support and syntax highlighting#331
AugustoL merged 2 commits 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

github-actions bot commented Mar 19, 2026

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

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We're trusting Prism.js (the syntax highlighter library). Prism.highlight() takes plain text, tokenizes it using grammar rules, and
returns HTML with wrappers. It HTML-escapes the input text before wrapping — so even if the source code contains

<script>alert('xss')</script>, Prism outputs <script>alert('xss')</script> wrapped in token spans. The source code itself (from

Sourcify/Etherscan) is never injected as raw HTML — only Prism's deterministic markup is.

The XSS risk with dangerouslySetInnerHTML is when you inject untrusted HTML. Prism's output is deterministic markup based on its grammar
rules — even if the source code contained <script> tags, Prism would escape them into <script> tokens. So this is a safe and standard
pattern for syntax highlighting in React.

…support

# Conflicts:
#	src/App.tsx
#	src/components/pages/evm/address/shared/ContractDetails.tsx
#	src/components/pages/evm/address/shared/ContractInfoCard.tsx
@AugustoL AugustoL merged commit 23876b7 into openscan-explorer:dev Mar 20, 2026
4 of 7 checks passed
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