> For the complete documentation index, see [llms.txt](https://docs.seismic.systems/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.seismic.systems/tutorials/understanding-the-clown-beatdown-contract/building-the-cli/seismic-viem-primer.md).

# Seismic-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](/clients/typescript/viem.md). *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:

```typescript
const walletClient = await createShieldedWalletClient({
  chain: seismicChain,
  transport: httpTransport,
  privateKey: "0xabcdef...",
});
```

`createShieldedWalletClient` takes in the following parameters:

1. `chain`: a well-defined [Chain](https://github.com/wevm/viem/blob/main/src/types/chain.ts) object
2. `transport`: the method of transport of interacting with the chain (`http`/`ws` along with the corresponding RPC URL)
3. `privateKey`: the private key to create the client for

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 `getShieldedContract` as follows:

```typescript
const contract = getShieldedContract({
  abi: myContractAbi,
  address: "0x1234...",
  client: shieldedWalletClient,
});
```

It takes in the following parameters:

1. `abi`: the ABI of the contract it is interacting with.
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.

```typescript
// Perform a shielded write
await contract.write.myFunction([arg1, arg2], { gas: 50000n });

// Perform a signed read
const value = await contract.read.getValue();
console.log("Value:", value);
```

We will extensively use **shielded writes (for `addSecret`) and signed reads (for `rob()`) in our CLI.**


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.seismic.systems/tutorials/understanding-the-clown-beatdown-contract/building-the-cli/seismic-viem-primer.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
