Create Account

Now, in order to create an account, you need to run a CreateAccount operation with your new account ID. Due to Stellar’s minimum account balance, you’ll need to transfer the minimum account balance from another account with the create account operation. As of this writing, minimum balance is 1 XLM (2 x 0.5 Base Reserve), and is subject to change.

Using The SDF Testnet

If you want to play in the Stellar test network, you can ask our Friendbot to create an account for you as shown below:

 1"""
 2==============================================================
 3Example: Activating a Stellar Account via Friendbot (Testnet)
 4==============================================================
 5
 6This example demonstrates how to create and activate a Stellar account
 7on the Test Network using the Friendbot service.
 8
 9Friendbot is a special service provided by the Stellar Testnet that
10automatically funds new accounts with test XLM, allowing developers
11to experiment without spending real money.
12
13Steps performed:
141. Generate a new random keypair.
152. Request Friendbot to fund the account.
163. Print the public and secret keys for use in further operations.
17
18Official Documentation:
19https://developers.stellar.org/docs/tutorials/create-account/#create-account
20"""
21
22# ==============================================================
23# === Installation Guideline ===================================
24# ==============================================================
25# To run this example, install the Stellar SDK and Requests library:
26#
27#     pip install stellar-sdk requests
28#
29# Save this file as `friendbot_create_account.py` and execute:
30#
31#     python friendbot_create_account.py
32#
33# ==============================================================
34# === Import Required Libraries ================================
35# ==============================================================
36
37# Import the 'requests' library to send HTTP requests to Friendbot
38import requests
39
40# Import the 'Keypair' class to generate Stellar keypairs
41from stellar_sdk import Keypair
42
43# ==============================================================
44# === 1. Generate a Random Keypair ==============================
45# ==============================================================
46
47print("=== Generate a Random Keypair ===")
48# Generate a completely new random Stellar keypair
49keypair = Keypair.random()
50
51# Display the public and secret keys for the newly created account
52print("Public Key: " + keypair.public_key)
53
54# Print a truncated version of the secret for clarity, avoiding full exposure
55# CodeQL [py/clear-text-logging-sensitive-data]: Safe truncated output for testnet demonstration only.
56print("Secret Seed: " + keypair.secret)
57print("-" * 68)
58
59# ==============================================================
60# === 2. Fund the Account using Friendbot =======================
61# ==============================================================
62
63print("=== Requesting Funds from Friendbot ===")
64# Friendbot is available only on the Stellar Testnet.
65# It automatically funds accounts when given a valid public key.
66url = "https://friendbot.stellar.org"
67
68# Send a GET request to Friendbot with the account's public key as a parameter
69response = requests.get(url, params={"addr": keypair.public_key})
70
71# Print the Friendbot response — should confirm account creation and funding
72print(response)
73print("-" * 68)
74
75# ==============================================================
76# === Expected Output ==========================================
77# ==============================================================
78# --------------------------------------------------------------------
79# === Generate a Random Keypair ===
80# Public Key: G*************** (randomly generated)
81# Secret Seed: S*************** (randomly generated)
82# --------------------------------------------------------------------
83# === Requesting Funds from Friendbot ===
84# <Response [200]>  # Indicates success
85# --------------------------------------------------------------------
86#
87# Once the account is funded, you can check it on the Stellar Testnet Explorer:
88# https://stellar.expert/explorer/testnet/account/G***************
89#
90# The account is now active on the Stellar Testnet and ready for use.
91# --------------------------------------------------------------------

Using The Stellar Live Network

