1

This is my code

var sourceSecretKey = 'REDACTED';

var sourceKeypair = StellarSdk.Keypair.fromSecret(sourceSecretKey);
var sourcePublicKey = sourceKeypair.publicKey();


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

server.loadAccount(sourcePublicKey)
    .then(function(account) {            
    var transaction = new StellarSdk.TransactionBuilder(account, {                
        fee: StellarSdk.BASE_FEE        
    })
        // Add a manageOffer operation
        .addOperation(StellarSdk.Operation.manageBuyOffer({
        selling: new StellarSdk.Asset.native(),
        buying: new StellarSdk.Asset('ABC', 'GDFBWP6GYJE7PMA4HVLLSPG6346Z67XAME7C2WJIUIA5HGJEJWFWIBPI'),
        amount: '1000000000',
        price: '15.6250000',
        offerId: '0'
        }))
        .addMemo(StellarSdk.Memo.text('Hello'))
        .setTimeout(180)
        .build();

    transaction.sign(sourceKeypair);

     console.log(transaction.toEnvelope().toXDR('base64'));    

    server.submitTransaction(transaction)
        .then(function(transactionResult) {

         console.log(JSON.stringify(transactionResult, null, 2));
         console.log('\nSuccess! View the transaction at: ');
         console.log(transactionResult._links.transaction.href);

        })
        .catch(function(err) {
         console.log('An error has occured:');
         console.log(JSON.stringify(err, null, ' '));                                                                            

        });
    })
    .catch(function(e) {
     console.error(e);

    });

The stringified error prints merely the following:

{
 "message": "Request failed with status code 400",
 "name": "Error",
 "stack": "Error: Request failed with status code 400\n    at createError (http://127.0.0.1:5500/bower_components/stellar-sdk/stellar-sdk.js:27374:15)\n    at settle (http://127.0.0.1:5500/bower_components/stellar-sdk/stellar-sdk.js:46113:12)\n    at XMLHttpRequest.handleLoad (http://127.0.0.1:5500/bower_components/stellar-sdk/stellar-sdk.js:27236:7)",
 "config": {
  "url": "https://horizon.stellar.org/transactions",
  "method": "post",
  "data": "tx=AAAAAJ2XxPOBZhImQhYvufkgoiaUvlcAA3oYpZpxw4uO%2F3GeAAAAZAGEyw0AAATMAAAAAQAAAAAAAAAAAAAAAF2JMHkAAAABAAAADkNhcnJpZWQgb3V0IG9uAAAAAAABAAAAAAAAAAMAAAAAAAAAAVVTRAAAAAAA6KYahh5gr2D4B3PgY0blxyy%2BWdyt2jdgjVjvQlEdn9wAAAEcW7%2BrgAAKCWsAmJaAAAAAAAAAAAAAAAAAAAAAAY7%2FcZ4AAABAlRB9uf3I2heyWIMNwVp6VWobugg%2B%2FC70y9%2Fplzf%2FCH0orSMapSHVhhYS%2FE78e9Hc2vDw84hfyMQrwLeZ1%2BVVDA%3D%3D",
  "headers": {
   "Accept": "application/json, text/plain, */*",
   "Content-Type": "application/x-www-form-urlencoded",
   "X-Client-Name": "js-stellar-sdk",
   "X-Client-Version": "2.0.1"
  },
  "transformRequest": [
   null
  ],
  "transformResponse": [
   null
  ],
  "timeout": 60000,
  "xsrfCookieName": "XSRF-TOKEN",
  "xsrfHeaderName": "X-XSRF-TOKEN",
  "maxContentLength": -1
 }
}

The error occurs after submitting the transaction. I would like to see the extras field of the error in order to specifically identify what caused the error. More info at https://www.stellar.org/developers/horizon/reference/errors/transaction-failed.html

1 Answer 1

2

Altough I don't see a e.response property in your output and I'm not up to date with the latest js-sdk, I think it should still be e.response.data.extras

try {
  await server.submitTransaction(...)
} catch (e) {
  console.log(e.response.data.extras);
}```

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.