Installation
Seismic Viem is powered by viem. To use it, install both viem
and seismic-viem
:
npm
npm i viem seismic-viem
Quick Start
1. Set up a client
import { createShieldedWalletClient, seismicDevnet1 } from 'seismic-viem'
import { http } from 'viem'
import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts'
const account = privateKeyToAccount(generatePrivateKey())
const wallet = await createShieldedWalletClient({
chain: seismicDevnet1,
transport: http(),
account,
})
2. Call Actions
import { parseEther } from 'viem'
const tx = wallet.sendTransaction({
to: '0x1234567890123456789012345678901234567890',
value: parseEther('0.1'),
})
3. Create a shielded contract instance
You can create a Shielded Contract Instance with the getShieldedContract
function by passing in a ABI, address, and Shielded Public and/or Shielded Wallet Client. Once created, you can call contract methods, fetch for events, listen to events, etc.
example.ts
import { getShieldedContract } from 'seismic-viem'
import { tokenAbi } from './abi'
import { publicClient, walletClient } from './client'
const contract = getShieldedContract({
address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
abi: tokenAbi,
// 1a. Insert a single client
client: walletClient,
// 1b. Or public and/or wallet clients
client: { public: publicClient, wallet: walletClient },
})
const amount = parseUnits('0.1', 18)
const receiver = '0x1234567890123456789012345678901234567890'
// 2. Make a shielded contract write
const txHash = await contract.write.transfer([receiver, amount])
console.log(`Send tx: ${txHash}`)