> For the complete documentation index, see [llms.txt](https://docs.sign.global/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sign.global/for-builders/index-1/npm-sdk/usage/schemas.md).

# Schemas

## Types

### Schema (Onchain)

| Name          | Type                       | Description                                                                                                                                                              |
| ------------- | -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| name          | `string`                   | Schema name.                                                                                                                                                             |
| description?  | `string`                   | Schema description.                                                                                                                                                      |
| revocable?    | `boolean`                  | Whether Attestations that adopt this Schema can be revoked.                                                                                                              |
| maxValidFor?  | `number`                   | The maximum number of seconds that an Attestation can remain valid. 0 means Attestations can be valid forever. This is enforced through `Attestation.validUntil`.        |
| hook?         | `address`                  | The contract address of the hook for this schema.                                                                                                                        |
| registrant    | `address`                  | The wallet address of the user that registered this schema.                                                                                                              |
| dataLocation? | `DataLocationOnChain`      | Where `Schema.data` is stored. See `DataLocation.DataLocation`.                                                                                                          |
| data          | `SchemaItem[]` or `string` | The data format defining this schema's data structure. When `dataLocation=ONCHAIN`, data is `SchemaItem[]`, when `dataLocation=ARWEAVE or IPFS`, data is id of the data. |

### Schema (Offchain)

| Name          | Type                   | Description                                                                                                                                                       |
| ------------- | ---------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| name          | `string`               | Schema name.                                                                                                                                                      |
| description?  | `string`               | Schema description.                                                                                                                                               |
| revocable?    | `boolean`              | Whether Attestations that adopt this Schema can be revoked.                                                                                                       |
| maxValidFor?  | `number`               | The maximum number of seconds that an Attestation can remain valid. 0 means Attestations can be valid forever. This is enforced through `Attestation.validUntil`. |
| dataLocation? | `DataLocationOffChain` | Where `Schema.data` is stored. See `DataLocation.DataLocation`.                                                                                                   |
| data          | `SchemaItem[]`         | The data format defining this schema's data structure.                                                                                                            |

## Usage

### Registering a Schema

```ts
async function createSchema(
  schema: Schema,
  options?: { getTxHash?: (txHash: `0x${string}`) => void }
): Promise<SchemaResult>;
```

#### Parameters

| Name     | Type                  | Description                    |
| -------- | --------------------- | ------------------------------ |
| schema   | `Schema`              | The schema being registered.   |
| options? | `CreateSchemaOptions` | Options for creating a schema. |

#### CreateSchemaOptions

| Name                 | Type                                | Description                                                                                                           |
| -------------------- | ----------------------------------- | --------------------------------------------------------------------------------------------------------------------- |
| delegationSignature? | string                              | The user's delegate signature for creating a schema on their behalf. Call `delegateSignSchema` to get this signature. |
| getTxHash?           | ``(txHash: `0x${string}`) => void`` | An optional callback that immediately returns the transaction hash.                                                   |

#### Example

```typescript
const res = await client.createSchema({
  name: "Example",
  data: [{ name: "name", type: "string" }],
});
```

### Retrieving a Schema

```ts
async function getSchema(schemaId: string): Promise<Schema>;
```

#### Parameters

| Name     | Type     | Description                                     |
| -------- | -------- | ----------------------------------------------- |
| schemaId | `string` | The ID of the schema we are trying to retrieve. |

#### Example

```typescript
const res = await client.getSchema("0x3e");
```

### Delegating On-chain Schema Registration via ECDSA

```ts
async function delegateSignSchema(
  schema: OnChainSchema,
  options: DelegateSignSchemaOptions
): Promise<SchemaDelegationSignature>;
```

#### Parameters

| Name    | Type                        | Description                              |
| ------- | --------------------------- | ---------------------------------------- |
| schema  | `OnChainSchema`             | An on-chain schema.                      |
| options | `DelegateSignSchemaOptions` | Options for delegate signing the schema. |

#### DelegateSignSchemaOptions

| Name               | Type                |                                                                                                                                |
| ------------------ | ------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
| chain              | `EvmChains`         | The EVM chain you are targetting.                                                                                              |
| delegationAccount? | `PrivateKeyAccount` | The signer account that signs the message. See `viem/accounts`. If this is null, a signer from `window.ethereum` will be used. |
| rpcUrl?            | `string`            | Optional RPC URL.                                                                                                              |
| walletClient?      | `WalletClient`      | Optional `WalletClient` from viem to use for transactions.                                                                     |


---

# 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.sign.global/for-builders/index-1/npm-sdk/usage/schemas.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.
