Skip to content
LogoLogo
@tevm/vite-plugin · @tevm/ts-plugin · +15 packages

Import .sol files like TypeScript

The Tevm bundler compiles Solidity on demand inside Vite, Rollup, esbuild, webpack, Rspack, and Bun — and hands you back a fully typed contract object. No codegen step, no artifacts directory, no stale ABI JSON.

npm install --save-dev @tevm/vite-plugin @tevm/ts-pluginSee the transform →
app.ts — import the .sol file like any module
import { Counter } from './contracts/Counter.sol' // fully typed — no codegen, no copied ABI const tx = await client.writeContract({ abi: Counter.abi, functionName: 'increment', })
Counter.sol ──▶ tevm bundler plugin ──▶ typed Contract module
2Import it. The bundler plugin resolves .sol files through the Tevm compiler pipeline.

Import a Solidity file the same way you import a TypeScript module, and get a fully typed contract object back.

import { Counter } from './contracts/Counter.sol'
 
Counter.abi
Counter.humanReadableAbi
Counter.deployedBytecode

There is no code generation step to run, no artifacts/ directory to check in, and no hand-written ABI constant that silently drifts from the contract it is supposed to describe. Your build tool compiles Counter.sol on demand, caches the result, and hands your application a Contract object with types derived from the real ABI.

Why this exists

Every JavaScript project that talks to a smart contract has to answer the same question: how does the ABI get from Solidity into TypeScript? The usual answers are all unsatisfying.

  • Copy the ABI into a .json or .ts file. It works until someone changes the contract and forgets the copy. The type checker cannot help you, because as far as it knows the stale ABI is the truth.
  • Run a codegen CLI in a pretest/prebuild hook. Now the generated files are either committed (noisy diffs, merge conflicts) or not committed (a broken checkout until someone runs the right command).
  • Load the ABI at runtime. You lose every type, and you find out about a renamed function in production.

The Tevm bundler removes the question. The Solidity file is the module. The import graph your bundler already walks is the same graph that tells it when to recompile, so a change to Counter.sol invalidates exactly the modules that depend on it — no more, no less.

What is in this repository

This repository is the whole Solidity-to-JavaScript pipeline:

See Ecosystem & repo layout for how this repository relates to tevm core and the other split repositories.

Get started

npm install --save-dev @tevm/vite-plugin @tevm/ts-plugin
vite.config.ts
import { vitePluginTevm } from '@tevm/vite-plugin'
import { defineConfig } from 'vite'
 
export default defineConfig({
	plugins: [vitePluginTevm()],
})

Head to Getting started for the complete walkthrough, including the TypeScript setup that makes your editor understand .sol imports.

The Tevm family

This site is one of the *.tevm.sh docs sites — jump between them: