Create an account | Stellar Docs (2024)

Before we get started with working with Stellar in code, consider going through the following examples using the Stellar Lab. The lab allows you create accounts, fund accounts on the Stellar test network, build transactions, run any operation, and inspect responses from Horizon via the Endpoint Explorer.

Accounts are a fundamental building block of Stellar: they hold all your balances, allow you to send and receive payments, and let you place offers to buy and sell assets. Since pretty much everything on Stellar is in some way tied to an account, the first thing you generally need to do when you start developing is create one. This beginner-level tutorial will show you how to do that.

Create a Keypair

Stellar uses public key cryptography to ensure that every transaction is secure: every Stellar account has a keypair consisting of a public key and a secret key. The public key is always safe to share — other people need it to identify your account and verify that you authorized a transaction. It's like an email address. The secret key, however, is private information that proves you own — and gives you access to — your account. It's like a password, and you should never share it with anyone.

Before creating an account, you need to generate your own keypair:

  • JavaScript
  • Java
  • Go
  • Python
// create a completely new and unique pair of keys
// see more about KeyPair objects: https://stellar.github.io/js-stellar-sdk/Keypair.html
const pair = StellarSdk.Keypair.random();

pair.secret();
// SAV76USXIJOBMEQXPANUOQM6F5LIOTLPDIDVRJBFFE2MDJXG24TAPUU7
pair.publicKey();
// GCFXHS4GXL6BVUCXBWXGTITROWLVYXQKQLF4YH5O5JT3YZXCYPAFBJZB

Create Account

A valid keypair, however, does not make an account: in order to prevent unused accounts from bloating the ledger, Stellar requires accounts to hold a minimum balance of 1 XLM before they actually exist. Until it gets a bit of funding, your keypair doesn't warrant space on the ledger.

On the public network, where live users make live transactions, your next step would be to acquire XLM, which you can do by consulting our section on lumens. Because this tutorial runs on the test network, you can get 10,000 test XLM from Friendbot, which is a friendly account funding tool.

To do that, send Friendbot the public key you created. It’ll create and fund a new account using that public key as the account ID.

  • JavaScript
  • Java
  • Go
  • Python
// The SDK does not have tools for creating test accounts, so you'll have to
// make your own HTTP request.

// if you're trying this on Node, install the `node-fetch` library and
// uncomment the next line:
// const fetch = require('node-fetch');

(async function main() {
try {
const response = await fetch(
`https://friendbot.stellar.org?addr=${encodeURIComponent(
pair.publicKey(),
)}`,
);
const responseJSON = await response.json();
console.log("SUCCESS! You have a new account :)\n", responseJSON);
} catch (e) {
console.error("ERROR!", e);
}
// After you've got your test lumens from friendbot, we can also use that account to create a new account on the ledger.
try {
const server = new StellarSdk.Horizon.Server(
"https://horizon-testnet.stellar.org",
);
var parentAccount = await server.loadAccount(pair.publicKey()); //make sure the parent account exists on ledger
var childAccount = StellarSdk.Keypair.random(); //generate a random account to create
//create a transacion object.
var createAccountTx = new StellarSdk.TransactionBuilder(parentAccount, {
fee: StellarSdk.BASE_FEE,
networkPassphrase: StellarSdk.Networks.TESTNET,
});
//add the create account operation to the createAccountTx transaction.
createAccountTx = await createAccountTx
.addOperation(
StellarSdk.Operation.createAccount({
destination: childAccount.publicKey(),
startingBalance: "5",
}),
)
.setTimeout(180)
.build();
//sign the transaction with the account that was created from friendbot.
await createAccountTx.sign(pair);
//submit the transaction
let txResponse = await server
.submitTransaction(createAccountTx)
// some simple error handling
.catch(function (error) {
console.log("there was an error");
console.log(error.response);
console.log(error.status);
console.log(error.extras);
return error;
});
console.log(txResponse);
console.log("Created the new account", childAccount.publicKey());
} catch (e) {
console.error("ERROR!", e);
}
})();

