0.1.14 • Published 9 months ago

@cliqueofficial/clique-client-sdk-web v0.1.14

Weekly downloads
-
License
-
Repository
-
Last release
9 months ago

Clique Client SDK

The Clique Client SDK is an open-source library that enables users to interact with the Clique Network. We currently support Rust, NodeJS, and Web.

Clique Query

Clique supports JSON-RPC-styled queries.

Fielddescriptionrequired
idUnique query IDYes
methodTask nameYes
paramsTask inputYes
inputTypesTask input typesYes
customTypesTask custom typesNo

How to use

Add this dependency to your package.json:

pnpm add @cliqueofficial/clique-client-sdk-web
# OR
yarn add @cliqueofficial/clique-client-sdk-web
# OR 
npm install @cliqueofficial/clique-client-sdk-web 
import { Client } from '@cliqueofficial/clique-client-sdk-web';

const client = new Client({ 
  endpoint: 'http://localhost:8000', 
  pollingInterval: 20, // default value is 20 ms
  retryNumber: 5,  // default value is 5
  allowExistQuery: false, // default value is false. If the user creates a query with the same id, method, and params, the client will return the result of the existing query when the value is true; otherwise, the client will throw an exception.
  trustedEnclaves: ['5d474d0e8b431764ddf3db67b1028399d42301340ceb4abc840c4dee426e0d9d'], // default is undefined. Trusted mr_enclaves of clique-kernel, if the value is undefined, all mr_enclaves will be trusted.
  trustedSigners: ['6601c448087c060907a3c71f1c10fbae92260bef8ac37258b2314338042dadb4'], // default is undefined. Trusted mr_signers of clique-kernel, if the value is undefined, all mr_signers will be trusted.
});

// Create single query
const query = {
  id: 1,
  method: 'clique_fibonacci',
  params: { n: '10' },
  inputTypes: { n: 'u256' },
};
// OR batch query
const query = [
  {
    id: 2,
    method: 'clique_fibonacci',
    params: { n: '11' },
    inputTypes: { n: 'u256' },
  },
  {
    id: 3,
    method: 'clique_fibonacci',
    params: { n: '12' },
    inputTypes: { n: 'u256' },
  },
];

// Run the query and wait for the result
const response = await client.runQuery(query);
console.log("runQuery response:", response);

// OR run the query with encryption enabled and wait for the result
const response = await client.runEncryptedQuery(query);
console.log("runEncryptedQuery response:", response);