Installation

Quick Start

Connect to Treasure Account

Call the logIn function to connect to the Treasure Account and start a user session.

Connect with email

Connect a user wallet based on email address and one-time password sent to that email.

When using the core package, applications must implement their own interfaces for logging in to the Treasure Account, including the multistep verification code flow for logging in with email.

import {
  createTreasureConnectClient,
  logIn,
  sendEmailVerificationCode,
} from "@treasure-dev/tdk-core";

const client = createTreasureConnectClient({ clientId: "..." });
const ecosystemId = "ecosystem.treasure-dev";
const ecosystemPartnerId = "...";
const email = "example@treasure.lol";

await sendEmailVerificationCode({
  client,
  email,
  ecosystemId,
  ecosystemPartnerId,
});

// Check email...

const { user, tdk } = await logIn({
  client,
  ecosystemId,
  ecosystemPartnerId,
  method: "email",
  email,
  verificationCode: "123456",
  apiUri: "https://tdk-api.spellcaster.lol",
  chainId: 421614,
  sessionOptions: {
    backendWallet: "...",
    approvedTargets: ["0x55d0cf68a1afe0932aff6f36c87efa703508191c"],
  },
});

Connect with social

Connect a user wallet with one of the support social login options.

import { createTreasureConnectClient, logIn } from "@treasure-dev/tdk-core";

const client = createTreasureConnectClient({ clientId: "..." });

const { user, tdk } = await logIn({
  client,
  ecosystemId: "ecosystem.treasure-dev",
  ecosystemPartnerId: "...",
  method: "google",
  apiUri: "https://tdk-api.spellcaster.lol",
  chainId: 421614,
  sessionOptions: {
    backendWallet: "...",
    approvedTargets: ["0x55d0cf68a1afe0932aff6f36c87efa703508191c"],
  },
});

Connect with custom auth

Connect a user wallet with a custom auth endpoint and allow compatibility with existing authentication systems. Please contact the Treasure team to enable this feature for your project.

import { createTreasureConnectClient, logIn } from "@treasure-dev/tdk-core";

const client = createTreasureConnectClient({ clientId: "..." });

const { user, tdk } = await logIn({
  client,
  ecosystemId: "ecosystem.treasure-dev",
  ecosystemPartnerId: "...",
  method: "auth_endpoint",
  payload: JSON.stringify({
    wanderersToken: "...",
  }),
  apiUri: "https://tdk-api.spellcaster.lol",
  chainId: 421614,
  sessionOptions: {
    backendWallet: "...",
    approvedTargets: ["0x55d0cf68a1afe0932aff6f36c87efa703508191c"],
  },
});

See the logIn docs for more configuration options.

Ecosystem game partners should contact Treasure to obtain values for clientId, ecosystemId, ecosystemPartnerId and backendWallet.

Call contract write

After starting a user session with approved target contract addresses, you can now use the TDKAPI object to call contract writes:

import { logIn } from "@treasure-dev/tdk-core";
import type { AddressString } from "@treasure-dev/tdk-core";

const { user, tdk } = await logIn({ ... });

await tdk.transaction.create(
  {
    address: "0x55d0cf68a1afe0932aff6f36c87efa703508191c",
    abi: [
      {
        inputs: [
          {
            internalType: "address",
            name: "_to",
            type: "address",
          },
          {
            internalType: "uint256",
            name: "_amount",
            type: "uint256",
          },
        ],
        name: "mint",
        outputs: [],
        stateMutability: "nonpayable",
        type: "function",
      },
    ] as const,
    functionName: "mint",
    args: [
      user.address as AddressString,
      1000000000000000000000n, // 1,000
    ],
  },
  { includeAbi: true },
);

See the connect-core example application for the full end-to-end source code.

Current Features