> **Can't find what you're looking for?** Use `search_docs` on the docs MCP server at `https://sdk.railnet.org/api/mcp` to find what you need.

# useHasRole

Reads whether an account may act under a role, as a TanStack Query result.

## Import

```ts
import { useHasRole } from '@railnetorg/railnet-sdk/react'
```

## Usage

```tsx
import { VEHICLE_STEAM_DEPOSIT } from '@railnetorg/railnet-sdk'
import { useHasRole } from '@railnetorg/railnet-sdk/react'
import { useAccount } from 'wagmi'

export function DepositGate({
  accessControl,
  vehicle,
}: { accessControl: Address; vehicle: Address }) {
  const { address } = useAccount()

  const { data: allowed, isPending } = useHasRole({
    accessControl,
    role: VEHICLE_STEAM_DEPOSIT,
    scope: vehicle,
    account: address as Address,
    enabled: Boolean(address),
  })

  if (isPending) return <Skeleton />
  if (!allowed) return <p>This account is not authorised on this vehicle.</p>

  return <DepositForm vehicle={vehicle} />
}
```

## Returns

A TanStack Query result over `boolean`, with its `queryKey` attached. `false` means the gated
write will revert on its role check. See [`getHasRole`](/actions/getHasRole).

## Parameters

Everything [`getHasRole`](/actions/getHasRole) takes, plus:

### chainId (optional)

* **Type:** `number`
* **Default:** the connected chain

### enabled (optional)

* **Type:** `boolean`
* **Default:** `true`

## Query options

[`hasRoleQueryOptions`](/react/queryOptions) is this read as TanStack Query options, with
`hasRoleQueryKey` and `hasRoleQueryPrefix` for invalidation.

```ts
import { hasRoleQueryOptions } from '@railnetorg/railnet-sdk/react'

await queryClient.prefetchQuery(hasRoleQueryOptions(client, parameters))
```
