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"""
 2This example shows how to activate an account via friendbot in a test network.
 3
 4This feature is only available for test networks.
 5
 6See: https://developers.stellar.org/docs/tutorials/create-account/#create-account
 7"""
 8
 9import requests
10
11from stellar_sdk import Keypair
12
13keypair = Keypair.random()
14
15print("Public Key: " + keypair.public_key)
16print("Secret Seed: " + keypair.secret)
17
18url = "https://friendbot.stellar.org"
19response = requests.get(url, params={"addr": keypair.public_key})
20print(response)

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"""
 2This example shows how to create and fund a new account with the specified starting balance.
 3
 4See: https://developers.stellar.org/docs/tutorials/create-account/#create-account
 5See: https://developers.stellar.org/docs/start/list-of-operations/#create-account
 6"""
 7
 8from stellar_sdk import Keypair, Network, Server, TransactionBuilder
 9
10server = Server(horizon_url="https://horizon-testnet.stellar.org")
11source = Keypair.from_secret("SBFZCHU5645DOKRWYBXVOXY2ELGJKFRX6VGGPRYUWHQ7PMXXJNDZFMKD")
12destination = Keypair.random()
13
14source_account = server.load_account(account_id=source.public_key)
15transaction = (
16    TransactionBuilder(
17        source_account=source_account,
18        network_passphrase=Network.TESTNET_NETWORK_PASSPHRASE,
19        base_fee=100,
20    )
21    .append_create_account_op(
22        destination=destination.public_key, starting_balance="12.25"
23    )
24    .set_timeout(30)
25    .build()
26)
27transaction.sign(source)
28response = server.submit_transaction(transaction)
29print(f"Transaction hash: {response['hash']}")
30print(
31    f"New Keypair: \n\taccount id: {destination.public_key}\n\tsecret seed: {destination.secret}"
32)

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.