Create Account¶
Now, in order to create an account, you need to run a CreateAccount operation with your new account ID.
Due to Digital World’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 unit
of the native asset (2 x 0.5 Base Reserve), and is subject to change.
Using The Digital World Testnet¶
If you want to play in the Digital World test network, you can use our Faucet to create an account for you as shown below:
1"""
2==============================================================
3Example: Activating a Digital World Account via Faucet (Testnet)
4==============================================================
5
6This example demonstrates how to create and activate a Digital World account
7on the Test Network using the Faucet service.
8
9Faucet is a special service provided by the Digital World 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 Faucet to fund the account.
163. Print the public and secret keys for use in further operations.
17
18Official Documentation:
19https://docs.digitalworld.global/docs/tutorials/create-account/#create-account
20"""
21
22# ==============================================================
23# === Installation Guideline ===================================
24# ==============================================================
25# To run this example, install the Digital World SDK and Requests library:
26#
27# pip install digital-world-sdk requests
28#
29# Save this file as `faucet_create_account.py` and execute:
30#
31# python faucet_create_account.py
32#
33# ==============================================================
34# === Import Required Libraries ================================
35# ==============================================================
36
37# Import the 'requests' library to send HTTP requests to Faucet
38import requests
39
40# Import the 'Keypair' class to generate Digital World keypairs
41from digital_world_sdk import Keypair
42
43# ==============================================================
44# === 1. Generate a Random Keypair ==============================
45# ==============================================================
46
47print("=== Generate a Random Keypair ===")
48# Generate a completely new random Digital World 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 Faucet =======================
61# ==============================================================
62
63print("=== Requesting Funds from Faucet ===")
64# Faucet is available only on the Digital World Testnet.
65# It automatically funds accounts when given a valid public key.
66url = "https://faucet.digitalworld.global"
67
68# Send a GET request to Faucet with the account's public key as a parameter
69response = requests.get(url, params={"addr": keypair.public_key})
70
71# Print the Faucet 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 Faucet ===
84# <Response [200]> # Indicates success
85# --------------------------------------------------------------------
86#
87# Once the account is funded, you can check it on the Digital World Testnet Explorer:
88# https://explorer.digitalworld.global/testnet/account/G***************
89#
90# The account is now active on the Digital World Testnet and ready for use.
91# --------------------------------------------------------------------
Using The Digital World Live Network¶
On the other hand, if you would like to create an account on the live network, you should buy some NATIVE from an exchange. When you withdraw the native asset 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 Digital World Account using Python SDK
4==============================================================
5
6This example demonstrates how to create a new Digital World account and fund it
7with a specified starting balance using the Digital World 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://docs.digitalworld.global/docs/tutorials/create-account/#create-account
18- List of operations: https://docs.digitalworld.global/docs/start/list-of-operations/#create-account
19"""
20
21# ==============================================================
22# === Installation Guideline ===================================
23# ==============================================================
24# To run this example, you need to install the Digital World SDK for Python:
25#
26# pip install digital-world-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 digital_world_sdk import Keypair, Network, GatewayServer, TransactionBuilder
37
38# ==============================================================
39# === 1. Setup GatewayServer and Source Account =======================
40# ==============================================================
41
42# Connect to the Digital World Testnet Gateway server
43server = GatewayServer(gateway_url="https://dex-testnet.digitalworld.global")
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 Gateway 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 SEEDS (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 Digital World 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
Digital World Live Network you will have to change the network passphrase to
Network.PUBLIC_NETWORK_PASSPHRASE and the server URL to point to
https://dex.digitalworld.global too.