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 | 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 | 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("Transaction hash: {}".format(response["hash"]))
print("New Keypair: \n\taccount id: {account_id}\n\tsecret seed: {secret_seed}".format(
account_id=destination.public_key, secret_seed=destination.secret))
|