Quickstart

In this guide, we’ll cover how to get started with @account-kit/infra and send a user operation. For smart contracts, we’ll leverage @account-kit/smart-contracts to use ModularAccountV2, but you’re free to use any smart contract you’d like.

Prerequisites

  • API key from your dashboard
  • minimum Typescript version of 5 and the packages below from aa-sdk

Installation

$yarn add @account-kit/infra @account-kit/smart-contracts @aa-sdk/core viem

Create a Gas Manager policy

If you want to sponsor gas, then you’ll also want to create a gas policy in the Gas Manager dashboard.

A gas manager policy is a set of rules that define which UOs are eligible for gas sponsorship. You can control which operations are eligible for sponsorship by defining rules:

  • Spending rules: limit the amount of money or the number of transactions that can be sponsored by this policy
  • Allowlist: restrict wallet addresses that are eligible for sponsorship. The policy will only sponsor gas for UOs that were sent by addresses on this list.
  • Blocklist: ban certain addresses from receiving sponsorship under this policy
  • Policy duration: define the duration of your policy and the sponsorship expiry period. This is the period for which the sponsor gas signature (gas sponsorship data) will remain valid once it is generated.

To learn more about policy configuration, refer to the guide on setting up a gas manager policy.

Once you have decided on policy rules for your app, create a policy in the Gas Manager dashboard.

Now you should have a Gas policy created with a policy id you can use to sponsor gas for your users.

Policy ID

Create a client

Now that you have an API key and a Policy ID, you can create a Smart Account Client to interact with the infrastructure.

Replace YOUR_API_KEY and POLICY_ID with the key and Policy ID created above.

1import { alchemy, sepolia } from "@account-kit/infra";
2
3const YOUR_API_KEY = "<YOUR_API_KEY>";
4
5export const chain = sepolia;
6
7export const policyId = "<POLICY_ID>";
8
9export const transport = alchemy({
10 apiKey: YOUR_API_KEY,
11});

Send a user operation

The last step is to send a user operation using the client you just created.

example.ts
1import { getClient } from "./client";
2
3const client = await getClient();
4
5const { hash } = await client.sendUserOperation({
6 uo: {
7 target: "0xTARGET_ADDRESS",
8 data: "0x",
9 value: 0n,
10 },
11});