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

react-koinos-toolkit

v0.3.0

Published

Reusable React components for common, Koinos-specific dApp needs

Downloads

12

Readme

react-koinos-toolkit

Reusable React components for common, Koinos-specific dApp needs

Koinos Logo React Logo

Quick Start

Your dApp is going to need a way for users to connect their wallet. By including this package and setting up the KoinosAccountProvider and KoinosAccountConnector you get the following experience:

Before connecting: disconnected closed component Click to open -> disconnected open component

After connecting: connected closed component Click to open -> connected open component

KoinosAccountProvider

In your root app component, set up the provider like so:

import { KoinosAccountProvider } from "react-koinos-toolkit";

function App() {
    return (
        <KoinosAccountProvider
            defaultRpcUrl={KOINOS_RPC}
            kapNameServiceAddress={KAP_NAME_SERVICE_ADDRESS}
            kapProfileAddress={KAP_PROFILE_ADDRESS}
        >
            your app components
        </KoinosAccountProvider>
    )
}

For Koinos mainnet, use the following variables:

KOINOS_RPC=https://api.koinos.io
KAP_NAME_SERVICE_ADDRESS=13tmzDmfqCsbYT26C4CmKxq86d33senqH3
KAP_PROFILE_ADDRESS=1EttfMuvTXGh8oE6vLiRF5JfqBvRiofFkB

Note: You will need a koinos.pro RPC URL once the above API node is deprecated.

KoinosAccountConnector

import { KoinosAccountConnector } from "react-koinos-toolkit";

function Header() {
    return (
        <KoinosAccountConnector sitePreferences={<MySitePreferencesComponent />} />
    )
}

For this setup, you can configure a light/dark theme toggle, or any other components you may want to show up under the --- site preferences --- divider in the connected dropdown.

useAccount

You will probably need to get the address of the connected wallet somewhere in your site. You'll use the useAccount hook to accomplish this.

import { useAccount } from "react-koinos-toolkit";

function MyComponent() {
    const { address, signer, provider } = useAccount();
}

You can do this from anywhere inside a child of the KoinosAccountProvider. For reference:

  • address is the address of the connected wallet
  • signer and provider can be used to talk to the blockchain without needing to know which wallet is being used.

For example, if you want to call a contract entry point using koilib, you'd set it up like so:

import { useAccount } from "react-koinos-toolkit";
import { Contract } from "koilib";

function MyNftMinter() {
    const { address, signer, provider } = useAccount();
    const nftContract = new Contract({
        id: "address of your NFT",
        abi: nftAbi,
        provider,
        signer
    });
    const mint = async (mintParams) => (
        await nftContract.functions.mint(mintParams)
    );
    // return some button that mints on click
}

Supported Wallets

For the moment, react-koinos-toolkit only supports Kondor and MKW.

This will be updated to support Portal and Konio in the near future. Additional wallets will be considered. If you want to request support for another wallet, please open an issue on this repository.

Package Weight, Theming, and TypeScript

This package has not been optimized yet, so it's heavier than it needs to be. It currently depends on Chakra UI, which is a great UI library, but I would like to remove the dependency in a future update.

If you want to override the styles of the connector, you can place your own ChakraProvider with your own theming inside the KoinosAccountProvider.

<KoinosAccountProvider>
    <ChakraProvider theme={myTheme}>
        KoinosAccountConnector and your own components go in here
    </ChakraProvider>
</KoinosAccountProvider>

Types have not been generated for this project yet, so if you're using TypeScript, you may need to import with an @ts-ignore comment.

import {
  KoinosAccountProvider,
  // @ts-ignore
} from "react-koinos-toolkit";