> ## Documentation Index
> Fetch the complete documentation index at: https://docs.initia.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# API Reference

> Complete API documentation for the autosign feature

## Overview

The `autoSign` object provides methods and properties for managing autosign
functionality. It is available via the `useInterwovenKit()` hook.

## Accessing the API

```tsx theme={null}
import { useInterwovenKit } from '@initia/interwovenkit-react'

function MyComponent() {
  const { autoSign } = useInterwovenKit()

  // Use autoSign methods and properties
}
```

## Type Definitions

### AutoSign Object

```tsx theme={null}
interface AutoSign {
  isLoading: boolean
  enable: (chainId?: string) => Promise<void>
  disable: (chainId?: string) => Promise<void>
  expiredAtByChain: Record<string, Date | null | undefined>
  isEnabledByChain: Record<string, boolean>
  granteeByChain: Record<string, string | undefined>
}
```

## Properties

### isLoading

Indicates whether autosign status is currently being checked.

<ParamField path="isLoading" type="boolean">
  Returns `true` when autosign status is being initialized or checked, `false`
  otherwise. Use this to show loading indicators in your UI.
</ParamField>

**Example:**

```tsx theme={null}
function AutosignButton() {
  const { autoSign } = useInterwovenKit()

  if (autoSign.isLoading) {
    return <button disabled>Loading...</button>
  }

  return <button>Enable Autosign</button>
}
```

### isEnabledByChain

Map of chain IDs to their autosign enabled status.

<ParamField path="isEnabledByChain" type="Record<string, boolean>">
  Returns an object mapping chain IDs to boolean values indicating whether
  autosign is currently enabled for each chain. Use this to check autosign
  status and conditionally render UI elements.
</ParamField>

**Example:**

```tsx theme={null}
function AutosignStatus({ chainId }: { chainId: string }) {
  const { autoSign } = useInterwovenKit()

  if (autoSign.isEnabledByChain[chainId]) {
    return <p>Autosign is enabled for {chainId}</p>
  }

  return <p>Autosign is not enabled</p>
}
```

### expiredAtByChain

Map of chain IDs to their expiration dates.

<ParamField path="expiredAtByChain" type="Record<string, Date | null | undefined>">
  Returns an object mapping chain IDs to expiration dates. Values can be: -
  `Date`: The date when autosign expires - `null`: Autosign is not enabled for
  this chain - `undefined`: Autosign is enabled with no expiration (permanent)
</ParamField>

**Example:**

```tsx theme={null}
function ExpirationDisplay({ chainId }: { chainId: string }) {
  const { autoSign } = useInterwovenKit()
  const expiration = autoSign.expiredAtByChain[chainId]

  if (expiration === null) {
    return <p>Autosign is not enabled</p>
  }

  if (expiration === undefined) {
    return <p>Autosign is enabled (no expiration)</p>
  }

  return <p>Autosign expires: {expiration.toLocaleString()}</p>
}
```

### granteeByChain

Map of chain IDs to grantee addresses (the derived AutoSign wallet addresses).

<ParamField path="granteeByChain" type="Record<string, string | undefined>">
  Returns an object mapping chain IDs to the grantee addresses that have been
  authorized to sign transactions. Use this for debugging or displaying which
  address is authorized for autosign.
</ParamField>

**Example:**

```tsx theme={null}
function MultiChainStatus() {
  const { autoSign } = useInterwovenKit()

  return (
    <div>
      {Object.entries(autoSign.isEnabledByChain).map(([chainId, isEnabled]) => {
        const expiration = autoSign.expiredAtByChain[chainId]

        return (
          <div key={chainId}>
            {chainId}: {isEnabled ? 'Enabled' : 'Disabled'}
            {isEnabled &&
              expiration &&
              ` (until ${expiration.toLocaleString()})`}
          </div>
        )
      })}
    </div>
  )
}
```

## Methods

### enable()

Enables autosign for a specific chain or the default chain.

<ParamField path="enable" type="(chainId?: string) => Promise<void>">
  Opens a drawer for user confirmation, derives the AutoSign wallet for the
  current app origin, and creates the necessary authz and feegrant permissions.
  Returns a Promise that resolves when autosign is successfully enabled or
  rejects if the user cancels or an error occurs.

  **Parameters:** - `chainId` (optional): Chain ID to enable autosign for. If not
  provided, uses the default chain ID from `InterwovenKitProvider`.

  **Returns:** Promise that resolves when autosign is enabled

  **Throws:** Error if user rejects the derivation or grant flow, or if the
  selected chain has no configured AutoSign message types
</ParamField>

**Example:**

```tsx theme={null}
async function enableAutosign() {
  try {
    await autoSign.enable()
    console.log('Autosign enabled for default chain')
  } catch (error) {
    console.error('Failed to enable autosign:', error)
  }
}

async function enableForChain() {
  try {
    await autoSign.enable('minievm-2')
    console.log('Autosign enabled for minievm-2')
  } catch (error) {
    console.error('Failed to enable autosign:', error)
  }
}
```

**Common Failure Cases:**

* `"User cancelled"`: The user closes the AutoSign flow before approving it.
* `No message types configured for chain ${chainId}`: The selected chain does
  not resolve to any allowed AutoSign message types.
* Grant creation fails on-chain or during the wallet/signature flow.

### disable()

Disables autosign for a specific chain or the default chain.

<ParamField path="disable" type="(chainId?: string) => Promise<void>">
  Revokes all authz and feegrant permissions for the specified chain, preventing
  further automatic signing. Returns a Promise that resolves when autosign is
  successfully disabled.

  **Parameters:** - `chainId` (optional): Chain ID to disable autosign for. If not
  provided, uses the default chain ID from `InterwovenKitProvider`.

  **Returns:** Promise that resolves when autosign is disabled

  **Throws:** Error if permissions are not configured or autosign is not enabled
</ParamField>

**Example:**

```tsx theme={null}
async function disableAutosign() {
  try {
    await autoSign.disable()
    console.log('Autosign disabled for default chain')
  } catch (error) {
    console.error('Failed to disable autosign:', error)
  }
}

async function disableForChain() {
  try {
    await autoSign.disable('minievm-2')
    console.log('Autosign disabled for minievm-2')
  } catch (error) {
    console.error('Failed to disable autosign:', error)
  }
}
```
