Create an Account
The first thing you’ll need to do anything on the XDBchain network is an account. Accounts hold all your money inside XDBchain and allow you to send and receive payments—in fact, pretty much everything in XDBchain is in some way tied to an account.
Every XDBchain account has a public key and a secret seed. XDBchain uses public key cryptography to ensure that every transaction is secure. The public key is always safe to share—other people need it to identify your account and verify that you authorized a transaction. The seed, however, is private information that proves you own your account. You should never share the seed with anyone. It’s kind of like the combination to a lock—anyone who knows the combination can open the lock. In the same way, anyone who knows your account’s seed can control your account.
If you’re familiar with public key cryptography, you might be wondering how the seed differs from a private key. The seed is actually the single secret piece of data that is used to generate both the public and private key for your account. XDBchain’s tools use the seed instead of the private key for convenience: To have full access to an account, you only need to provide a seed instead of both a public key and a private key.1
Because the seed must be kept secret, the first step in creating an account is creating your own seed and key—when you finally create the account, you’ll send only the public key to a XDBchain server. You can generate the seed and key with the following command:
1
2
3
4
5
6
7
8
9
// create a completely new and unique pair of keys
// see more about KeyPair objects: https://stellar.github.io/js-stellar-sdk/Keypair.html
const StellarSdk = require("stellar-sdk");
const pair = StellarSdk.Keypair.random();
pair.secret();
// SBJZCCGQAGHG2ONCF6HKTFAQKVIJNIHK7VDTH4RCA2OB4P5UK52MMF3Q
pair.publicKey();
// GAFKDVZ4E4YFAEZZGAOYTNWJTVK7XBC4WF5FMZ4PMJUAPAZYU4N4MHEB
Now that you have a seed and public key, you can create an account. In order to prevent people from making a huge number of unnecessary accounts, each account must have a minimum balance of 1 XDB (XDBs are the built-in currency of the XDBchain network).2 Since you don’t yet have any XDBs, though, you can’t pay for an account. In the real world, you’ll usually pay an exchange that sells XDBs in order to create a new account. On XDBchain’s test network, however, you can ask Friendbot, our friendly robot with a very fat wallet, to create an account for you.
To create a test account, send Friendbot the public key you created. It’ll create and fund a new account using that public key as the account ID.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// 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.futurenet.xdbchain.com?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);
}
})();
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.
1
2
3
4
5
6
7
8
const server = new StellarSdk.Server("https://horizon.futurenet.xdbchain.com");
// 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.
A private key is still used to encrypt data and sign transactions. When you create a
KeyPair
object using a seed, the private key is immediately generated and stored internally. ↩Other features of XDBchain, like trust lines, require higher minimum balances. For more on minimum balances, see fees. ↩