file-linesSeismic-viem Primer

Before proceeding to write the CLI, you need to be acquainted with some of the functions and utilities used to enable Seismic primitives (e.g. shielded reads, shielded writes etc.) through our client library, seismic-viem , which we will be using heavily to write the CLI. The detailed docs for seismic-viem can be found here. Estimated time: ~15 minutes

Shielded wallet client

The shielded wallet client is the shielded/Seismic counterpart of the wallet client in viem . It is used to enable extended functionality for interacting with shielded blockchain features, wallet operations, and encryption. It can be initialized using the createShieldedWalletClient function as follows:

import { createShieldedWalletClient, sanvil } from 'seismic-viem'
import { http } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'

const walletClient = await createShieldedWalletClient({
  chain: sanvil,
  transport: http(),
  account: privateKeyToAccount('0xabcdef...'),
})

createShieldedWalletClient takes in the following parameters:

  1. chain : a well-defined Chainarrow-up-right object

  2. transport : the method of transport of interacting with the chain (http /ws along with the corresponding RPC URL)

  3. account: a viem Account object (e.g. from privateKeyToAccount())

Once initialized, it can then be used to perform wallet operations or shielded-specific actions.

Shielded contract

A shielded contract instance provides an interface to interact with a shielded contract onchain. It has extended functionality for performing shielded write operations, signed reads, and contract interaction for a specific contract performed by a specific wallet client that it is initialized with. It can be initialized with the getShieldedContract as follows:

It takes in the following parameters:

  1. abi : the ABI of the contract. After running sforge build, the ABI is in out/<ContractName>.sol/<ContractName>.json. You can also generate it manually with ssolc --abi <file>.sol. To use it in your code, you can import the JSON file directly, or copy the ABI array into a constant in your source (more tedious, but gives you better type inference).

  2. address : the address of the deployed contract it is interacting with.

  3. client : the shielded wallet client that the interactions are to be performed by.

This function extends the base getContract functionality by adding:

  • Shielded write actions for nonpayable and payable functions.

  • Signed read actions for pure and view functions.

  • Proxy-based access to dynamically invoke contract methods.

We will extensively use shielded writes (for shake ) and shielded reads (for look()) in our CLI.

Last updated