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"""
 8import requests
 9
10from stellar_sdk import Keypair
11
12keypair = Keypair.random()
13
14print("Public Key: " + keypair.public_key)
15print("Secret Seed: " + keypair.secret)
16
17url = "https://friendbot.stellar.org"
18response = requests.get(url, params={"addr": keypair.public_key})
19print(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"""
 7from stellar_sdk import Keypair, Network, Server, TransactionBuilder
 8
 9server = Server(horizon_url="https://horizon-testnet.stellar.org")
10source = Keypair.from_secret("SBFZCHU5645DOKRWYBXVOXY2ELGJKFRX6VGGPRYUWHQ7PMXXJNDZFMKD")
11destination = Keypair.random()
12
13source_account = server.load_account(account_id=source.public_key)
14transaction = (
15    TransactionBuilder(
16        source_account=source_account,
17        network_passphrase=Network.TESTNET_NETWORK_PASSPHRASE,
18        base_fee=100,
19    )
20    .append_create_account_op(
21        destination=destination.public_key, starting_balance="12.25"
22    )
23    .build()
24)
25transaction.sign(source)
26response = server.submit_transaction(transaction)
27print(f"Transaction hash: {response['hash']}")
28print(
29    f"New Keypair: \n\taccount id: {destination.public_key}\n\tsecret seed: {destination.secret}"
30)