Payment error "Transaction Failed"
See original GitHub issueHi,
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:
- Created 6 years ago
- Comments:9 (1 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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 usingStellarSdk.Operation.createAccount
.Refer to the documentation of the create operation here: https://stellar.github.io/js-stellar-sdk/Operation.html#.createAccount
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 adestination
and astartingBalance
, which ensures that you are activating an account only using XLM tokens.Hope that answers your question.