@tevm/voltaire/provider and @tevm/voltaire/jsonrpc work directly inside Svelte 5 runes, Svelte stores, and SvelteKit +page.server.ts load functions.
Installation
npm install @tevm/voltaire
Svelte 5 Runes
<script lang="ts">
import { Address } from '@tevm/voltaire/Address';
import { Wei } from '@tevm/voltaire/Denomination';
import { Rpc } from '@tevm/voltaire/jsonrpc';
import { HttpProvider } from '@tevm/voltaire/provider';
const provider = new HttpProvider('https://eth.llamarpc.com');
let address = $state('');
let balance = $state<string | null>(null);
let loading = $state(false);
let error = $state<string | null>(null);
$effect(() => {
if (!Address.isValid(address)) {
balance = null;
return;
}
let cancelled = false;
loading = true;
error = null;
provider
.request(Rpc.Eth.GetBalanceRequest(Address.from(address), 'latest'))
.then((hex) => {
if (!cancelled) balance = Wei.toEther(Wei.from(BigInt(hex as string)));
})
.catch((e) => {
if (!cancelled) error = e instanceof Error ? e.message : String(e);
})
.finally(() => {
if (!cancelled) loading = false;
});
return () => {
cancelled = true;
};
});
</script>
<input bind:value={address} placeholder="0x..." />
{#if loading}
<p>Loading...</p>
{:else if error}
<p>Error: {error}</p>
{:else if balance !== null}
<p>Balance: {balance} ETH</p>
{/if}
SvelteKit Server Load Function
Keep private RPC credentials on the server and serialize plain values to the client:// src/routes/address/[address]/+page.server.ts
import { error } from '@sveltejs/kit';
import { Address } from '@tevm/voltaire/Address';
import { Wei } from '@tevm/voltaire/Denomination';
import { Rpc } from '@tevm/voltaire/jsonrpc';
import { HttpProvider } from '@tevm/voltaire/provider';
import type { PageServerLoad } from './$types';
const provider = new HttpProvider(process.env.RPC_URL ?? 'https://eth.llamarpc.com');
export const load: PageServerLoad = async ({ params }) => {
if (!Address.isValid(params.address)) {
throw error(400, 'Invalid Ethereum address');
}
const addr = Address.from(params.address);
const [balanceHex, nonceHex, code] = (await Promise.all([
provider.request(Rpc.Eth.GetBalanceRequest(addr, 'latest')),
provider.request(Rpc.Eth.GetTransactionCountRequest(addr, 'latest')),
provider.request(Rpc.Eth.GetCodeRequest(addr, 'latest')),
])) as [string, string, string];
return {
address: params.address,
balance: Wei.toEther(Wei.from(BigInt(balanceHex))),
nonce: Number(BigInt(nonceHex)),
isContract: code !== '0x',
};
};
Polling Readable Store
// src/lib/blocks.ts
import { Rpc } from '@tevm/voltaire/jsonrpc';
import { HttpProvider } from '@tevm/voltaire/provider';
import { readable } from 'svelte/store';
const provider = new HttpProvider('https://eth.llamarpc.com');
export const latestBlock = readable<bigint | null>(null, (set) => {
const fetchHead = async () => {
const hex = (await provider.request(Rpc.Eth.BlockNumberRequest())) as string;
set(BigInt(hex));
};
void fetchHead();
const id = setInterval(() => void fetchHead(), 12_000);
return () => clearInterval(id);
});
Related
- JSON-RPC Provider — HTTP and WebSocket providers
- Address — Validation and checksumming
- Polling Utilities — Polling receipts and state transitions

