Skip to content
Function: getShieldedContract()

seismic-viem


seismic-viem / getShieldedContract

Function: getShieldedContract()

function getShieldedContract<
  TTransport,
  TAddress,
  TAbi,
  TClient,
  TChain,
  TAccount,
>(
  params
): ShieldedContract<TTransport, TAddress, TAbi, TChain, TAccount, TClient>

Defined in: packages/seismic-viem/src/contract/contract.ts:156

This function extends viem's base getContract functionality by adding:

  • write: write to a contract with encrypted calldata
  • read: read from a contract using a signed read
  • tread: transparently read from a contract using an unsigned read (from the zero address)
  • twrite: transparently write to a contract using non-encrypted calldata

Example

const contract = getShieldedContract({
  abi: myContractAbi,
  address: '0x1234...',
  client: shieldedWalletClient,
})
 
// 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)

Type Parameters

TTransport extends Transport

TAddress extends `0x${string}`

TAbi extends Abi | readonly unknown[]

TClient extends | ShieldedWalletClient<TTransport, TChain, TAccount> | KeyedClient<TTransport, TChain, TAccount>

TChain extends undefined | Chain = undefined | Chain

TAccount extends Account = Account

Parameters

params

GetContractParameters<TTransport, TChain, TAccount, TAbi, TClient, TAddress>

The configuration object.

  • abi (Abi) - The contract's ABI.
  • address (Address) - The contract's address.
  • client (ShieldedWalletClient) - The client instance to use for interacting with the contract.

Returns

ShieldedContract<TTransport, TAddress, TAbi, TChain, TAccount, TClient>

Throws

If the wallet client is not provided for shielded write or signed read operations.

Throws

If the wallet client does not have an account configured for signed reads.

Remarks

  • The read property will always call a signed read
  • The tread property will toggle between public reads and signed reads, depending on whether an account is provided
  • The write property will encrypt calldata of the transaction
  • The twrite property will make a normal write, e.g. with transparent calldata
  • The client must be a ShieldedWalletClient