This code successfully creates a new account, and funds it with 5 XLM, but it does not add trust lines to the account. Is it acceptable to chain a changeTrust operation within this transaction? Or do I need to construct a separate change trust operation, signed by the new account?

This also does not write to firebase. Any idea why?

const functions = require('firebase-functions');
const admin = require('firebase-admin');

const StellarSdk = require('stellar-sdk');
var server = new StellarSdk.Server('https://horizon-testnet.stellar.org');

var publicKey = 'xxx';
var secretKey = 'xxx';
var sourceKeyPair = StellarSdk.Keypair.fromSecret(secretKey);
var issuerPublicKey = 'xxx';

exports.createAccount = functions.https.onCall((data, context) => {

    var newPublicKey = data.publicKey;

    .then(function(source) {

      var transaction = new StellarSdk.TransactionBuilder(source)

        destination: newPublicKey,
        startingBalance: '5',
        asset: new StellarSdk.Asset('USD', issuerPublicKey),
        asset: new StellarSdk.Asset('GOLD', issuerPublicKey),


        .then(function(transactionResult) {
            console.log(JSON.stringify(transactionResult, null, 2));
                publicKey: newPublicKey,
        .catch(function(err) {
            console.log('An error has occured:');
    .catch(function(err) {


You have to specify the affected new account, otherwise all operations within a transaction refer to the account that creates the transaction (sourceKeyPair in your case).

              asset: asset,
              source: newPublicKey
  • 1
    ... and apply one more signature on the transaction with corresponding secret key. – Orbit Lens Jan 31 '19 at 23:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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