• General
  • Paying lumens from root account to a keypair.

dzham

Should this operation be wrapped in a transaction? Also, I know, that the source is optional. However, the explanation on the page is not clear; "Defaults to the transaction's source account.". For now, I am using the root account because, I want to fund this account to begin with.

This is my approach:

var transaction = new StellarSdk.TransactionBuilder(sourceAccount)
  .addOperation(StellarSdk.Operation.createAccount({
  destination: destinationId,
  startingBalance: xferAmount,
  source : sourceKeys.publicKey()
}))
  .addMemo(StellarSdk.Memo.text('Test Transaction'))
  .build();
  
transaction.sign(sourceKeys);
server.submitTransaction(transaction);

Your approach looks good.

"source" in an operation is only needed if it's not the same account as the one you initialize your TransactionBuilder with.

    dzham

    ok, this is what I get:

    /home/champ/node_modules/stellar-base/lib/transaction_builder.js:143
                    var sequenceNumber = new BigNumber(this.source.sequenceNumber()).add(1);
                                                                   ^
    
    TypeError: this.source.sequenceNumber is not a function
        at TransactionBuilder.build (/home/champ/node_modules/stellar-base/lib/transaction_builder.js:143:64)
        at Object.<anonymous> (/home/champ/launch/STELLAR/js/acts.js:23:4)
        at Module._compile (module.js:410:26)
        at Object.Module._extensions..js (module.js:417:10)
        at Module.load (module.js:344:32)
        at Function.Module._load (module.js:301:12)
        at Function.Module.runMain (module.js:442:10)
        at startup (node.js:136:18)
        at node.js:966:3

    This is what I am using:

    StellarSdk.Network.use(new StellarSdk.Network(NETWORK_PASSPHRASE));
    var opts = new StellarSdk.Config.setAllowHttp(true);
    var server = new StellarSdk.Server(HORIZON_ENDPOINT, opts);
    var sourceKeys = StellarSdk.Keypair.fromSecret(fromWallet);
    var destinationId = toWallet;
    
    var transaction = new StellarSdk.TransactionBuilder(sourceKeys.publicKey())
      .addOperation(StellarSdk.Operation.createAccount({
        destination: destinationId,
        startingBalance: xferAmount,
        source : sourceKeys.publicKey()
      }))
      .addMemo(StellarSdk.Memo.text('Test Transaction'))
      .build();
      
    transaction.sign(sourceKeys);
    server.submitTransaction(transaction);

    You need to put it inside

    server.loadAccount(sourceKeys.publicKey())
    .then(function(sourceAccount) {
    }

      Yay! Got it working now. Thanks, dzham ?

      Here is my final attempt.

      var sourceKeys = StellarSdk.Keypair.fromSecret(fromWallet);
      var destinationId = toWallet;
      
      server.loadAccount(sourceKeys.publicKey())
        .then(function(sourceAccount) {
          var txn = new StellarSdk.TransactionBuilder(sourceAccount)
                      .addOperation(StellarSdk.Operation.createAccount({
                          destination: destinationId,
                          startingBalance: xferAmount
                        }
                        )
                      )
                      .addMemo(StellarSdk.Memo.text('Test Transaction')
                      )
                      .build();
                      
          txn.sign(sourceKeys);
          return server.submitTransaction(txn);
          })
        .then(function(result) {
          console.log('Success! Results:', result);
        })
        .catch(function(error) {
          console.error('Something went wrong!', error);
        });
      a year later

      getting error:

      txn.sign(sourceKeys); return undefined.

      full logs:

      Something went wrong! { [BadResponseError: Transaction submission failed. Server responded: 400 Bad Request]
      name: 'BadResponseError',
      message: 'Transaction submission failed. Server responded: 400 Bad Request',
      data:
      { type: 'https://stellar.org/horizon-errors/transaction_failed',
      title: 'Transaction Failed',
      status: 400,
      detail: 'The transaction failed when submitted to the stellar network. The
      extras.result_codesfield on this response contains further details. Descriptions of each code can be found at: https://www.stellar.org/developers/learn/concepts/list-of-operations.html',
      extras:
      { envelope_xdr: 'AAAAAAddjXCk31Sls13W6FA9O55705UkKWBV3snLfHR5zYuLAAAAZAAAAAAAAAABAAAAAAAAAAEAAAAQVGVzdCBUcmFuc2FjdGlvbgAAAAEAAAABAAAAAAddjXCk31Sls13W6FA9O55705UkKWBV3snLfHR5zYuLAAAAAAAAAAAZ/fuhypNHFtstyD79BIWNcWG4TdSIrajl/W8U0GIE9QAAAAJUC+QAAAAAAAAAAAF5zYuLAAAAQC34xSbG919Gk3ODPDZE5WgqXcduYulTLI8mK2yKCMNDhuvloXEjrTKTZ46Y7xdaAkMH+suTUL4LGVN+QUs0IwM=',
      result_codes: [Object],
      result_xdr: 'AAAAAAAAAGT////6AAAAAA==' } } }

        sohan

        Hard to say when result_codes isn't visible

        Build with Laboratory at my local node:
        {
        "type": "https://stellar.org/horizon-errors/transaction_failed",
        "title": "Transaction Failed",
        "status": 400,
        "detail": "The transaction failed when submitted to the stellar network. The
        extras.result_codesfield on this response contains further details. Descriptions of each code can be found at: https://www.stellar.org/developers/learn/concepts/list-of-operations.html",
        "extras": {
        "envelope_xdr": "AAAAAAddjXCk31Sls13W6FA9O55705UkKWBV3snLfHR5zYuLAAAAZAAAAAAAAAABAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAARWUmcRfF2d9inSCk+kUg1XsC/XyDEjzkLUZ0o2wpuq4AAAAAO5rKAAAAAAAAAAABec2LiwAAAEBW4ujJyAknsEHCY5+5CKHx6Lybi5h1lU9BvNG0bSxLAqzuWT6Tc4yJEbGNQdtbUv8RWjhPbWDXUkeZQuhVMCgK",
        "result_codes": {
        "transaction": "tx_bad_auth"
        },
        "result_xdr": "AAAAAAAAAGT////6AAAAAA=="
        }
        }

        I am trying send fund from root account,

          4 months later
          2 months later
          { type: 'https://stellar.org/horizon-errors/transaction_failed',
            title: 'Transaction Failed',
            status: 400,
            detail: 'The transaction failed when submitted to the stellar network. The `extras.result_codes` field on this response contains further details.  Descriptions of each code can be found at: https://www.stellar.org/developers/learn/concepts/list-of-operations.html',
            extras:
             { envelope_xdr: 'AAAAADI5YN09kKPH/l0f2RoBfi+BFoiPO51ZjjImbH0oWMXkAAAAZAAAAAAAAAABAAAAAAAAAAEAAAAQVGVzdCBUcmFuc2FjdGlvbgAAAAEAAAAAAAAAAAAAAAA1Wp87mEGFy+krPwRIIheem0UFQpINZNy/hO0ZI8DGIwAAAAA7msoAAAAAAAAAAAEoWMXkAAAAQA9ZMJ+nKrbbrPa2Gxzj1cwhOKdkS0YJWCHwZLeFTaTQXotRcFmjI/stk+faP0ABklU9vZJ3sODuki755lnmcQg=',
               result_codes: { transaction: 'tx_bad_seq' },
               result_xdr: 'AAAAAAAAAGT////7AAAAAA==' } }

          tx_bad_seq is coming for me while sending from root account to new keypair. any idea about it?

            Vishwas1 This is my guess as I don't know the protocol in depth but "bad sequence" probably means that the Sequence Number you sent in your transaction is not what Horizon expected.
            If you check your account (e.g. https://horizon.stellar.org/accounts/GAREELUB43IRHWEASCFBLKHURCGMHE5IF6XSE7EXDLACYHGRHM43RFOX ) you can see a value like
            "sequence": "27707856228712522",
            If you submit a transaction with this number incremented +1, you should be good.