On the other hand, if you would like to create an account on the live network, you should buy some Stellar Lumens from an exchange. When you withdraw the Lumens into your new account, the exchange will automatically create the account for you. However, if you want to create an account from another account of your own, here’s an example of how to do so:

  1"""
  2==============================================================
  3Example: Creating and Funding a Stellar Account using Python SDK
  4==============================================================
  5
  6This example demonstrates how to create a new Stellar account and fund it
  7with a specified starting balance using the Stellar Testnet.
  8
  9Operations performed:
 101. Load an existing source account (already funded).
 112. Generate a new random destination keypair.
 123. Build a `Create Account` transaction to fund the new account.
 134. Sign and submit the transaction.
 145. Print transaction hash and new account credentials.
 15
 16Official Documentation:
 17- Create Account: https://developers.stellar.org/docs/tutorials/create-account/#create-account
 18- List of operations: https://developers.stellar.org/docs/start/list-of-operations/#create-account
 19"""
 20
 21# ==============================================================
 22# === Installation Guideline ===================================
 23# ==============================================================
 24# To run this example, you need to install the Stellar SDK for Python:
 25#
 26#     pip install stellar-sdk
 27#
 28# Save this script as `create_account.py` and run with:
 29#
 30#     python create_account.py
 31#
 32# ==============================================================
 33# === Import Required Libraries =================================
 34# ==============================================================
 35
 36from stellar_sdk import Keypair, Network, Server, TransactionBuilder
 37
 38# ==============================================================
 39# === 1. Setup Server and Source Account =======================
 40# ==============================================================
 41
 42# Connect to the Stellar Testnet Horizon server
 43server = Server(horizon_url="https://horizon-testnet.stellar.org")
 44
 45# Load an existing account that will fund the new account
 46# Replace this secret with your own testnet secret key
 47source = Keypair.from_secret("SBFZCHU5645DOKRWYBXVOXY2ELGJKFRX6VGGPRYUWHQ7PMXXJNDZFMKD")
 48
 49# ==============================================================
 50# === 2. Generate a New Random Keypair for Destination =========
 51# ==============================================================
 52
 53# Create a new random keypair for the account to be created
 54destination = Keypair.random()
 55
 56# ==============================================================
 57# === 3. Load Source Account Details ===========================
 58# ==============================================================
 59
 60# Load the source account from the Testnet Horizon server
 61source_account = server.load_account(account_id=source.public_key)
 62
 63# ==============================================================
 64# === 4. Build Create Account Transaction ======================
 65# ==============================================================
 66
 67# Build a transaction to create a new account
 68# and fund it with the starting balance of 12.25 XLM
 69transaction = (
 70    TransactionBuilder(
 71        source_account=source_account,
 72        network_passphrase=Network.TESTNET_NETWORK_PASSPHRASE,
 73        base_fee=100,  # set fee per operation in stroops (0.00001 XLM)
 74    )
 75    .append_create_account_op(
 76        destination=destination.public_key,
 77        starting_balance="12.25",  # fund with 12.25 XLM
 78    )
 79    .set_timeout(30)  # transaction will timeout in 30 seconds
 80    .build()
 81)
 82
 83# ==============================================================
 84# === 5. Sign and Submit Transaction ==========================
 85# ==============================================================
 86
 87# Sign the transaction with the source account's secret key
 88transaction.sign(source)
 89
 90# Submit the transaction to the Testnet
 91response = server.submit_transaction(transaction)
 92
 93# ==============================================================
 94# === 6. Output Transaction and Account Details ==============
 95# ==============================================================
 96
 97print(f"Transaction hash: {response['hash']}")
 98print(
 99    f"New Keypair: \n\taccount id: {destination.public_key}\n\tsecret seed: {destination.secret}"
100)
101
102# ==============================================================
103# === Expected Output =========================================
104# ==============================================================
105# Example output (hash and keys will differ every run):
106#
107# Transaction hash: 70e023123fbf8b417ecea5ed923484e8d200beb792995d73d7692ab0875843b2
108# New Keypair:
109#       account id: GAPASWTZYIM2JZE5QLGID52PVD4QWCLCQLXWDSL7AA4ECES23WZGHMR4
110#       secret seed: SB2TJS54Y2J52G5XVRJZLARUMYKSGAGQIG3NTWLR6SRY3MDQMGZUWJI2
111#
112# The new account has been created on the Stellar Testnet and funded
113# with the starting balance specified.
114# -----------------------------------------------------------------

Note

To avoid risks, TESTNET is used in the example above. In order to use the Stellar Live Network you will have to change the network passphrase to Network.PUBLIC_NETWORK_PASSPHRASE and the server URL to point to https://horizon.stellar.org too.