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

# Runtime context

> Read sdk.context to access the full host context (user identity, capabilities, and Startale-specific data) from inside your Mini App.

When your Mini App runs inside the Startale App, the host populates `sdk.context` with three layers: Farcaster-standard fields, client/device metadata, and a `startale` extension object with Startale-specific user data.

## Full context shape

```ts theme={null}
const context = await sdk.context

// Farcaster-standard user identity
context.user       // { fid, username, displayName, pfpUrl }
context.location   // { type: 'launcher' }
context.client     // { platformType, clientFid, added, safeAreaInsets }

// Device capabilities
context.features   // { haptics: boolean, cameraAndMicrophoneAccess: boolean }

// Startale-specific
context.startale   // { starPoints, eoaWallets, language, legacyAddress, legacySignature }
```

| Field | Type | Description |
| - | - | - |
| `user.fid` | `number` | Internal Startale identifier. Present for protocol compatibility, not a Farcaster account ID. Do not use this to identify users; use the smart account address from `eth_requestAccounts` instead. |
| `user.username` | `string` | The user's Startale display username. |
| `user.displayName` | `string` | Display name. |
| `user.pfpUrl` | `string` | Profile photo URL. |
| `location.type` | `string` | Launch context. Always `'launcher'` when opened from the Mini App grid. |
| `client.platformType` | `string` | Host platform identifier. |
| `client.clientFid` | `number` | Internal Startale client identifier. Present for protocol compatibility, not a Farcaster account ID. |
| `client.safeAreaInsets` | `object` | `{ top, bottom, left, right }` in px; use for notch-safe layout. |
| `features.haptics` | `boolean` | Whether the host supports haptic feedback. Use before calling haptic actions. |
| `features.cameraAndMicrophoneAccess` | `boolean` | Whether camera/mic access is available. `true` only in a secure context (HTTPS) on a device with media devices. Check before requesting access. See [SDK actions](https://docs.startale.com/miniapps/sdk-actions.md#actions-requestcameraandmicrophoneaccess). |
| `startale.starPoints` | `number` | The user's current STAR Points balance. |
| `startale.eoaWallets` | `string[]` | Addresses verified as linked to the user's smart account. |
| `startale.language` | `string` | The Startale App **edition** the user is in, as a code (`'en'` for Global, `'ja'` for Japan). It is not simply a UI language toggle, see [Reading the app edition](#reading-the-app-edition). |
| `startale.legacyAddress` | `string` | The user's smart account address from before an account upgrade. Only present once the user has completed an upgrade; `undefined` otherwise. See [Legacy address after an account upgrade](#legacy-address-after-an-account-upgrade). |
| `startale.legacySignature` | `string` | A signature from `legacyAddress` approving the current smart account as its successor. Set together with `legacyAddress`. Verify it before relying on `legacyAddress` for anything beyond display, see [Verifying the legacy signature](#verifying-the-legacy-signature). |

> [!NOTE]
>
> **Identifying users.** Use the smart account address (retrieved via `eth_requestAccounts`) as the primary user identifier in your backend. `user.fid` and `client.clientFid` are internal protocol placeholders and are not stable user identifiers.

## Reading context

`sdk.context` is a Promise. The bridge between your Mini App and the host is asynchronous, so you must `await` it before reading any field.

The `startale` object is a Startale extension not included in the official `@farcaster/miniapp-sdk` TypeScript types. Cast the result to access it with full type safety:

```ts theme={null}
import { sdk } from '@farcaster/miniapp-sdk'

type StartaleContext = {
  user?: { username?: string; displayName?: string; pfpUrl?: string }
  client?: { safeAreaInsets?: { top: number; bottom: number; left: number; right: number } }
  features?: { haptics?: boolean; cameraAndMicrophoneAccess?: boolean }
  startale?: {
    starPoints?: number
    eoaWallets?: string[]
    language?: 'en' | 'ja'
    legacyAddress?: string
    legacySignature?: string
  }
}

const context = (await sdk.context) as StartaleContext

const starPoints = context.startale?.starPoints ?? 0
const eoaWallets = context.startale?.eoaWallets ?? []
const language   = context.startale?.language ?? 'en'
const username   = context.user?.username ?? ''
const legacyAddress   = context.startale?.legacyAddress
const legacySignature = context.startale?.legacySignature
```

In React, read context once on mount inside a `useEffect`:

```tsx theme={null}
import { useEffect, useState } from 'react'
import { sdk } from '@farcaster/miniapp-sdk'

type StartaleContext = {
  user?: { username?: string; pfpUrl?: string }
  features?: { haptics?: boolean; cameraAndMicrophoneAccess?: boolean }
  client?: { safeAreaInsets?: { top: number; bottom: number; left: number; right: number } }
  startale?: {
    starPoints?: number
    eoaWallets?: string[]
    language?: 'en' | 'ja'
    legacyAddress?: string
    legacySignature?: string
  }
}

export function useStartaleContext() {
  const [context, setContext] = useState<StartaleContext | null>(null)

  useEffect(() => {
    sdk.context
      .then((raw) => setContext(raw as StartaleContext))
      .catch(console.error)
  }, [])

  return context
}
```

```tsx theme={null}
function App() {
  const context = useStartaleContext()

  const starPoints = context?.startale?.starPoints ?? 0
  const eoaWallets = context?.startale?.eoaWallets ?? []
  const username   = context?.user?.username ?? ''

  return <Dashboard starPoints={starPoints} eoaWallets={eoaWallets} username={username} />
}
```

> [!NOTE]
>
> The `startale` type cast is necessary today because the Startale context extensions are not yet part of the upstream `@farcaster/miniapp-sdk` type definitions. The cast is safe; the host always populates these fields when your Mini App runs inside the Startale App.

## STAR Points

STAR Points are the Startale App's user-engagement currency. Users earn them through daily activities in the Mission Center and through USDSC usage inside the app, and the balance is treated as a proof of contribution toward future token rewards. Mini Apps see the balance through `sdk.context.startale.starPoints` and can use it as an eligibility signal, for example, gating bonus content or rewarding power users.

For the full earning rules and the latest mission catalog, link users to the [Startale App page](https://startale.com/en/app).

## Reading user STAR Points

```ts theme={null}
import { sdk } from '@farcaster/miniapp-sdk'

const context = await sdk.context
const points = context.startale?.starPoints ?? 0

console.log(`User has ${points} STAR Points`)
```

## Reading the app edition

`startale.language` tells you which edition of the Startale App the user is running at the moment your Mini App loads: Global (`'en'`) or Japan (`'ja'`). The host decides this, including any residency and compliance checks, before your Mini App ever sees it.

Use it to pick the content or feature set your Mini App shows, for example JP-only copy or anything gated on Japan compliance requirements. Don't run your own geo or residency checks for this: if `startale.language` says `'ja'`, the host has already confirmed the user's edition, and any JP content it's willing to show them is already vetted for that edition.

Edition and display language happen to match today, so you can also use the same field to pick your Mini App's own UI translation if it has one:

```ts theme={null}
import { sdk } from '@farcaster/miniapp-sdk'

const context = await sdk.context
const edition = context.startale?.language ?? 'en' // 'en' = Global, 'ja' = Japan

if (edition === 'ja') {
  // show Japan-edition content
}

i18n.changeLanguage(edition) // optional: also use it for your own i18n
```

## Discovering linked EOAs

`eoaWallets` is the canonical way to discover personal wallets the user has linked to their Startale account. Each address has been verified server-side via SIWE.

Common use cases:

* Restoring user progress from an existing user base.
* Granting NFT utility based on assets held in a personal wallet.
* Co-marketing eligibility checks ("are you an existing player of project X?").

If your project issues NFTs that users hold directly in their smart account, see [NFT assets](https://docs.startale.com/miniapps/nft-assets.md) for how those are surfaced in the Startale App's Collectibles UI and the metadata structure required for correct display.

```ts theme={null}
import { sdk } from '@farcaster/miniapp-sdk'
import { createPublicClient, http, erc721Abi } from 'viem'
import { soneium } from 'viem/chains'

const context = await sdk.context
const eoaAddresses = context.startale?.eoaWallets ?? []

const publicClient = createPublicClient({
  chain: soneium,
  transport: http(),
})

for (const address of eoaAddresses) {
  const balance = await publicClient.readContract({
    address: NFT_CONTRACT_ADDRESS,
    abi: erc721Abi,
    functionName: 'balanceOf',
    args: [address as `0x${string}`],
  })
  if (balance > 0n) {
    // User holds the NFT in this linked EOA
  }
}
```

## EOAs are read-only

You can read balances and onchain state for any address in `eoaWallets`. You cannot sign or send transactions from a linked EOA inside a Mini App, the active signer is always the user's smart account.

If a user holds assets in a linked EOA that they want to use inside your Mini App:

1. Detect the asset using `eoaWallets` and a read-only contract call.
2. Inform the user that they need to transfer the asset to their smart account.
3. The transfer must happen outside the Mini App, on your project's standalone website where MetaMask connects directly.

See [Wallet integration](https://docs.startale.com/miniapps/wallet-integration.md) for the full constraint surface.

## Legacy address after an account upgrade

Startale may, under rare circumstances, upgrade a user to a new smart account address. When this happens, the address your Mini App sees from `eth_requestAccounts` changes. `startale.legacyAddress` and `startale.legacySignature` let you detect the change and remap any offchain state (progress, inventory, points) you keyed to the old address.

Both fields are set together, once the user has completed the upgrade. Before that, and for users who have never been upgraded, both are `undefined`; the two cases are indistinguishable from context alone.

```ts theme={null}
import { sdk } from '@farcaster/miniapp-sdk'

const context = await sdk.context
const legacyAddress = context.startale?.legacyAddress
const legacySignature = context.startale?.legacySignature

if (legacyAddress) {
  // The user has upgraded. legacyAddress was their smart account address
  // before the upgrade; the current address is still the one returned by
  // eth_requestAccounts.
}
```

> [!WARNING]
>
> `legacyAddress` is reported by the client SDK, like the rest of `sdk.context`. Do not trust it for a privileged operation, such as crediting a balance or transferring a paid entitlement, without verifying `legacySignature` first.

> [!WARNING]
>
> `legacyAddress` is not guaranteed to be checksummed ([EIP-55](https://eips.ethereum.org/EIPS/eip-55)). Compare it case-insensitively, for example by lowercasing both sides, instead of with a strict string equality check against an address you already have on file in a different casing.

## Verifying the legacy signature

`legacySignature` is a signature produced by the smart account at `legacyAddress`, over the current smart account address lowercased to a plain string. It certifies that the legacy account itself approved the current account as its successor. Verify it the same way you verify any Startale smart-account signature, see [Sign messages](https://docs.startale.com/app-sdk/sign-messages.md): with viem's `verifyMessage`, which resolves EOA, ERC-1271, and [ERC-6492](https://eips.ethereum.org/EIPS/eip-6492) signatures automatically.

```ts theme={null}
import { createPublicClient, http } from 'viem'
import { soneium } from 'viem/chains'

const publicClient = createPublicClient({ chain: soneium, transport: http() })

async function verifyLegacyAddress(
  legacyAddress: string,
  legacySignature: string,
  currentAddress: string,
) {
  return publicClient.verifyMessage({
    address: legacyAddress as `0x${string}`,
    message: currentAddress.toLowerCase(),
    signature: legacySignature as `0x${string}`,
  })
}
```

Reject the mapping unless all of the following hold: `legacyAddress` and `legacySignature` are both present, `verifyMessage` returns `true`, and the address you passed as `currentAddress` is the one you independently obtained from `eth_requestAccounts`, not a value read from context.

[Reference verification snippet](https://gist.github.com/JGJP/2f0a0cd55b66f04206d3d1c2adf739ae)

## Sandbox simulation gap

The Mini App sandbox simulates `sdk.context.startale.starPoints` as `100` and populates `location`, `client.platformType`, and `client.safeAreaInsets` with default values. `sdk.context.startale.eoaWallets`, `sdk.context.startale.language`, `user`, and `features` are not populated.

Test EOA-discovery features, identity-dependent logic, and capability checks against a staging or production Startale App, not the local sandbox.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.