We provide a lightweight viem extension to our client which introduces 2 simple methods to integrate with Viem: client.viem.createPublicClient() and client.viem.createWalletClient().

Since our client was built with a modular approach, this package comes as a standalone, so to reduce the client’s package size.

Installation

Simply run the following in your terminal:

npm i @dynamic-labs/viem-extension@alpha

Creating Viem clients

First, extend your client with our extension:

import { ViemExtension } from '@dynamic-labs/viem-extension'

export const client = createClient({
  environmentId: 'YOUR-ENVIRONMENT-ID',
}).extend(ViemExtension())

Now you can easily leverage all the power of Viem by creating wallet and public clients:

import { mainnet } from 'viem/chains'

// Create a public client using one of viem's provided chains
const publicViemClient = client.viem.createPublicClient({ chain: mainnet })

const lookupBalance = (address: `0x${string}`) =>
  publicViemClient.getBalance({ address })

// Create a wallet client
const walletViemClient = client.viem.createWalletClient({
  wallet: client.wallets.primary,
})

const signMessage = (message: string) =>
  walletViemClient.signMessage({ message })

You can read more about our viem integration here.