I'm building an API to transfer assets from stellar based wallets, I am currently using the JS SDK. This is my code below:

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

router.post('/sendToken', function (req, res, next) {
  var sourceKey = req.body.source_keys;
  var issuingKeys = StellarSdk.Keypair.fromSecret(req.body.issuing_keys);
  var receivingKeys = req.body.receiving_keys;

  var l2l = new StellarSdk.Asset('L2L', sourceKey);

      .then(function (account) {
          var trusted = account.balances.some(function (balance) {
              return balance.asset_code === 'XXX' && balance.asset_issuer === sourceKey;
          if (trusted === true) {
                  .then(function (issuer) {
                    var transaction = new StellarSdk.TransactionBuilder(issuer, {
    networkPassphrase: StellarSdk.Networks.PUBLIC,
                              destination: receivingKeys,
                              asset: l2l,
                              amount: req.body.amount
                      return server.submitTransaction(transaction);
                  .then(function (result) {
                      console.log('Success! Results:', result);
                  .catch(function (error) {
                      console.error('Error!', error);
          } else {
              console.log('not trusted')

module.exports = router;

I have no idea where I'm going wrong, could anyone guide me?

  • Please add full error stacktrace to the question description.There is no way to tell where it errorred just from the code itself. Also check the extras.result_codes from the error object. – Orbit Lens Sep 19 at 2:18
  • I didn't get the extra.results_code just got a generic code of 400, here it is (node:16153) UnhandledPromiseRejectionWarning: Error: Bad Request at new NetworkError (/home/ubuntu/Stellar Material/Rest-Api/node_modules/stellar-sdk/lib/errors.js:10:24) – Raffay Ansari Sep 19 at 6:30
  • at /home/ubuntu/Stellar Material/Rest-Api/node_modules/stellar-sdk/lib/call_builder.js:241:55 at step (/home/ubuntu/Stellar Material/Rest-Api/node_modules/tslib/tslib.js:136:27) at Object.next (/home/ubuntu/Stellar Material/Rest-Api/node_modules/tslib/tslib.js:117:57) at /home/ubuntu/Stellar Material/Rest-Api/node_modules/tslib/tslib.js:110:75 at new Promise (<anonymous>) at Object.__awaiter (/home/ubuntu/Stellar Material/Rest-Api/node_modules/tslib/tslib.js:106:16) – Raffay Ansari Sep 19 at 6:32
  • However, I always get this before starting the instance Global class Network is deprecated. Please pass explicit argument instead, e.g. new Transaction(envelope, Networks.PUBLIC) (see git.io/fj9fG for more info). – Raffay Ansari Sep 19 at 6:34

Your Answer

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

Browse other questions tagged or ask your own question.