1.4.17 • Published 5 months ago

@windingtree/sdk-react v1.4.17

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

@windingtree/sdk-react

This package provides a collection of React context providers and hooks that abstract the interaction with the Winding Tree SDK and blockchain related functionality.

Installation

pnpm i @windingtree/sdk-react

Key concepts

The package consists of several main elements:

  • ConfigProvider: Manages the application's configuration stored in local storage.
  • ContractsProvider: Utilizes the @windingtree/sdk-contracts-manager package to manage the application's contracts.
  • NodeProvider: Connects to the Winding Tree Node using a TRPC client, provided by the @trpc/client package.
  • WalletProvider: Uses the viem library to interact with the user's wallet (such as MetaMask) and manage the wallet state.

All these providers are designed to be used with React's Context API, providing a simple and idiomatic way to use Winding Tree SDK with a React application.

Usage

The providers can be imported directly from the package:

import { createRoot } from 'react-dom/client';
import { Hash } from 'viem';
import { App } from './App.js';
import {
  ConfigProvider,
  NodeProvider,
  WalletProvider,
  ContractsProvider,
} from '@windingtree/sdk-react/providers';
import { polygonZkEvmTestnet } from 'viem/chains';
import { contractsConfig } from 'wtmp-examples-shared-files/dist/index.js';

const root = createRoot(document.getElementById('root') as HTMLElement);
root.render(
  <ConfigProvider>
    <NodeProvider>
      <WalletProvider targetChain={polygonZkEvmTestnet}>
        <ContractsProvider contractsConfig={contractsConfig}>
          <App />
        </ContractsProvider>
      </WalletProvider>
    </NodeProvider>
  </ConfigProvider>,
);

Then these providers can be used inside components:

import {
  useConfig,
  useNode,
  useWallet,
} from '@windingtree/sdk-react/providers';

export const Widget = () => {
  const { isAuth, login, setAuth, resetAuth } = useConfig();
  const { node, nodeConnected } = useNode();
  const { isConnected, walletClient } = useWallet();
  /** ... */
};

Documentation

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

Testing

pnpm test

Contributing

Contribution guidelines

1.4.17

5 months ago

1.4.16

6 months ago

1.4.15

7 months ago

1.4.14

7 months ago

1.4.13

7 months ago

1.4.12

7 months ago

1.4.11

7 months ago

1.4.10

7 months ago

1.4.9

7 months ago

1.4.8

7 months ago

1.4.6

7 months ago

1.4.7

7 months ago

1.4.5

8 months ago

1.4.4

8 months ago

1.4.3

8 months ago

1.4.2

8 months ago

1.4.1

8 months ago

1.4.1-beta.0

8 months ago

1.4.0

9 months ago

1.3.5

9 months ago

1.3.4

9 months ago

1.3.3

9 months ago

1.3.2

9 months ago

1.3.1

9 months ago

1.3.0

10 months ago

1.2.2

11 months ago

1.2.1

11 months ago

1.2.0

11 months ago

1.2.0-beta.0

11 months ago

1.1.1-beta.0

1 year ago

1.1.0

1 year ago

1.1.0-beta.3

1 year ago

1.1.0-beta.2

1 year ago

1.1.0-beta.1

1 year ago

1.1.0-beta.0

1 year ago