> ## Documentation Index
> Fetch the complete documentation index at: https://seilabs-docs-evm-cookbook.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Pimlico Account Abstraction Integration

> Learn how to integrate Pimlico's account abstraction services with Sei network for gasless transactions and smart account functionality.

[Pimlico](https://pimlico.io) is an account abstraction (AA) infrastructure provider. With Pimlico, you can integrate smart accounts and gasless transactions into your Sei dApps. This guide shows how to use Pimlico's infrastructure to create a smart account and send your first gasless transaction on Sei Testnet.

## Getting started

### Dependencies

To integrate Pimlico into your Sei dApp, install these dependencies:

```bash theme={null}
pnpm install permissionless viem dotenv
```

<Info>permissionless.js is an AA SDK that works with any account, paymaster, or bundler implementation. It does not lock you in to one vendor.</Info>

### Setting up Pimlico dashboard

Before you start the integration:

1. Go to the [Pimlico dashboard](https://dashboard.pimlico.io).
2. Create an account. Then generate an API key.
3. Store your API key in a `.env` file:

```shell theme={null}
PIMLICO_API_KEY='pim_xxxxxxxxxxxxxxxxxxxxxx'
```

## Configuring Pimlico client

First, set up the necessary clients and configurations.

```typescript theme={null}
import { createSmartAccountClient } from 'permissionless';
import { createPimlicoClient } from 'permissionless/clients/pimlico';
import { createPublicClient, http, Hex } from 'viem';
import { privateKeyToAccount, generatePrivateKey } from 'viem/accounts';
import { seiTestnet } from 'viem/chains';
import { toSimpleSmartAccount } from 'permissionless/accounts';
import { writeFileSync } from 'fs';
import 'dotenv/config';

const apiKey = process.env.PIMLICO_API_KEY;
if (!apiKey) throw new Error('Missing PIMLICO_API_KEY');

// Generate or load private key
const privateKey =
  process.env.PRIVATE_KEY ??
  (() => {
    const pk = generatePrivateKey();
    writeFileSync('.env', `PRIVATE_KEY=${pk}`);
    return pk;
  })();

// Create public client
export const publicClient = createPublicClient({
  chain: seiTestnet,
  transport: http('https://evm-rpc-testnet.sei-apis.com')
});

// Create Pimlico client
const pimlicoUrl = `https://api.pimlico.io/v2/${seiTestnet.id}/rpc?apikey=${apiKey}`;

export const pimlicoClient = createPimlicoClient({
  chain: seiTestnet,
  transport: http(pimlicoUrl)
});
```

## Creating a smart account

Next, create a simple smart account instance. A single EOA signer controls this account:

```typescript theme={null}
import { toSimpleSmartAccount } from 'permissionless/accounts';

const account = await toSimpleSmartAccount({
  client: publicClient,
  owner: privateKeyToAccount(privateKey as Hex)
});

console.log(`Smart account address: ${account.address}`);
```

<Info>For the full list of smart account types that permissionless.js supports, see the [smart account comparison](https://docs.pimlico.io/permissionless/how-to/accounts/comparison).</Info>

## Setting up the smart account client

To interact with the smart account, create a `SmartAccountClient`:

```typescript theme={null}
import { createSmartAccountClient } from 'permissionless';

const smartAccountClient = createSmartAccountClient({
  account,
  chain: seiTestnet,
  bundlerTransport: http(pimlicoUrl),
  paymaster: pimlicoClient,
  userOperation: {
    estimateFeesPerGas: async () => {
      return (await pimlicoClient.getUserOperationGasPrice()).fast;
    }
  }
});
```

## Sending a gasless transaction

When the setup is complete, you can send a gasless transaction from your smart account:

```typescript theme={null}
const txHash = await smartAccountClient.sendTransaction({
  to: '0xd8da6bf26964af9d7eed9e03e53415d37aa96045',
  value: 0n,
  data: '0x1234'
});

console.log(`Transaction included: ${txHash}`);
return txHash;
```

## Complete example

This complete example combines all of the steps:

```typescript theme={null}
import { createSmartAccountClient } from 'permissionless';
import { createPimlicoClient } from 'permissionless/clients/pimlico';
import { privateKeyToAccount, generatePrivateKey } from 'viem/accounts';
import { createPublicClient, http, Hex } from 'viem';
import { seiTestnet } from 'viem/chains';
import { toSimpleSmartAccount } from 'permissionless/accounts';
import { writeFileSync } from 'fs';
import 'dotenv/config';

async function main() {
  // Initialize clients and account
  const apiKey = process.env.PIMLICO_API_KEY;
  if (!apiKey) throw new Error('Missing PIMLICO_API_KEY');

  // Generate or load private key
  const privateKey =
    process.env.PRIVATE_KEY ??
    (() => {
      const pk = generatePrivateKey();
      writeFileSync('.env', `PRIVATE_KEY=${pk}`);
      return pk;
    })();

  // Create public client
  const publicClient = createPublicClient({
    chain: seiTestnet,
    transport: http('https://evm-rpc-testnet.sei-apis.com')
  });

  // Create Pimlico client
  const pimlicoUrl = `https://api.pimlico.io/v2/${seiTestnet.id}/rpc?apikey=${apiKey}`;

  const pimlicoClient = createPimlicoClient({
    chain: seiTestnet,
    transport: http(pimlicoUrl)
  });

  // Create smart account
  const account = await toSimpleSmartAccount({
    client: publicClient,
    owner: privateKeyToAccount(privateKey as Hex)
  });

  console.log(`Smart account address: ${account.address}`);

  // Create smart account client
  const smartAccountClient = createSmartAccountClient({
    account,
    chain: seiTestnet,
    bundlerTransport: http(pimlicoUrl),
    paymaster: pimlicoClient,
    userOperation: {
      estimateFeesPerGas: async () => {
        return (await pimlicoClient.getUserOperationGasPrice()).fast;
      }
    }
  });

  // Send transaction
  const txHash = await smartAccountClient.sendTransaction({
    to: '0xd8da6bf26964af9d7eed9e03e53415d37aa96045',
    value: 0n,
    data: '0x1234'
  });

  console.log(`Transaction included: ${txHash}`);
}

main().catch(console.error);
```

## What's happening under the hood?

When you send a transaction with the smart account client:

1. The client builds a user operation (a transaction format for smart accounts).
2. The client requests sponsorship from Pimlico's paymaster.
3. The client signs the operation with the private key of the smart account owner.
4. The client submits the operation to Pimlico's bundler.
5. The bundler monitors the chain until the operation is included in a block.

If your smart account contract is not deployed yet, the first transaction also deploys it.

## Conclusion

This guide showed how to:

* Set up Pimlico's infrastructure
* Create a smart account
* Send gasless transactions

With this implementation, users do not need to handle gas or manage native tokens to interact with your dApp.

For more information about Pimlico and its features, see these resources:

* [Pimlico documentation](https://docs.pimlico.io)
* [Pimlico dashboard](https://dashboard.pimlico.io)
* [Pimlico GitHub](https://github.com/pimlicolabs)

To get help and share what you build, join the [Pimlico Telegram](https://t.me/pimlicoHQ) community.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.