<VersionWarning version="0.1" />

# How to create and use a LightAccount with permissionless.js

[LightAccount](https://github.com/alchemyplatform/light-account) is the smart account implementation made by Alchemy and inspired by SimpleAccount.
It has a few additional [features](https://github.com/alchemyplatform/light-account?tab=readme-ov-file#features), such as transferrable ownership and upgradability.
This guide will show you how to create and use a LightAccount with permissionless.js.

## Steps

::::steps
### Import the required packages

```ts
import { createSmartAccountClient, ENTRYPOINT_ADDRESS_V06 } from "permissionless"
import { signerToLightSmartAccount } from "permissionless/accounts"
import {
	createPimlicoBundlerClient,
	createPimlicoPaymasterClient,
} from "permissionless/clients/pimlico"
import { createPublicClient, getContract, http, parseEther } from "viem"
import { privateKeyToAccount } from "viem/accounts"
import { sepolia } from "viem/chains"
```

### Create the clients

First we must create the public, bundler, and (optionally) paymaster clients that will be used to interact with the LightAccount.

```ts
export const publicClient = createPublicClient({
	transport: http("https://sepolia.rpc.thirdweb.com"),
})

export const paymasterClient = createPimlicoPaymasterClient({
	entryPoint: ENTRYPOINT_ADDRESS_V06,
	transport: http("https://api.pimlico.io/v2/sepolia/rpc?apikey=API_KEY"),
})

export const pimlicoBundlerClient = createPimlicoBundlerClient({
	transport: http("https://api.pimlico.io/v2/sepolia/rpc?apikey=API_KEY"),
	entryPoint: ENTRYPOINT_ADDRESS_V06,
})
```

### Create the LightAccount

:::info
For a full list of options for creating a LightAccount, take a look at the reference documentation page for [`signerToLightSmartAccount`](/references/permissionless/v0_1/reference/accounts/signerToLightSmartAccount).
:::

You can also pass an `address` to use an already created LightAccount.

```ts
const lightAccount = await signerToLightSmartAccount(publicClient, {
	signer: privateKeyToAccount("0x..."),
	entryPoint: ENTRYPOINT_ADDRESS_V06,
	lightAccountVersion: "1.1.0",
})
```

### Create the smart account client

The smart account client is a permissionless.js client that is meant to serve as an almost drop-in replacement for viem's [walletClient](https://viem.sh/docs/clients/wallet).

```ts
const smartAccountClient = createSmartAccountClient({
	account: lightAccount,
	entryPoint: ENTRYPOINT_ADDRESS_V06,
	chain: sepolia,
	bundlerTransport: http("https://api.pimlico.io/v2/sepolia/rpc?apikey=API_KEY"),
	middleware: {
		sponsorUserOperation: paymasterClient.sponsorUserOperation, // optional
		gasPrice: async () => (await pimlicoBundlerClient.getUserOperationGasPrice()).fast, // if using pimlico bundler
	},
})
```

### Send a transaction

Transactions using permissionless.js simply wrap around user operations. This means you can switch to permissionless.js from your existing viem EOA codebase with minimal-to-no changes.

```ts
const txHash = await smartAccountClient.sendTransaction({
	to: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
	value: parseEther("0.1"),
})
```

This also means you can also use viem Contract instances to transact without any modifications.

```ts
const nftContract = getContract({
	address: "0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2",
	abi: nftAbi,
	client: {
		public: publicClient,
		wallet: smartAccountClient,
	},
})

const txHash = await nftContract.write.mint()
```

You can also send an array of transactions in a single batch.

```ts
const txHash = await smartAccountClient.sendTransactions({
	transactions: [
		{
			to: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
			value: parseEther("0.1"),
			data: "0x",
		},
		{
			to: "0x1440ec793aE50fA046B95bFeCa5aF475b6003f9e",
			value: parseEther("0.1"),
			data: "0x1234",
		},
	],
})
```
::::
