LogoLogo
  • Sign Protocol
    • Introduction
    • FAQ
  • For Hackers
    • Getting Started
  • For Builders
    • Getting Started
      • Fundamentals
      • Tutorials
        • Building a Simple Notary Platform
          • Schema Creation
          • Attestation Creation
          • Querying Attestations
          • Parsing Attestation Data
        • Delegate Attestation Creation
          • Express Backend
          • Solidity
      • Examples
        • Attestation Discord Bot
        • KYC-Gated Smart Contract Access Control
    • Supported Networks
    • Sign Developer Platform
    • Advanced Topics
      • Cross Chain Attestations
      • Hybrid Attestations
      • Schema Hooks
        • Tutorial: Checking Attestation Data
          • Schema Creation
          • Schema Hook
          • Creating an Attestation (Solidity)
      • ZK Attestations
        • Compile a Circuit
        • Create a Schema Hook
    • Querying Data
      • NPM SDK
        • Usage & Examples
      • REST APIs
        • Schemas
        • Attestations
      • GraphQL
        • Schemas
        • Attestations
    • Writing Data
      • NPM SDK
        • Installation
        • Usage
          • Schemas
          • Attestations
        • Examples
        • Changelog
      • Smart Contract
        • EVM
          • Interfaces
            • ISP
            • ISPHook
            • IVersionable
          • Data Models
            • Schema
            • Attestation
            • DataLocation
  • For Thinkers
    • A Future Of Verifiable Trust
    • Effective Attestations
    • Incentive-Aligned Public Good
    • Glossary
      • Attestations
      • Schema
      • Schema Registry
      • Attestation Repository
  • Case Study
    • EthSign
    • KYC-Gated Contract Calls
    • Proof of Audit
    • Developer Onchain Reputation
    • Onboarding Web2 Data
Powered by GitBook
LogoLogo

Copyright Sign 2021-2024

On this page
  • On-chain Mode
  • Off-chain (Arweave) Mode

Was this helpful?

  1. For Builders
  2. Writing Data
  3. NPM SDK

Examples

On-chain Mode

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

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",
});
PreviousAttestationsNextChangelog

Last updated 2 months ago

Was this helpful?