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
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
"""
This example shows how to activate an account via friendbot in a test network.

This feature is only available for test networks.

See: https://developers.stellar.org/docs/tutorials/create-account/#create-account
"""
import requests

from stellar_sdk import Keypair

keypair = Keypair.random()

print("Public Key: " + keypair.public_key)
print("Secret Seed: " + keypair.secret)

url = "https://friendbot.stellar.org"
response = requests.get(url, params={"addr": keypair.public_key})
print(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
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""
This example shows how to create and fund a new account with the specified starting balance.

See: https://developers.stellar.org/docs/tutorials/create-account/#create-account
See: https://developers.stellar.org/docs/start/list-of-operations/#create-account
"""
from stellar_sdk import TransactionBuilder, Server, Network, Keypair

server = Server(horizon_url="https://horizon-testnet.stellar.org")
source = Keypair.from_secret("SBFZCHU5645DOKRWYBXVOXY2ELGJKFRX6VGGPRYUWHQ7PMXXJNDZFMKD")
destination = Keypair.random()

source_account = server.load_account(account_id=source.public_key)
transaction = (
    TransactionBuilder(
        source_account=source_account,
        network_passphrase=Network.TESTNET_NETWORK_PASSPHRASE,
        base_fee=100,
    )
    .append_create_account_op(
        destination=destination.public_key, starting_balance="12.25"
    )
    .build()
)
transaction.sign(source)
response = server.submit_transaction(transaction)
print(f"Transaction hash: {response['hash']}")
print(
    f"New Keypair: \n\taccount id: {destination.public_key}\n\tsecret seed: {destination.secret}"
)