Tutorial: Solidity bundler
Instead of running a separate Solidity compile step, copying ABI JSON files, and regenerating TypeScript bindings after every edit, the TEVM bundler compiles .sol files into typed ES modules at build time. Paired with @tevm/ts-plugin, your editor shows type errors and NatSpec hover documentation as you type.
-
Install TEVM and viem
Section titled “Install TEVM and viem”All bundler plugins ship inside the umbrella
tevmpackage undertevm/bundler/*:Terminal window pnpm add tevm viem -
Register your bundler plugin
Section titled “Register your bundler plugin”vite.config.ts import { defineConfig } from 'vite'import { vitePluginTevm } from 'tevm/bundler/vite-plugin'export default defineConfig({plugins: [vitePluginTevm()],})build.ts import { build } from 'esbuild'import { esbuildPluginTevm } from 'tevm/bundler/esbuild-plugin'await build({entryPoints: ['src/index.ts'],bundle: true,outfile: 'dist/index.js',plugins: [esbuildPluginTevm()],})rollup.config.ts import { rollupPluginTevm } from 'tevm/bundler/rollup-plugin'export default {input: 'src/index.ts',output: { dir: 'dist', format: 'esm' },plugins: [rollupPluginTevm()],}webpack.config.ts import { WebpackPluginTevm } from 'tevm/bundler/webpack-plugin'export default {plugins: [new WebpackPluginTevm()],}rspack.config.ts import { rspackPluginTevm } from 'tevm/bundler/rspack-plugin'export default {plugins: [rspackPluginTevm()],}plugins.ts import { plugin } from 'bun'import { bunPluginTevm } from 'tevm/bundler/bun-plugin'plugin(bunPluginTevm({}))Register
plugins.tsinbunfig.toml:bunfig.toml preload = ["./plugins.ts"][test]preload = ["./plugins.ts"] -
Enable TypeScript IDE support
Section titled “Enable TypeScript IDE support”Add
@tevm/ts-plugintotsconfig.jsonso TypeScript resolves.solimports, shows NatSpec comments on hover, and flags wrong argument types before build time:tsconfig.json {"compilerOptions": {"plugins": [{ "name": "@tevm/ts-plugin" }]}}In VS Code, run TypeScript: Select TypeScript Version and select Use Workspace Version.
Add
.tevm/to.gitignoreso compiled cache artifacts stay out of version control. -
Import and run a Solidity contract
Section titled “Import and run a Solidity contract”Write a contract (imports from
node_modulesand Foundry remappings work automatically when configured intevm.config.json):src/Counter.s.sol // SPDX-License-Identifier: MITpragma solidity ^0.8.20;contract Counter {uint256 public number;function setNumber(uint256 next) public {number = next;}}Import
Counterdirectly and use its typeddeploy,read, andwriteaction creators withcreateMemoryClient():src/run-counter.ts import { Counter } from './Counter.s.sol'import { createMemoryClient, PREFUNDED_ACCOUNTS } from 'tevm'const client = createMemoryClient({account: PREFUNDED_ACCOUNTS[0],})try {const hash = await client.deployContract(Counter.deploy())const receipt = await client.getTransactionReceipt({ hash })const counter = Counter.withAddress(receipt.contractAddress!)await client.writeContract(counter.write.setNumber(42n))const value = await client.readContract(counter.read.number())console.log(value) // 42n} finally {await client.tevmClose()} -
Alternative: Static codegen without a bundler plugin
Section titled “Alternative: Static codegen without a bundler plugin”If your framework runs strict type-checking outside the bundler (such as Next.js
tscbuilds), generate.tscontract modules alongside your.solfiles instead:Terminal window npx tevm gen
Browser compatibility
Section titled “Browser compatibility”The bundler compiles Solidity at build time and emits pure JavaScript/TypeScript Contract objects (abi, humanReadableAbi, read, write, events, and optional bytecode) with zero native dependencies. Use those compiled imports in React, Svelte, Astro, or Next.js frontends with viem, wagmi, or in-browser TEVM WASM.
Next steps
Section titled “Next steps”- Bundler plugins reference —
tevm.config.jsonoptions, Foundry remappings, and troubleshooting. - Testing with Vitest — combine
.s.solimports with Vitest and snapshots. - Standalone bundler docs — deep dives for
evmts/tevm-bundler.

