file-contractuseShieldedContract

Get a ShieldedContract instance for reads and writes

Hook that creates a ShieldedContract instance from seismic-viem's getShieldedContract. Provides a contract object with type-safe methods for both shielded writes and signed reads.

import { useShieldedContract } from "seismic-react";

Config

Parameter
Type
Required
Description

abi

Abi

Yes

Contract ABI

address

Address

Yes

Contract address

Return Type

Property
Type
Description

contract

ShieldedContract | null

The shielded contract instance

abi

Abi

The ABI passed in

address

Address

The address passed in

error

Error | null

Error if wallet client not initialized


Usage

Basic

import { useShieldedContract } from 'seismic-react'

const abi = [
  {
    name: 'balanceOf',
    type: 'function',
    stateMutability: 'view',
    inputs: [],
    outputs: [{ name: '', type: 'uint256' }],
  },
  {
    name: 'transfer',
    type: 'function',
    stateMutability: 'nonpayable',
    inputs: [
      { name: 'to', type: 'address' },
      { name: 'amount', type: 'uint256' },
    ],
    outputs: [],
  },
] as const

function MyContract() {
  const { contract, error } = useShieldedContract({
    abi,
    address: '0x1234567890abcdef1234567890abcdef12345678',
  })

  if (error) return <div>Error: {error.message}</div>
  if (!contract) return <div>Loading contract...</div>

  return <div>Contract ready</div>
}

Using the contract for reads and writes

Once you have a ShieldedContract instance, call its methods directly for both signed reads and shielded writes:

TypeScript ABI typing

For full type inference on contract methods, define your ABI with as const:

circle-info

useShieldedContract requires a connected wallet via ShieldedWalletProvider. The contract field is null until the wallet client is initialized.

See Also

Last updated