npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mysten/dapp-kit

v0.14.29

Published

A collection of React hooks and components for interacting with the Sui blockchain and wallets.

Downloads

12,423

Readme

Sui dApp Kit

The Sui dApp Kit is a set of React components, hooks, and utilities that make it easy to build a dApp for the Sui ecosystem. It provides hooks and components for querying data from the Sui blockchain, and connecting to Sui wallets.

See https://sdk.mystenlabs.com/typescript for full documentation

Core Features

  • Query Hooks: dApp Kit provides a set of hooks for making rpc calls to the Sui blockchain, making it easy to load any information needed for your dApp.
  • Automatic Wallet State Management: dApp Kit removes the complexity of state management related to wallet connections. You can focus on building your dApp.
  • Supports all Sui wallets: No need to manually define wallets you support. All Sui wallets are automatically supported.
  • Easy to integrate: dApp Kit provides pre-built React Components that you can drop right into your dApp, for easier integration
  • Flexible: dApp Kit ships both fully functional React Component, and lower level hooks that you can use to build your own custom components.

Install from NPM

To use the Sui dApp Kit in your project, run the following command in your project root:

npm i --save @mysten/dapp-kit @mysten/sui @tanstack/react-query

Setting up providers

To be able to use the hooks and components in the dApp Kit, you need to wrap your app with a couple providers. The props available on the providers are covered in more detail in their respective docs pages.

import { createNetworkConfig, SuiClientProvider, WalletProvider } from '@mysten/dapp-kit';
import { getFullnodeUrl, type SuiClientOptions } from '@mysten/sui/client';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';

// Config options for the networks you want to connect to
const { networkConfig } = createNetworkConfig({
	localnet: { url: getFullnodeUrl('localnet') },
	mainnet: { url: getFullnodeUrl('mainnet') },
});
const queryClient = new QueryClient();

function App() {
	return (
		<QueryClientProvider client={queryClient}>
			<SuiClientProvider networks={networkConfig} defaultNetwork="localnet">
				<WalletProvider>
					<YourApp />
				</WalletProvider>
			</SuiClientProvider>
		</QueryClientProvider>
	);
}

Using UI components to connect to a wallet

The dApp Kit provides a set of flexible UI components that can be used to connect and manage wallet accounts from your dApp. The components are built on top of Radix UI and are customizable so you can quickly get your dApp up and running.

To use our provided UI components, you will need to import the dApp Kit's CSS stylesheet into your dApp as shown below. For more information regarding customization options, check out the respective documentation pages for the components and themes.

import '@mysten/dapp-kit/dist/index.css';

Using hooks to make RPC calls

The dApp Kit provides a set of hooks for making RPC calls to the Sui blockchain. The hooks are thin wrappers around useQuery from @tanstack/react-query. For more comprehensive documentation on how these query hooks can be used, check out the react-query docs.

import { useSuiClientQuery } from '@mysten/dapp-kit';

function MyComponent() {
	const { data, isPending, error, refetch } = useSuiClientQuery('getOwnedObjects', {
		owner: '0x123',
	});

	if (isPending) {
		return <div>Loading...</div>;
	}

	return <pre>{JSON.stringify(data, null, 2)}</pre>;
}