I am having some issues with an application I'm trying to build. I am new to JS.
What I am trying to accomplish:
Sending 2 variables (wallet, amount) to the function transferLumens. These 2 variables come from another function where amount and wallet are stored in a list. This list is looped through to get wallet and amount thrown to transferLumens function.
I checked the passing variables and they are valid.
The payment's go through sometimes but it fails more than anything. The error code is:
Error: Request failed with status code 400 ...
result_codes: { transaction: 'tx_bad_seq' },
result_xdr: 'AAAAAAAAAGT////7AAAAAA==' }
The guide for Stellar Developers, sequenceNumbers was some what helpful. How do I get the currenct sequence number before a transaction submit?
Any guidance is much appreciated.
function transferLumens(wallet, amount) {
var StellarSdk = require('stellar-sdk');
var server = new StellarSdk.Server('https://horizon-testnet.stellar.org');
StellarSdk.Network.useTestNetwork();
var sourceKeys = StellarSdk.Keypair
.fromSecret('SECRETKEY');
//var testamount = "2.4";
server.loadAccount(wallet)
.catch(StellarSdk.NotFoundError, function (error) {
throw new Error('The destination account does not exist!');
})
.then(function () {
return server.loadAccount(sourceKeys.publicKey());
})
.then(function (sourceAccount) {
transaction = new StellarSdk.TransactionBuilder(sourceAccount)
.addOperation(StellarSdk.Operation.payment({
destination: wallet,
asset: StellarSdk.Asset.native(),
amount: amount
}))
.addMemo(StellarSdk.Memo.text("TEST PAYMENT"))
.build();
transaction.sign(sourceKeys);
// console.log(transaction.toEnvelope().toXDR('base64'));
return server.submitTransaction(transaction);
})
.then(function (result) {
console.log('Success! Results:', result);
})
.catch(function (error) {
console.error('Something went wrong!', error);
});
}
error.response.data.extras
will give you more information about the error. You can check the errors here stellar.org/developers/guides/concepts/list-of-operations.html – Bartek Nowotarski Jul 18 '18 at 19:27