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.
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.- Kit
- Web3.js v3
- Rust
- Python
- Go
- Web3.js (legacy)
Kit
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);
Output from a local Surfpool network
Output
Transaction Signature for create account: 5BC7tKudGe6pM7FDW4YKFcm1k2ZtDgMS7GhVmZitk7gfWjt2acKNpzWGzhxLq6CPNXG64nZrjdJzmHmEjjCjibbj
Web3.js v3
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);
Output from a local Surfpool network
Output
Transaction Signature: 5RAUrxZgUsyuA54g8MG3juKipk8VqzXyv2G4XGWHHiiM3c9fkUWFar6CTwXabnxWpBVjiCXs7peFA6FzBPVrZ5LS
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(())
}
Output from a local Surfpool network
Output
Account {
lamports: 890880,
data.len: 0,
owner: 11111111111111111111111111111111,
executable: false,
rent_epoch: 0,
}
Python
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())
Output from a local Surfpool network
Output
Transaction Signature for create account: 3WTnBoMbPVHoKNXC7KuEJ3N8SbdfG9rotSunCYKqFgQWrDNv7H6AFX4uVU4kjaStAZdwFxvSs5zGQmZVWirSVt7i
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)
}
Output from a local Surfpool network
Output
Transaction Signature for create account: 5JBwD31mcTqmqCHfr5chBTtNaeB4c7CWi3K6giPm98ycqGanD7rNnG6boViVK4NSVQP9K1De9mmhSvyJgPbEmjmv
Web3.js (legacy)
@solana/web3.js 1.x is no longer actively maintainedIt receives critical fixes only. Use Kit for new code. To migrate existing code, follow the Kit upgrade guide, or the web3.js v3 migration guide 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.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);
Output from a local Surfpool network
Output
Transaction Signature: aKU6xEaay5wvuXLrSQ7v2C5g7dwwgisgpwvGQimNFHtTbt8rA3EZpBDrNsoUbtfHTjrvpYEWfVRxDQyHwvBEsb4
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.