Now for the last step: getting the account’s details and checking its balance. Accounts can carry multiple balances — one for each type of currency they hold.

  • JavaScript
  • Java
  • Go
  • Python
const server = new StellarSdk.Horizon.Server(
"https://horizon-testnet.stellar.org",
);

// the JS SDK uses promises for most actions, such as retrieving an account
const account = await server.loadAccount(pair.publicKey());
console.log("Balances for account: " + pair.publicKey());
account.balances.forEach(function (balance) {
console.log("Type:", balance.asset_type, ", Balance:", balance.balance);
});

Now that you’ve got an account, you can start sending and receiving payments, or, if you're ready to hunker down, you can skip ahead and build a wallet or issue a Stellar-network asset.

info

In the above code samples, proper error checking is omitted for brevity. However, you should always validate your results, as there are many ways that requests can fail. You should refer to the guide on Error Handling for tips on error management strategies.

Create an account | Stellar Docs (2024)
Top Articles
USD/CAD Rebound Unravels as Fed Balance Sheet Approaches Record High
3 Tips to Teach Little Kids About Money - The Bossy Brunette
Sdn Md 2023-2024
Www.paystubportal.com/7-11 Login
Login Page
2024 Fantasy Baseball: Week 10 trade values chart and rest-of-season rankings for H2H and Rotisserie leagues
Pitt Authorized User
Self-guided tour (for students) – Teaching & Learning Support
Campaign Homecoming Queen Posters
Https //Advanceautoparts.4Myrebate.com
Newgate Honda
Bros Movie Wiki
Rosemary Beach, Panama City Beach, FL Real Estate & Homes for Sale | realtor.com®
2016 Hyundai Sonata Refrigerant Capacity
Buy Swap Sell Dirt Late Model
Petco Vet Clinic Appointment
Craigslist Clinton Ar
Theater X Orange Heights Florida
yuba-sutter apartments / housing for rent - craigslist
Bocca Richboro
Parkeren Emmen | Reserveren vanaf €9,25 per dag | Q-Park
2015 Kia Soul Serpentine Belt Diagram
Scott Surratt Salary
Craftybase Coupon
ATM, 3813 N Woodlawn Blvd, Wichita, KS 67220, US - MapQuest
Used Safari Condo Alto R1723 For Sale
How Much Is An Alignment At Costco
How To Make Infinity On Calculator
Shaman's Path Puzzle
ShadowCat - Forestry Mulching, Land Clearing, Bush Hog, Brush, Bobcat - farm & garden services - craigslist
Edward Walk In Clinic Plainfield Il
Craigslist Org Sf
Orangetheory Northville Michigan
Sephora Planet Hollywood
Mcgiftcardmall.con
Ktbs Payroll Login
5 Tips To Throw A Fun Halloween Party For Adults
The Banshees Of Inisherin Showtimes Near Reading Cinemas Town Square
B.C. lightkeepers' jobs in jeopardy as coast guard plans to automate 2 stations
Alston – Travel guide at Wikivoyage
Doublelist Paducah Ky
Europa Universalis 4: Army Composition Guide
Lawrence E. Moon Funeral Home | Flint, Michigan
Phmc.myloancare.com
Amateur Lesbian Spanking
Dayton Overdrive
Theater X Orange Heights Florida
Ihop Deliver
Sleep Outfitters Springhurst
Syrie Funeral Home Obituary
Saw X (2023) | Film, Trailer, Kritik
Craigslist Centre Alabama
Latest Posts
Article information

Author: Ray Christiansen

Last Updated:

Views: 6478

Rating: 4.9 / 5 (49 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Ray Christiansen

Birthday: 1998-05-04

Address: Apt. 814 34339 Sauer Islands, Hirtheville, GA 02446-8771

Phone: +337636892828

Job: Lead Hospitality Designer

Hobby: Urban exploration, Tai chi, Lockpicking, Fashion, Gunsmithing, Pottery, Geocaching

Introduction: My name is Ray Christiansen, I am a fair, good, cute, gentle, vast, glamorous, excited person who loves writing and wants to share my knowledge and understanding with you.