0

I am trying to send a payment on stellar testnet. I have already created both accounts using https://friendbot.stellar.org. So both account have a balance. When I am sending payment it is showing "Something went wrong!" but no error is showing. I have checked the code and found that upon calling build() the program throws an error, which is caught in the catch block. Could anyone tell me what error could be thrown by the build function?

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

StellarSdk.Network.useTestNetwork();

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

var sourceKeys = StellarSdk.Keypair
  .fromSecret('SCZANGBA5YHTNYVVV4C3U252E2B6P6F5T3U6MM63WBSBZATAQI3EBTQ4');

var destinationId = 'GA2C5RFPE6GCKMY3US5PAB6UZLKIGSPIUKSLRB6Q723BM2OARMDUYEJ5';
// Transaction will hold a built transaction we can resubmit if the result is unknown.

var transaction;


// First, check to make sure that the destination account exists.
// You could skip this, but if the account does not exist, you will be charged
// the transaction fee when the transaction fails.

server.loadAccount(destinationId)
  // If the account is not found, surface a nicer error message for logging.

  .catch(StellarSdk.NotFoundError, function (error) {

    throw new Error('The destination account does not exist!');

  })

  // If there was no error, load up-to-date information on your account.
  .then(function() {

    return server.loadAccount(sourceKeys.publicKey());

  })
  .then(function(sourceAccount) {

    // Start building the transaction.

    transaction = new StellarSdk.TransactionBuilder(sourceAccount)

      .addOperation(StellarSdk.Operation.payment({

        destination: destinationId,

        // Because Stellar allows transaction in many currencies, you must
        // specify the asset type. The special "native" asset represents Lumens.

        asset: StellarSdk.Asset.native(),

        amount: "10"

      }))

      // A memo allows you to add your own metadata to a transaction. It's
      // optional and does not affect how Stellar treats the transaction.

      .addMemo(StellarSdk.Memo.text('Test Transaction'))

      .build();

    // Sign the transaction to prove you are actually the person sending it.

    transaction.sign(sourceKeys);

    // And finally, send it off to Stellar!

    return server.submitTransaction(transaction);

  })

  .then(function(result) {

    console.log('Success! Results:', result);

  })

  .catch(function(error) {

    console.error('Something went wrong!', error);

    // If the result is unknown (no response body, timeout etc.) we simply resubmit

    // already built transaction:

    // server.submitTransaction(transaction);

  });
1

Not sure why you think it's thrown by build() Usually errors are thrown when you try to submit invalid transaction.

you're dumping whole error object, that's why you can't see what's on 3rd nesting level of response you're getting from horizon.

if you dig down in your error handling to

.catch(function(error) {
    console.error('Something went wrong!', error.response.data.extras);
})

you will be able to see response from horizon:

{ envelope_xdr: 'AAAAALQVLw52HjIVKlqx4rWxgwxV1OlUImbKUYmkx5i70s4oAAAAZAAEntQAAAKeAAAAAAAAAAEAAAAQVGVzdCBUcmFuc2FjdGlvbgAAAAEAAAAAAAAAAQAAAAA0LsSvJ4wlMxukuvAH1MrUg0nooqS4h9D+thZpwIsHTAAAAAAAAAAABfXhAAAAAAAAAAABu9LOKAAAAECYx+8d6GbUPXPutCvns31u/m/A2TsKHABKSOKwaqG2FqlQvcopBrZOaTvqIhoL3zDCwr9+gWYOKE3aKsOhLOkD',
  result_codes: { transaction: 'tx_failed', operations: [ 'op_underfunded' ] },
  result_xdr: 'AAAAAAAAAGT/////AAAAAQAAAAAAAAAB/////gAAAAA=' }

['op_underfunded'] is what we've been looking for

This error message means you don't have enough funds to send this amount

Your source account for the secret key that you posted GC2BKLYOOYPDEFJKLKY6FNNRQMGFLVHJKQRGNSSRRGSMPGF32LHCQVGF

currently has 1.8833 XLM, which is not enough to send 10.

  • wlhen i am using error.response.data.extras then i am getting error Cannot read property 'data' of undefined. – Eithan pitt Feb 14 at 8:42
  • I am sending payment from secret key "SAOUNYUBZDO3T3BIS2TC4W3TD6T5K5LQMQYKYQHJZYCEVS2KEG52OWA4" to destination key "GDSQT7FFLLVVU2KW33D52DIOGDGPXCK5HVHMLOBAF6YY5VKUKFFETFXF". on testnet – Eithan pitt Feb 14 at 8:46
  • could you send me verified code for send transactions with above keys ? – Eithan pitt Feb 15 at 9:07

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.