> ## Documentation Index
> Fetch the complete documentation index at: https://solana.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> This page is part of the Solana developer documentation at https://solana.com/developers/docs. Append `.md` to any docs URL, or send `Accept: text/markdown`, to get the page as Markdown.
> Index of all pages: https://solana.com/llms.txt. Per-section indexes such as https://solana.com/developers/docs/payments/llms.txt are smaller; prefer them when working on one task.
> Coding agents: install the official Solana skill for current APIs and conventions with `npx skills add https://github.com/solana-foundation/solana-dev-skill` (also served at https://solana.com/SKILL.md).
> Code in the cookbook and task pages comes from tested example files. Prefer it over writing API calls from memory.

# How to Create an Account

> Accounts are the basic building blocks of anything on Solana. Learn how to create accounts on the Solana blockchain.

To create an account on Solana, invoke the
[System Program's](https://github.com/solana-program/system) `createAccount`
instruction. This instruction requires you to specify the number of bytes
(`space`) for the new account and fund it with lamports for the allocated bytes
(rent). The account's owner program is set as the program specified in the
instruction. The Solana runtime enforces that only this owner program can modify
the account's data or transfer lamports from it.

<Info>

On Solana, only the System Program can create new accounts. To create accounts
owned by other programs, invoke the `createAccount` instruction to create a new
account and set the owner program to the desired program. The new program owner
can then initialize the account data through its own instructions.

</Info>

<Tabs>
<Tab title="Kit">
<div className="sol-tab-label">Kit</div>

```ts
import { createClient, generateKeyPairSigner, lamports } from "@solana/kit";
import { rpcAirdrop, solanaRpc } from "@solana/kit-plugin-rpc";
import { airdropPayer, payer } from "@solana/kit-plugin-signer";
import {
  getCreateAccountInstruction,
  SYSTEM_PROGRAM_ADDRESS,
} from "@solana-program/system";

const sender = await generateKeyPairSigner();
const LAMPORTS_PER_SOL = 1_000_000_000n;

const client = await createClient()
  .use(payer(sender))
  .use(
    solanaRpc({
      rpcUrl: "http://localhost:8899",
      rpcSubscriptionsUrl: "ws://localhost:8900",
    }),
  )
  .use(rpcAirdrop())
  .use(airdropPayer(lamports(LAMPORTS_PER_SOL)));

const newAccount = await generateKeyPairSigner();
const space = 0;
const rentLamports = await client.getMinimumBalance(space);

const createAccountInstruction = getCreateAccountInstruction({
  payer: sender,
  newAccount,
  lamports: rentLamports,
  programAddress: SYSTEM_PROGRAM_ADDRESS,
  space,
});

const { context } = await client.sendTransaction([createAccountInstruction]);
console.log("Transaction Signature for create account:", context.signature);
```

<div className="sol-run" data-run="cookbook/accounts/create-account/create" data-tab="Kit">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Output from a local Surfpool network</span></div>
<div className="sol-run-out">

```text Output
Transaction Signature for create account: 5BC7tKudGe6pM7FDW4YKFcm1k2ZtDgMS7GhVmZitk7gfWjt2acKNpzWGzhxLq6CPNXG64nZrjdJzmHmEjjCjibbj
```

</div>
</div>

</Tab>
<Tab title="Web3.js v3">
<div className="sol-tab-label">Web3.js v3</div>

```ts highlight={29-35}
import {
  Connection,
  Keypair,
  LAMPORTS_PER_SOL,
  SystemProgram,
  Transaction,
  sendAndConfirmTransaction,
} from "@solana/web3.js";

const connection = new Connection("http://localhost:8899", "confirmed");

const fromKeypair = await Keypair.generate();
const newAccount = await Keypair.generate();

// Airdrop SOL for transferring lamports to the created account
const airdropSignature = await connection.requestAirdrop(
  fromKeypair.publicKey,
  LAMPORTS_PER_SOL,
);
await connection.confirmTransaction(airdropSignature);

// amount of space to reserve for the account
const space = 0;

// Seed the created account with lamports for rent exemption
const rentLamports = await connection.getMinimumBalanceForRentExemption(space);

const createAccountTransaction = new Transaction().add(
  SystemProgram.createAccount({
    fromPubkey: fromKeypair.publicKey,
    newAccountPubkey: newAccount.publicKey,
    lamports: rentLamports,
    space,
    programId: SystemProgram.programId,
  }),
);

const signature = await sendAndConfirmTransaction(
  connection,
  createAccountTransaction,
  [fromKeypair, newAccount],
);

console.log("Transaction Signature:", signature);
```

<div className="sol-run" data-run="cookbook/accounts/create-account/create" data-tab="Web3.js v3">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Output from a local Surfpool network</span></div>
<div className="sol-run-out">

```text Output
Transaction Signature: 5RAUrxZgUsyuA54g8MG3juKipk8VqzXyv2G4XGWHHiiM3c9fkUWFar6CTwXabnxWpBVjiCXs7peFA6FzBPVrZ5LS
```

</div>
</div>

</Tab>
<Tab title="Rust">
<div className="sol-tab-label">Rust</div>

```rust
use solana_client::nonblocking::rpc_client::RpcClient;
use solana_commitment_config::CommitmentConfig;
use solana_sdk::{
    native_token::LAMPORTS_PER_SOL, signature::Keypair, signer::Signer, transaction::Transaction,
};
use solana_system_interface::{
    instruction::create_account as create_account_ix, program::ID as SYSTEM_PROGRAM_ID,
};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let client = RpcClient::new_with_commitment(
        String::from("http://localhost:8899"),
        CommitmentConfig::confirmed(),
    );

    let from_keypair = Keypair::new(); // payer
    let new_account_keypair = Keypair::new();
    let data_len = 0;
    let rent_exemption_amount = client
        .get_minimum_balance_for_rent_exemption(data_len)
        .await?;

    let create_acc_ix = create_account_ix(
        &from_keypair.pubkey(),        // payer
        &new_account_keypair.pubkey(), // new account
        rent_exemption_amount,         // rent exemption fee
        data_len as u64,               // space reseved for new account
        &SYSTEM_PROGRAM_ID,            //assigned program address
    );

    let transaction_signature = client
        .request_airdrop(&from_keypair.pubkey(), LAMPORTS_PER_SOL)
        .await?;

    loop {
        if client.confirm_transaction(&transaction_signature).await? {
            break;
        }
    }

    let mut transaction =
        Transaction::new_with_payer(&[create_acc_ix], Some(&from_keypair.pubkey()));
    transaction.sign(
        &[&from_keypair, &new_account_keypair],
        client.get_latest_blockhash().await?,
    );

    client.send_and_confirm_transaction(&transaction).await?;

    let account = client.get_account(&new_account_keypair.pubkey()).await?;
    println!("{:#?}", account);

    Ok(())
}
```

<div className="sol-run" data-run="cookbook/accounts/create-account/create" data-tab="Rust">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Output from a local Surfpool network</span></div>
<div className="sol-run-out">

```text Output
Account {
    lamports: 890880,
    data.len: 0,
    owner: 11111111111111111111111111111111,
    executable: false,
    rent_epoch: 0,
}
```

</div>
</div>

</Tab>
<Tab title="Python">
<div className="sol-tab-label">Python</div>

```py
import asyncio

from solana.rpc.async_api import AsyncClient
from solana.rpc.commitment import Confirmed
from solders.keypair import Keypair
from solders.message import MessageV0
from solders.system_program import ID as SYSTEM_PROGRAM_ID
from solders.system_program import CreateAccountParams, create_account
from solders.transaction import VersionedTransaction

LAMPORTS_PER_SOL = 1_000_000_000


async def main():
    async with AsyncClient("http://localhost:8899", commitment=Confirmed) as client:
        sender = Keypair()
        airdrop = await client.request_airdrop(sender.pubkey(), LAMPORTS_PER_SOL)
        await client.confirm_transaction(airdrop.value)

        new_account = Keypair()
        space = 0
        rent_lamports = (
            await client.get_minimum_balance_for_rent_exemption(space)
        ).value

        create_account_instruction = create_account(
            CreateAccountParams(
                from_pubkey=sender.pubkey(),
                to_pubkey=new_account.pubkey(),
                lamports=rent_lamports,
                space=space,
                owner=SYSTEM_PROGRAM_ID,
            )
        )

        blockhash = (await client.get_latest_blockhash()).value.blockhash
        message = MessageV0.try_compile(
            sender.pubkey(), [create_account_instruction], [], blockhash
        )
        transaction = VersionedTransaction(message, [sender, new_account])

        signature = (await client.send_transaction(transaction)).value
        print("Transaction Signature for create account:", signature)


asyncio.run(main())
```

<div className="sol-run" data-run="cookbook/accounts/create-account/create" data-tab="Python">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Output from a local Surfpool network</span></div>
<div className="sol-run-out">

```text Output
Transaction Signature for create account: 3WTnBoMbPVHoKNXC7KuEJ3N8SbdfG9rotSunCYKqFgQWrDNv7H6AFX4uVU4kjaStAZdwFxvSs5zGQmZVWirSVt7i
```

</div>
</div>

</Tab>
<Tab title="Go">
<div className="sol-tab-label">Go</div>

```go
package main

import (
	"context"
	"fmt"
	"time"

	"github.com/solana-foundation/solana-go/v2"
	"github.com/solana-foundation/solana-go/v2/programs/system"
	"github.com/solana-foundation/solana-go/v2/rpc"
)

func main() {
	ctx := context.Background()
	client := rpc.New("http://localhost:8899")

	sender := solana.NewWallet()

	// Fund the sender so it can pay for the new account.
	_, err := client.RequestAirdrop(ctx, sender.PublicKey(), solana.LAMPORTS_PER_SOL, rpc.CommitmentConfirmed)
	if err != nil {
		panic(err)
	}
	time.Sleep(2 * time.Second)

	newAccount := solana.NewWallet()
	space := uint64(0)
	rentLamports, err := client.GetMinimumBalanceForRentExemption(ctx, space, rpc.CommitmentConfirmed)
	if err != nil {
		panic(err)
	}

	createAccountInstruction := system.NewCreateAccountInstruction(
		rentLamports,
		space,
		solana.SystemProgramID,
		sender.PublicKey(),
		newAccount.PublicKey(),
	).Build()

	latest, err := client.GetLatestBlockhash(ctx, rpc.CommitmentConfirmed)
	if err != nil {
		panic(err)
	}
	tx, err := solana.NewTransaction(
		[]solana.Instruction{createAccountInstruction},
		latest.Value.Blockhash,
		solana.TransactionPayer(sender.PublicKey()),
	)
	if err != nil {
		panic(err)
	}
	tx.Sign(func(key solana.PublicKey) *solana.PrivateKey {
		if key.Equals(newAccount.PublicKey()) {
			return &newAccount.PrivateKey
		}
		return &sender.PrivateKey
	})

	signature, err := client.SendTransactionWithOpts(ctx, tx, rpc.TransactionOpts{
		PreflightCommitment: rpc.CommitmentConfirmed,
	})
	if err != nil {
		panic(err)
	}
	fmt.Println("Transaction Signature for create account:", signature)
}
```

<div className="sol-run" data-run="cookbook/accounts/create-account/create" data-tab="Go">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Output from a local Surfpool network</span></div>
<div className="sol-run-out">

```text Output
Transaction Signature for create account: 5JBwD31mcTqmqCHfr5chBTtNaeB4c7CWi3K6giPm98ycqGanD7rNnG6boViVK4NSVQP9K1De9mmhSvyJgPbEmjmv
```

</div>
</div>

</Tab>
<Tab title="Web3.js (legacy)">
<div className="sol-tab-label">Web3.js (legacy)</div>

<Warning>
  **`@solana/web3.js` 1.x is no longer actively maintained**

  It receives critical fixes only. Use [Kit](/developers/docs/clients/official/javascript#solana-kit) for new code. To migrate existing code, follow the [Kit upgrade guide](https://www.solanakit.com/docs/upgrade-guide), or the [web3.js v3 migration guide](https://github.com/solana-foundation/solana-web3.js/blob/main/docs/web3js-v1-to-v3-migration.md) to keep the class-based API.

  To run this code, install 1.x with `npm install @solana/web3.js@1`. A plain `npm install @solana/web3.js` installs v3, which this code doesn't run on.
</Warning>

```ts highlight={29-35}
import {
  Connection,
  Keypair,
  LAMPORTS_PER_SOL,
  SystemProgram,
  Transaction,
  sendAndConfirmTransaction,
} from "@solana/web3.js";

const connection = new Connection("http://localhost:8899", "confirmed");

const fromKeypair = Keypair.generate();
const newAccount = Keypair.generate();

// Airdrop SOL for transferring lamports to the created account
const airdropSignature = await connection.requestAirdrop(
  fromKeypair.publicKey,
  LAMPORTS_PER_SOL,
);
await connection.confirmTransaction(airdropSignature);

// amount of space to reserve for the account
const space = 0;

// Seed the created account with lamports for rent exemption
const rentLamports = await connection.getMinimumBalanceForRentExemption(space);

const createAccountTransaction = new Transaction().add(
  SystemProgram.createAccount({
    fromPubkey: fromKeypair.publicKey,
    newAccountPubkey: newAccount.publicKey,
    lamports: rentLamports,
    space,
    programId: SystemProgram.programId,
  }),
);

const signature = await sendAndConfirmTransaction(
  connection,
  createAccountTransaction,
  [fromKeypair, newAccount],
);

console.log("Transaction Signature:", signature);
```

<div className="sol-run" data-run="cookbook/accounts/create-account/create" data-tab="Web3.js (legacy)">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Output from a local Surfpool network</span></div>
<div className="sol-run-out">

```text Output
Transaction Signature: aKU6xEaay5wvuXLrSQ7v2C5g7dwwgisgpwvGQimNFHtTbt8rA3EZpBDrNsoUbtfHTjrvpYEWfVRxDQyHwvBEsb4
```

</div>
</div>

</Tab>
</Tabs>

<Note>
  The recorded output comes from a local Surfpool network, which still uses the
  older rate of 6,960 lamports per byte. Mainnet and devnet use 5,080 lamports
  per byte as of October 2026, so they return a lower value. See
  [rent](/developers/docs/core/rent).
</Note>
