question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Payment error "Transaction Failed"

See original GitHub issue

Hi,

I’m working on a simple API, we are using this SDK but when we try on live with this script.

var StellarSdk = require('stellar-sdk');
StellarSdk.Network.usePublicNetwork();

var keypair = StellarSdk.Keypair.fromSecret('OUR SECRET');
var server = new StellarSdk.Server('https://horizon.stellar.org');

var sourceKeypair = StellarSdk.Keypair.random();
console.log(sourceKeypair.publicKey());
console.log(sourceKeypair.secret());

var secret = sourceKeypair.secret();
var public = sourceKeypair.publicKey();



server.loadAccount(keypair.publicKey())
  .then(function(source) {
    var transaction = new StellarSdk.TransactionBuilder(source)
      .addOperation(StellarSdk.Operation.payment({
        destination: public,
        amount: "1",
        asset: StellarSdk.Asset.native()
      }))
      .build();

    transaction.sign(keypair);

    return server.submitTransaction(transaction);
})
.then(function() {
  return server.loadAccount(public)
})
.catch(function(error) {
  console.error('Error!', error);
});

We create a new account and activate it with 1 lumen, the secret of the Payment have at least 1000 lumens, but when we make the transactions, it give this error:

Error! { [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_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',
     instance: 'horizon-001a/Fm1q5QnVH4-247091670',
     extras: 
      { envelope_xdr: 'AAAAACO0e3CpDcv7A+FzZkIdKI0Jqhln3kEwK3OsVJW6fOYMAAAAZADzojYAAAAaAAAAAAAAAAAAAAABAAAAAAAAAAEAAAAA90HkP1W5wCsFRAGGKE1z1b+b7PnetRAQI6/XIo9R2PwAAAAAAAAAAACYloAAAAAAAAAAAbp85gwAAABAr1tWwYjH5fjEUL6gsgFCrJbQakDuSk6bE2AYE51NAZkH4N6f7JCkwAEH2A1XSG334sprokpxy7lWcVPW92XgBw==',
        result_codes: [Object],
        result_xdr: 'AAAAAAAAAGT/////AAAAAQAAAAAAAAAB////+wAAAAA=' } } }

Any advice?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
therealsanmahcommented, Jan 30, 2018

Just noticed that this is a new keypair you’ve generated. Whenever you create a new keypair, you don’t necessarily create an account, which means you can’t send lumens to it yet. So for the first transaction to a newly created account (read, keyPair), instead of using the StellarSdk.Operation.payment operation, you should be using StellarSdk.Operation.createAccount.

Refer to the documentation of the create operation here: https://stellar.github.io/js-stellar-sdk/Operation.html#.createAccount

3reactions
therealsanmahcommented, Jan 31, 2018

You’re welcome @bartekn

@ulisescarreonalvarez - I’ll try to answer your question from what I know.

As per the stellar network rules, an account is only said to be created when it is activated by depositing a fund (of at least 1 XLM). It might seem very confusing that to create an account you need to deposit funds, but to fund an account using the payment operation, you need to have an already activated account.

The payment operation isn’t designed to create an account on the network and fund it. I don’t know for sure, but this is my theory on why it could be so - The payment operation supports paying using a multitude of tokens, but an account is only said to be activated when it has 1 or more XLM tokens. So, what if someone tried to fund an uncreated account with some other token?

Hence, it may make sense to separate out the create account operation into a separate one, which can only be done using XLM token. Note that, the createAccount operation does not let you specify which token you want to fund it with. It only lets you input a destination and a startingBalance, which ensures that you are activating an account only using XLM tokens.

Hope that answers your question.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fix payment issues, such as declined or incomplete transactions
"Your transaction cannot be completed". A variety of different situations may trigger this message. Try these suggestions to resolve the issue:.
Read more >
Payment Errors - Failed Payment: Transaction Declined
This could mean that the card details are incorrect or the card has been reported lost or stolen. Contact your customer to follow...
Read more >
The 3 Most Effective Ways to Deal With Failed Payments
Understanding why an error message was received is vital to solving frequent failure issues. But the diagnosis isn't always simple. Payments can ...
Read more >
Why does my online credit card payment fail?
Sometimes online credit card transactions would fail - the reasons for such failure may simply be the use of a wrong card number...
Read more >
Credit Card Decline Messages: Everything You Need To Know
Understanding decline codes and error messages ... Irrespective of what's causing the payment to fail, every time a card is declined, your gateway ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found