useShieldedContract
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
abi
Abi
Yes
Contract ABI
address
Address
Yes
Contract address
Return Type
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:
See Also
useShieldedWallet -- Access the underlying wallet and public clients
useShieldedWriteContract -- Send encrypted writes without a contract instance
useSignedReadContract -- Perform signed reads without a contract instance
ShieldedWalletProvider -- Context provider required by this hook
Hooks Overview -- Summary of all hooks
Last updated

