@windingtree/sdk-node-api
TypeScript icon, indicating that this package has built-in type declarations

1.7.4 • Public • Published

@windingtree/sdk-node-api

The WindingTree market protocol node API server and client. This SDK provides a client and server implementation for communication with the WindingTree Market Protocol Node. This API allows to implement the protocol node management. For the implementation detail please see the node manager app example.

Installation

pnpm i @windingtree/sdk-node-api

Key concepts

This SDK is designed to work with the WindingTree Market Protocol and includes several core components:

  • Routers: These modules define the procedures for user management, admin management, and deal management. Procedures include registration, login, logout, delete, update, checkIn, and checkOut actions, among others.
  • Server: The server module sets up an API server that uses the defined routers to handle requests.
  • Client: The client module provides utilities for creating EIP-712 signatures for certain operations and middleware functions for tRPC link operations.
  • Constants: This module exports various constants used across the SDK, such as the access token name and the typed domain for admin signature.
  • Utils: This module exports a schema used for pagination in query inputs.

Usage

The package exports a NodeApiServer class that can be used to set up an API server that interacts with the WindingTree Market Protocol. The server uses tRPC, an end-to-end typesafe RPC framework, allowing for easy interaction with clients.

import { NodeApiServer } from '@windingtree/sdk-node-api/server';
import { appRouter } from '@windingtree/sdk-node-api/router';
import { ProtocolContracts } from '@windingtree/sdk-contracts-manager';
import { memoryStorage } from '@windingtree/sdk-storage';

// Initialize your ProtocolContracts, Node, and other components here...
const contractsManager = new ProtocolContracts({...});

const usersStorage = await memoryStorage.createInitializer({
  scope: 'users',
})();
const dealsStorage = await memoryStorage.createInitializer({
  scope: 'deals',
})();

const apiServer = new NodeApiServer({
  usersStorage,
  dealsStorage,
  prefix: 'my-prefix',
  port: 3000,
  secret: 'my-secret',
  ownerAccount: entityOwnerAddress,
  protocolContracts: contractsManager,
});

apiServer.start(appRouter);

// Handle incoming requests and perform necessary actions here...

Here's a simple example (React) of using the @windingtree/sdk-node-api/client:

import { createAdminSignature } from '@windingtree/sdk-node-api/client';
import { useNode, useWallet } from '@windingtree/sdk-react/providers';

// Your code to setup the WindingTree Wallet goes here. Assuming you have a `walletClient` object in the app component.
const { walletClient } = useWallet();
const { node } = useNode();

const handleAdminRegister = async (name: string) => {
  try {
    const signature = await createAdminSignature(walletClient);

    await node.admin.register.mutate({
      login: name,
      password: signature,
    });
  } catch (error) {
    console.error('Error admin register:', error);
  }
};

handleAdminRegister();

Documentation

For full documentation and examples, visit windingtree.github.io/sdk

Testing

pnpm test

Contributing

Contribution guidelines

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.7.40latest
1.5.1-beta.01beta

Version History

VersionDownloads (Last 7 Days)Published
1.7.40
1.7.30
1.7.20
1.7.10
1.7.00
1.6.10
1.6.00
1.5.70
1.5.62
1.5.51
1.5.41
1.5.31
1.5.21
1.5.11
1.5.1-beta.01
1.5.01
1.4.01
1.3.41
1.3.31
1.3.21
1.3.11
1.3.00
1.2.255
1.2.145
1.2.02
1.2.0-beta.01
1.1.1-beta.01
1.1.00
1.1.0-beta.30
1.1.0-beta.20
1.1.0-beta.10
1.1.0-beta.00

Package Sidebar

Install

npm i @windingtree/sdk-node-api

Weekly Downloads

1

Version

1.7.4

License

MIT

Unpacked Size

271 kB

Total Files

41

Last publish

Collaborators

  • kostysh
  • kvakes
  • tomashq