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

@tezos-il/tezos-react-hooks

v0.0.9

Published

A react library to use tezos in your app

Downloads

13

Readme

Tezos-hooks

All Contributors

Provides react hooks for Tezos Taquito (and Beacon)

How to install

For now, this library requires your dapp to use typescript. In the near future we will make it available for all users. We're also, for now, requiring you use @taquito/taquito and @taquito/beacon-wallet

Run:

# for yarn users
yarn add @tezos-il/tezos-react-hooks @taquito/taquito @taquito/beacon-wallet

# for npm users
npm i @tezos-il/tezos-react-hooks @taquito/taquito @taquito/beacon-wallet

How to use

just import the required hook into your app:

import {TezosContextProvider, useTezosContext, useBeaconWallet, useContract, useBalance} from `@tezos-il/tezos-react-hooks`

TezosContext

We're providing a context provider/hook pair that is required for all of our hooks. The way to use it this:

Usually you'll want to configure the Tezos object you get from taquito. Otherwise we supply a default that connects to mainnet on https://mainnet.smartpy.io

Wrap the components where you use the tezos hooks with TezosContextProvider - usually you do this in your root component.

import {TezosToolkit} from '@taquito/taquito'
import {TezosContextProvider} from '@tezos-il/tezos-react-hooks'

const tezos = new TezosToolkit()

// configure tezos here

<TezosContextProvider tezos={tezos}>
    <App />
</TezosContextProvider>

and inside your app you can use the hooks useBeaconWallet, useBalance, useContract which use this tezos object, or you can get this object by using useTezosContext:

import {useTezosContext} from '@tezos-il/tezos-react-hooks'

function Component() {
    const {tezos} = useTezosContext()
    ...
}

useBeaconWallet

This example will connect to the wallet automatically and will show the address once connected:

import {useEffect}, React from 'react'
import {useBeaconWallet} from '@tezos-il/tezos-react-hooks'

function App() {
    const {
        wallet, // the wallet object returned from taquito
        initialized, // true iff the wallet is initialized
        address, // null when wallet is not initialized, otherwise it's the wallet's address
        connect, //call this function with DAppClientOptions to connect to a beacon wallet
        loading, // true when wallet is loading
        balance, // holds the account's balance (for now it's not reactive)
        error, // string, not empty when there's an error
        clearErrors // can be called to clear the error
    } = useBeaconWallet()

    useEffect(() => {
        connect()
    }, [])

    return <div>{balance}</div>
}

Expose other utility values as error, loading, initialized

useContract

import {useEffect}, React from 'react'
import {useContract} from '@tezos-il/tezos-react-hooks'

function App() {
  const {
    contract, // WalletContract object
    error,
    storage, // contract storage
    loading,
    connect, // a function to connect to the contract
    clearError
  } = useContract(CONTRACT_ADDRESS)
  ...
}

By calling connect with a valid contract address the contract object will be a WalletContract. Using this object you can call an entrypoint by calling contract.methods.entrypoint().send(). This is just a simple example, you can see more in Taquito docs.

useBalance

import {useEffect}, React from 'react'
import {useBalance} from '@tezos-il/tezos-react-hooks'

function App() {
  const {
    balance, // the balance of ACCOUNT_ADDRESS (mutes)
    error,
    loading,
    clearError,
    balanceInTez // a function to get `balance` in tez
  } = useBalance(ACCOUNT_ADDRESS)
...
}

Contributors ✨

Thanks goes to these wonderful people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!