Skip to content

Core Quickstart

If you're not using React, but still want a number of the abstractions that make the React package so easy to use, you can leverage the @account-kit/core package directly.

In this guide, we'll walk you through how to use this package to send a user operation, while using the reactive utilities exported by this package.

Install packages

Prerequisites Installation

To get started, you'll need to install the required packages. We also install the infra package because it contains the necessary Chain definitions that makes it easier to setup your a Bundler client.

yarn
yarn add @account-kit/core @account-kit/infra

Get your API keys

  1. Get your API key by creating a new app in your Alchemy Dashboard

  2. Create a new account config in your Account Kit Dashboard

    1. Apply the config to your app from step 1

      apply your the config to the app from the first step
    2. Enable authentication methods you want to support.


      Email auth

      If you want to use email auth, toggle on email.

      • For testing, use http://localhost:3000 as the Redirect URL (Note http not https)
      • The user will be redirected to the Redirect URL when they click the magic link in the email
      • Optionally stylize ✨ the email with your brand color and logo!
      configure email auth
      Social auth

      If you want to enable social login, toggle which auth providers you want to support.

      • For testing, add http://localhost:3000 as a whitelisted origin

      • Add the link that your dapp will be running on to the whitelisted origin list

      • Optionally enter your own OAuth credentials or use our defaults

        configure social auth
  3. Create the config and copy the API Key

    how to copy the api key

Create a config

Now, you're ready to create a config. The config we create should be a static object that you can import anywhere into your application. It contains all of the state that the functions within this package use.

import { createConfig } from "@account-kit/core";
import { alchemy, sepolia } from "@account-kit/infra";
 
export const config = createConfig({
  transport: alchemy({ apiKey: "YOUR_API_KEY" }),
  chain: sepolia,
  // optional if you want to sponsor gas
  policyId: "YOUR_POLICY_ID",
});

Authenticate the user

Before you can create a Smart Account instance for your users, you need to authenticate them with the user. Depending on what framework you're using this will look different, but using email based auth as an example you would:

  1. collect the user's email
  2. call the authenticate method on the signer
  3. handle the redirect from the user's email and pass the bundle to the signer to complete login
example.ts
import { config } from "./config";
import { getSigner } from "@account-kit/core";
 
const signer = getSigner(config);
 
if (!signer) {
  // this can happen if your rendering this on the server
  // the signer instance is only available on the client
  throw new Error("Signer not found");
}
 
// authenticate the user with email
await signer.authenticate({
  type: "email",
  email: "user@email.com",
});
 
// once the user has clicked on the email and been redirected back to your site
const bundle = new URLSearchParams(window.location.search).get("bundle");
if (!bundle) {
  throw new Error("No bundle found in URL");
}
await signer.authenticate({ type: "email", bundle });

Send a user operation

Now that you have your config, you can send user operations by leveraging the underlying smart account client.

example.ts
import { watchSmartAccountClient } from "@account-kit/core";
import { config } from "./config";
 
let clientState;
 
// The watch smart account client will handle all of the possible state changes
// that can impact this client:
//  - Signer status
//  - Account instantiation
//  - Chain changes
const clientSubscription = watchSmartAccountClient(
  {
    type: "LightAccount",
  },
  config
)((clientState_) => {
  clientState = clientState_;
});
 
if (clientState == null || clientState.isLoadingClient) {
  console.log("Loading...");
}
 
const client = clientState.client;
 
await client.sendUserOperation({
  uo: {
    target: "0xtarget",
    data: "0x",
    value: 0n,
  },
});

The key thing here is the watchSmartAccountClient method which allows you to subscribe to the state of signer and underlying account to give you a stable instance of the Smart Account Client. How you store the clientState variable will depend largely on your framework, but the above example should give you a good starting point.