Accounts
Overview
The primary way you interact with the Stellar network is through your account(s). Accounts are identified by a public key and saved in the ledger.
Every Stellar account has a public key and a secret seed. The public key is always safe to share—other people need it to identify your account and verify that you authorized a transaction.
The secret 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.
User accounts in the Mobius DApp Store are generated from a 24 word mnemonic phrase in browser that users save somewhere safe. From this 24 word phrase, an infinite number of accounts can be generated. Users have two types of accounts:
- The primary user account
- Their user account for each DApp
Each user has a primary user account that they must fund with lumens initially to cover the account minimum balance and transaction fees. The user can then send MOBI to that account, or buy MOBI with the lumens on that account within the DApp Store UI.
For every application the user accesses, a new user account is created using the application ID of the DApp and the user’s mnemonic phrase. A user can deposit MOBI on those accounts from their primary user account.

Walkthrough
Create DApp Instance##
Account details can be found after creating a dapp
instance using the token given to the client in the Authentication process. That token is to be sent back to the server on each request for user verification. The following sample creates a dapp
instance.
/**
* @param {string} APP_SECRET_SEED - App developer secret seed
* @param {string} USER_PUBLIC_KEY - User public key
* @returns {Promise}
*/
const dapp = await Mobius.AppBuilder.build(APP_SECRET_SEED, USER_PUBLIC_KEY);
# Takes 2 Parameters
# App Secret Seed - string
# User Public Key - String
# Returns dapp instance
def dapp
@dapp = Mobius::Client::App.new(dapp_secret_seed, user_public_key)
end
# Takes 2 Parameters
# App Secret Seed - string
# User Public Key - String
# Returns dapp instance
def dapp_instance(user_public_key):
dapp = AppBuilder().build(dapp_secret_seed, user_public_key)
return dapp
// Takes 2 parameters
// Param $APP_SECRET_SEED - App developer secret seed
// Param $USER_PUBLIC_KEY - User public key
$dapp = new Mobius\Client\App($APP_SECRET_SEED, $USER_PUBLIC_KEY);
Account Methods##
The following methods are available after creating a dapp
instance. For a more details on each method see App in the DApp Store SDK Reference.
const dappAccount = dapp.appAccount; // Returns app account {object}
const dappBalance = dapp.appBalance; // Returns app balance {int}
const dappKeypair = dapp.appKeypair; // Returns app key pair {object}
const authorized = dapp.authorized; // Returns authorized {boolean}
const userAccount = dapp.userAccount; // Returns user account {object}
const userBalance = dapp.userBalance; // Returns user balance {int}
const userKeypair = dapp.userKeypair; // Returns user public key {object}
@dapp_account = dapp.app_account # Returns app account ⇒ object
@dapp_balance = dapp.app_balance # Returns app balance ⇒ int
@dapp_keypair = dapp.app_keypair # Returns app key pair ⇒ object
@authorized = dapp.authorized? # Returns authorized ⇒ boolean
@user_account = dapp.user_account # Returns user account ⇒ object
@user_balance = dapp.user_balance # Returns user balance ⇒ int
@user_keypair = dapp.user_keypair # Returns user public key ⇒ object
dapp_account = dapp.app_account # Returns app account
dapp_balance = dapp.app_balance # Returns app balance
dapp_keypair = dapp.app_keypair # Returns app key pair
authorized = dapp.authorized # Returns authorized
user_account = dapp.user_account # Returns user account
user_balance = dapp.user_balance # Returns user balance
user_keypair = dapp.user_keypair # Returns user public key
$dapp_account = $dapp.app_account() // Returns app account
$dapp_balance = $dapp.app_balance // Returns float app balance
$dapp_keypair = $dapp.app_keypair // Returns app key pair
$authorized = $dapp.authorized // Returns boolean|array of signer
$user_account = $dapp.user_account // Returns user account
$user_balance = $dapp.balance // Returns float user balance
$user_keypair = $dapp.user_keypair // Returns user public key
Example##
The example below creates a simple endpoint on the server to get the users balance. The frontend of an application can send a request to this endpoint and the users balance would be returned.
// Using Express
app.get("/balance", async (req, res, next) => {
try {
const APP_SECRET_SEED = 'SD3XEDAPTGELU2L6XMX....KZEZRGJSPQNTXZRIC';
// req.user.sub should be the public key, found by decoding users jwt token
const dapp = await Mobius.AppBuilder.build(APP_SECRET_SEED, req.user.sub);
// return the user balance to the client
res.json({balance: dapp.userBalance});
} catch (e) {
next(e);
}
});
# GET /balance
def balance
render plain: dapp.user_balance
end
private
# dapp instance
def dapp
@dapp_secret_seed = "SD3XEDAPTGELU2L6XMX....KZEZRGJSPQNTXZRIC"
@dapp = Mobius::Client::App.new(dapp_secret_seed, user_public_key)
end
@app.route('/api/balance', methods=['GET'])
# check and decode JWT sent from client
@login_required
def balance(user_public_key):
try:
dapp = AppBuilder().build(dapp_secret_seed, user_public_key)
return jsonify({'balance': dapp.user_balance()})
except Exception as error:
return error
if($endpoint == '/api/balance' && $_SERVER['REQUEST_METHOD'] == 'GET'){
try{
// decodes JWT and returns the users public key
$public_key = getPublicKey($_GET['token']);
$dapp = new Mobius\Client\App(APP_KEY, $public_key);
echo json_encode( array( 'balance' => $dapp->balance()));
}catch(\Exception $e){
echo $e->getMessage();
}
die;
}
Using Environment Variables
Make sure you keep all the secret seeds stored safely, extracting into ENV variables or equivalent. Keys present throughout the documentation only serve for example purposes and belong to an account in the Test network.
Updated about 7 years ago