Usage

Treasure Connect

To get started with Treasure Connect and allow users to log into their Treasure Accounts, only a few configuration options are required

import { treasureTopaz } from "@treasure-dev/tdk-core";
import { ConnectButton, TreasureProvider } from "@treasure-dev/tdk-react";
import { ThirdwebProvider } from "thirdweb/react";

function App() {
  return (
    <ThirdwebProvider>
      <TreasureProvider
        appName="Treasure"
        apiUri="https://tdk-api.spellcaster.lol"
        defaultChainId={treasureTopaz.id}
        clientId="..."
        ecosystemId="ecosystem.treasure-dev"
        ecosystemPartnerId="..."
      >
        <ConnectButton />
      </TreasureProvider>
    </ThirdwebProvider>
  );
}

Enable backend transactions

To start on-chain sessions for your users that can enable the sending of backend transations, sessionOptions and a backendWallet must be provided:

import { TreasureProvider } from "@treasure-dev/tdk-react";
import { ThirdwebProvider } from "thirdweb/react";

function App() {
  return (
    <ThirdwebProvider>
      <TreasureProvider
        ...
        sessionOptions={{
          backendWallet: "...",
          approvedTargets: [
            "0x55d0cf68a1afe0932aff6f36c87efa703508191c",
          ],
        }}
      >
        <ConnectButton />
      </TreasureProvider>
    </ThirdwebProvider>
  );
}

Props

appName

string

  • The name of the application, used in the connect modal flow.

appIconUri

string | undefined

  • An icon URI for the application, used in the connect modal flow.

autoConnectTimeout

number | undefined

  • Time in milliseconds to wait before the wallet auto-connect feature times out.
  • Defaults to 5_000 (5 seconds).

language

"en" | "es" | "ja" | "ru" | undefined

  • Language to use for UI elements.
  • Defaults to the user’s browser language, if supported. Otherwise, falls back to “en”.

apiUri

string | undefined

  • The TDK API URI to use for all HTTP requests.
  • Defaults to "https://tdk-api.treasure.lol".
  • Development environment value is "https://tdk-api.spellcaster.lol".

defaultChainId

number | undefined

  • The chain ID to use for initial connection.
  • Defaults to 42161 (Arbitrum One).

clientId

string

ecosystemId

string | undefined

  • The ecosystem ID for the ecosystem wallets.
  • Defaults to "ecosystem.treasure".
  • Development environment value is "ecosystem.treasure-dev".

ecosystemPartnerId

string

  • The ecosystem partner ID for the ecosystem wallets.

sessionOptions

SessionOptions | undefined

  • Options for creating user sessions, if using account abstraction.

backendWallet

string | undefined

approvedTargets

string[] | undefined

  • List of contract addresses that should be approved for interaction via the TDK API during the user’s session. Leave blank if no contract interactions are needed.

nativeTokenLimitPerTransaction

bigint | undefined

  • Maximum amount of native token that can be transferred in a single transaction, specified in wei. Leave blank if no native token transfers are needed besides gas fees.

sessionDurationSec

number | undefined

  • Duration of the user session, in seconds.
  • Defaults to 86,400 (24 hours).

sessionMinDurationLeftSec

number | undefined

  • Minimum duration left in the user session, in seconds, before the user is prompted to extend their session.
  • Defaults to 3,600 (1 hour).