whitechainSepolia in viem/chains. No custom chain definition is needed. This page shows how to install viem, create a client, and run the most common read and write operations.
Install
Terminal
await and process.env. Add "type": "module" to package.json and declare the node types in tsconfig.json:
package.json
tsconfig.json
1. Create a client
UsecreatePublicClient for read operations and createWalletClient for transactions and contract writes.
Read the private key from an environment variable and exclude .env from version control.
client.ts
http() with no argument uses the RPC endpoint built into whitechainSepolia (https://rpc.testnet.whitechain.io). Pass a URL string to http('https://...') to override it.2. Read a balance
getBalance returns the WBT balance of an address in wei. Use formatEther to convert it to a decimal string.
3. Send WBT
sendTransaction sends WBT to a recipient address. Use parseEther to express the value in WBT rather than wei.
4. Call a contract
Define the contract address and ABI once and share them across read and write operations.contract.ts
Keep
as const on the ABI. Without it, TypeScript cannot infer function names or argument types from the array.Read from a contract
readContract calls a view or pure function. No transaction is sent and no gas is spent.
Write to a contract
writeContract sends a transaction that calls a state-changing function.

