Sorry for the newbie question...

When a user subscribes to my service, I would like to:

  1. Create a new stellar account for the subscriber
  2. Seed it with 1.5 XLM (to activate it)
  3. Create a Trustline and then
  4. Send it a custom asset

How can I do this?


1 Answer 1


1) You need a core + horizon server to have access to the stellar network but for the beginning you can simply start with the public ones provided by SDF (Stellar Development Foundation).

2) Pick a sdk for the language of your choice, it's api will give you all methods you need to query stellar accounts and create transactions.

3) Learn what you need to know about stellar transactions. In a nutshell: A transaction has a source account which is going to take the network transaction fees. It wraps one or more operations like payments or changing trustlines. By default operations apply to the transactions source account but you can define a different source account for each operation as well. This means you can complete your use case in a single transaction:

  • Generate a keypair for your new user
  • Create transaction from a well funded account
    • Add Operation: Create user account with starting balance of 1.5 XLM
    • Add Operation: Create a trustline from user to your asset
    • Add Operation: Send asset tokens to user
  • Sign tx with your own keypair (keypairs, if different accounts involved)
  • Sign tx with the new users keypair
  • Submit it to the network.

An easy way to get used to transactions is playing around with Stellar Laboratory Transaction Builder

4) Implement it, here is an example in javascript:

const StellarSdk = require('stellar-sdk');

(async () => {

    try {
        const horizon = new StellarSdk.Server('https://horizon-testnet.stellar.org');

        // Generate keypair for a new account
        // You might want to do this on the client side so new users
        // would not expose their secret keys
        const newAccountKeypair = StellarSdk.Keypair.random();

        // This account creates the tx and funds the new account
        const txCreatorKeypair = StellarSdk.Keypair.fromSecret(

        // This is the asset issuers account
        const assetIssuerKeypair = StellarSdk.Keypair.fromSecret(

        // Our custom asset is defined by its asset code and the issuers accountID
        const asset = new StellarSdk.Asset(

        // Load account, cause tx needs its sequence number + 1
        const account = await horizon.loadAccount(txCreatorKeypair.publicKey());

        // Build a transaction...
        const transaction = await new StellarSdk.TransactionBuilder(account)


            // ... with a createAccount operation for the new acc
                startingBalance: '1.5',
                destination: newAccountKeypair.publicKey()

            // ... create a trustline
                asset: asset,
                source: newAccountKeypair.publicKey()

            // ... send 100 fresh minted tokens from issuer
                asset: asset,
                destination: newAccountKeypair.publicKey(),
                amount: '100',
                source: assetIssuerKeypair.publicKey(),

        // Needs to sign because its creating tx and funding XLM

        // Needs to sign because funding custom asset

        console.log('This is the transaction signed by creator + issuer: ' + transaction.toEnvelope().toXDR('base64') );

        // Needs to sign because it gets a trustline created
        // Needs to be done on client side if secret is not shared.

        console.log("Submitting to network...");
        const result = await horizon.submitTransaction(transaction);

        console.log("Transaction successfully sent and recorded in ledger " + result.ledger);
        console.log("txhash = " + result.hash);
        console.log("New account public: " + newAccountKeypair.publicKey() );
        console.log("New account secret: " + newAccountKeypair.secret() );

    } catch (e) {


  • Thanks sui! Will try this now and let you know.
    – TKT
    Feb 26, 2019 at 22:02
  • One thing to note is that you can't open a trustline for your users, they will have trust your asset themselves. They can do so by submitting a transaction from the Stellar Laboratory. Feb 28, 2019 at 23:46
  • There's a core advancement proposal to change this behavior, but it's still a draft github.com/stellar/stellar-protocol/blob/master/core/… Feb 28, 2019 at 23:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.