> 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/clients/typescript/react/hooks/useshieldedwrite.md).

# useShieldedWrite

{% hint style="info" %}
This hook wraps `useShieldedWriteContract` from seismic-react. The actual export name is `useShieldedWriteContract`.
{% endhint %}

Hook for sending shielded write transactions. Encrypts calldata before submission so transaction data is not visible on-chain.

```typescript
import { useShieldedWriteContract } from "seismic-react";
```

## Config

| Parameter      | Type     | Required | Description                             |
| -------------- | -------- | -------- | --------------------------------------- |
| `address`      | `Hex`    | Yes      | Contract address                        |
| `abi`          | `Abi`    | Yes      | Contract ABI                            |
| `functionName` | `string` | Yes      | Name of the nonpayable/payable function |
| `args`         | `array`  | No       | Arguments to pass to the function       |
| `gas`          | `bigint` | No       | Gas limit override                      |
| `gasPrice`     | `bigint` | No       | Gas price override                      |

## Return Type

| Property        | Type                        | Description                                 |
| --------------- | --------------------------- | ------------------------------------------- |
| `writeContract` | `() => Promise<Hex>`        | Function to execute the shielded write      |
| `write`         | `() => Promise<Hex>`        | Alias for writeContract                     |
| `isLoading`     | `boolean`                   | Whether a write is in progress              |
| `error`         | `Error \| null`             | Error from the most recent write            |
| `hash`          | `` `0x${string}` \| null `` | Transaction hash from last successful write |

***

## Usage

### Shielded token transfer

```typescript
import { useShieldedWriteContract } from 'seismic-react'

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

function TransferToken() {
  const { writeContract, isLoading, error, hash } = useShieldedWriteContract({
    address: '0x1234567890abcdef1234567890abcdef12345678',
    abi,
    functionName: 'transfer',
    args: ['0xRecipientAddress...', 1000n],
  })

  return (
    <div>
      <button onClick={writeContract} disabled={isLoading}>
        {isLoading ? 'Sending...' : 'Transfer'}
      </button>
      {hash && <p>Transaction: {hash}</p>}
      {error && <p>Error: {error.message}</p>}
    </div>
  )
}
```

### Transaction hash tracking

The `hash` field updates after each successful write. Use it to link to a block explorer or track confirmation.

```typescript
import { useShieldedWriteContract } from 'seismic-react'
import { useEffect } from 'react'

function WriteWithTracking() {
  const { writeContract, hash, isLoading } = useShieldedWriteContract({
    address: CONTRACT_ADDRESS,
    abi,
    functionName: 'increment',
  })

  useEffect(() => {
    if (hash) {
      console.log('Transaction confirmed:', hash)
    }
  }, [hash])

  return (
    <div>
      <button onClick={writeContract} disabled={isLoading}>
        Increment
      </button>
      {hash && (
        <a href={`https://seismic-testnet.socialscan.io/tx/${hash}`} target="_blank" rel="noreferrer">
          View on explorer
        </a>
      )}
    </div>
  )
}
```

### Loading and error state handling

```typescript
import { useShieldedWriteContract } from 'seismic-react'

function WriteWithStates() {
  const { writeContract, isLoading, error, hash } = useShieldedWriteContract({
    address: CONTRACT_ADDRESS,
    abi,
    functionName: 'setNumber',
    args: [42n],
  })

  return (
    <div>
      <button onClick={writeContract} disabled={isLoading}>
        {isLoading ? 'Encrypting & sending...' : 'Set Number'}
      </button>
      {isLoading && <p>Transaction in progress...</p>}
      {error && <p style={{ color: 'red' }}>Failed: {error.message}</p>}
      {hash && <p style={{ color: 'green' }}>Success: {hash}</p>}
    </div>
  )
}
```

### With gas override

Pass `gas` or `gasPrice` to override the automatic estimates:

```typescript
import { useShieldedWriteContract } from 'seismic-react'

function WriteWithGasOverride() {
  const { writeContract, isLoading } = useShieldedWriteContract({
    address: CONTRACT_ADDRESS,
    abi,
    functionName: 'expensiveOperation',
    gas: 500_000n,
    gasPrice: 20_000_000_000n,
  })

  return (
    <button onClick={writeContract} disabled={isLoading}>
      Execute
    </button>
  )
}
```

{% hint style="info" %}
Like `useSignedReadContract`, the write function is imperative -- you call `writeContract()` or `write()` explicitly. The hook does not auto-execute on mount or when arguments change.
{% endhint %}

## See Also

* [useSignedReadContract](/clients/typescript/react/hooks/useshieldedread.md) -- Perform signed, encrypted read calls
* [useShieldedContract](/clients/typescript/react/hooks/useshieldedcontract.md) -- Contract instance with both read and write methods
* [useShieldedWallet](/clients/typescript/react/hooks/useshieldedwallet.md) -- Access the underlying wallet client
* [ShieldedWalletProvider](/clients/typescript/react/shielded-wallet-provider.md) -- Context provider required by this hook
* [Hooks Overview](/clients/typescript/react/hooks.md) -- Summary of all hooks


---

# 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/clients/typescript/react/hooks/useshieldedwrite.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.
