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 email = "example@treasure.lol";
await sendEmailVerificationCode({
client,
email,
ecosystemPartnerId: "...",
});
const { user, tdk } = await logIn({
client,
ecosystemPartnerId: "...",
method: "email",
email,
verificationCode: "123456",
apiUri: "https://tdk-api.spellcaster.lol",
chainId: 421614,
sessionOptions: {
backendWallet: "...",
approvedTargets: ["0x55d0cf68a1afe0932aff6f36c87efa703508191c"],
},
});
import { createTreasureConnectClient, logIn } from "@treasure-dev/tdk-core";
const client = createTreasureConnectClient({ clientId: "..." });
const { user, tdk } = await logIn({
client,
ecosystemPartnerId: "...",
method: "google",
apiUri: "https://tdk-api.spellcaster.lol",
chainId: 421614,
sessionOptions: {
backendWallet: "...",
approvedTargets: ["0x55d0cf68a1afe0932aff6f36c87efa703508191c"],
},
});
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,
ecosystemPartnerId: "...",
method: "auth_endpoint",
payload: JSON.stringify({
wanderersToken: "...",
}),
apiUri: "https://tdk-api.spellcaster.lol",
chainId: 421614,
sessionOptions: {
backendWallet: "...",
approvedTargets: ["0x55d0cf68a1afe0932aff6f36c87efa703508191c"],
},
});
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,
],
},
{ includeAbi: true },
);