# Examples

### On-chain Mode

```tsx
import {
  SignProtocolClient,
  SpMode,
  EvmChains,
  delegateSignAttestation,
  delegateSignRevokeAttestation,
  delegateSignSchema,
} from "@ethsign/sp-sdk";
import { privateKeyToAccount } from "viem/accounts";
const privateKey = "0xabc"; // Optional

const client = new SignProtocolClient(SpMode.OnChain, {
  chain: EvmChains.polygonMumbai,
  account: privateKeyToAccount(privateKey), // Optional if you are using an injected provider
  apiKey: 'xxx', // Optional, from https://developer.sign.global/
});

// Create schema
const createSchemaRes = await client.createSchema({
  name: "xxx",
  data: [{ name: "name", type: "string" }],
});

// Delegated create schema
const delegationPrivateKey = "0xaaaaa";
const info = await delegateSignSchema(
  {
    name: "xxx",
    data: [{ name: "name", type: "string" }],
  },
  {
    chain: EvmChains.sepolia,
    delegationAccount: privateKeyToAccount(delegationPrivateKey),
  }
);
const delegateCreateSchemaRes = await client.createSchema(info.schema, {
  delegationSignature: info.delegationSignature,
});

// Create attestation
const createAttestationRes = await client.createAttestation({
  schemaId: "0x3",
  data: { name: "a" },
  indexingValue: "xxx",
});

// Delegated create attestation
const delegationPrivateKey = "0xaaaaa";
const info = await delegateSignAttestation(
  {
    schemaId: "0x1",
    data: { name: "a" },
    indexingValue: "xxx",
  },
  {
    chain: EvmChains.sepolia,
    delegationAccount: privateKeyToAccount(delegationPrivateKey),
  }
);

const delegationCreateAttestationRes = await client.createAttestation(
  info.attestation,
  {
    delegationSignature: info.delegationSignature,
  }
);

// Revoke attestation
const revokeAttestationRes = await client.revokeAttestation("0x3", {
  reason: "test",
});

// Delegated revoke attestation
const delegationPrivateKey = "0xaaaaa";
const info = await delegateSignRevokeAttestation(attestationId, {
  chain: EvmChains.sepolia,
  reason: "test",
  delegationAccount: privateKeyToAccount(delegationPrivateKey),
});
const delegationRevokeAttestationRes = await client.revokeAttestation(
  info.attestationId,
  {
    reason: info.reason,
    delegationSignature: info.delegationSignature,
  }
);
```

### Off-chain (Arweave) Mode

```tsx
import {
  SignProtocolClient,
  SpMode,
  EvmChains,
  OffChainSignType,
} from "@ethsign/sp-sdk";
import { privateKeyToAccount } from "viem/accounts";
const privateKey = "0xabc"; // Optional
const client = new SignProtocolClient(SpMode.OffChain, {
  signType: OffChainSignType.EvmEip712,
  account: privateKeyToAccount(privateKey), // Optional
  apiKey: 'xxx', // Required, from https://developer.sign.global/
});

// Create schema
const schemaInfo = await client.createSchema({
  name: "xxx",
  data: [{ name: "name", type: "string" }],
});

// Create attestation
const attestationInfo = await client.createAttestation({
  schemaId: "xxxx", // `schemaInfo.schemaId` or other `schemaId`
  data: { name: "a" },
  indexingValue: "xxx",
});

// Revoke attestation
const attestationId = "xxx";
const revokeAttestationRes = await client.revokeAttestation(attestationId, {
  reason: "test",
});
```


---

# Agent Instructions: 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:

```
GET https://docs.sign.global/for-builders/index-1/npm-sdk/examples.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
