Hook for accessing values from the TreasureProvider context.

Usage

import { useTreasure } from "@treasure-dev/tdk-react";

function App() {
  const { user } = useTreasure();
  return (
    <>
      {user ? `Logged in as ${user.smartAccountAddress}` : "Not logged in"}
    </>
  );
}

Return Type

chain

Chain

  • The currently selected chain with chain details.

contractAddresses

Record<Contract, AddressString>

  • Contract address mapping for the currently selected chain.

tdk

TDKAPI

  • The client for interacting with the TDK API.

thirdwebClient

ThirdwebClient

user

User | undefined

  • The logged in user, if any.

isConnecting

boolean

  • True if the user is actively connecting, whether explicitly or in the background.

logIn

(wallet: Wallet) => void

  • Log in a new user with an active wallet and start a new session.

logOut

() => void

  • Log out and disconnect the current user.

startUserSession

(options: SessionOptions) => void

  • Start a new session with the current user.
  • Useful for chain switching or changing the list or approved target contract addresses during a user’s session.