0

whenever I run this HTML page

<!Doctype html>
<html> 
    <head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/stellar-sdk/0.11.0/stellar-sdk.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/stellar-base/0.9.0/stellar-base.js"></script>

    <script>
        function myFunction()
        {
            var server = new StellarSdk.Server('https://horizon-testnet.stellar.org');
            StellarSdk.Network.useTestNetwork();
            StellarBase.Network.useTestNetwork();
            var sender_sk = 'SCOWI2SSVFMO32LM233H5WFGPYMHPWHHZ2TS5VHBOELIBKHRT4SNLXVI';
            var sender_pair = StellarSdk.Keypair.fromSecret(sender_sk);
            var sender_pk = sender_pair.publicKey();
            var recipient_sk = 'SAPZY3RFSSZUH66EM2VOJ2MAMNYTPI7E26OUW4ZKTR34E6Q64UOIGTU3';
            var recipient_pair = StellarSdk.Keypair.fromSecret(recipient_sk);
            var recipient_pk = recipient_pair.publicKey();
            // making up our own currency quest 
            var quest = new StellarSdk.Asset('quest',sender_pk);
            
            server.loadAccount(recipient_pk)
                .then(function(account) 
                {
                var transaction = new StellarSdk.TransactionBuilder(account).
                addOperation(StellarSdk.Operation.changeTrust
                    ({
                    asset : quest,
                    limit : "100000" 
               
                    }) )
                    .build();   
                    transaction.sign(recipient_pair); 
                    server.submitTransaction(transaction);
                    console.log("Trustline created");
                })
            // server.loadAccount(sender_pk)
            //  .then(function(account) 
            //  {
            //  var transaction = new StellarSdk.TransactionBuilder(account)
            //  .addOperation(StellarSdk.Operation.payment
            //          ({
            //          destination : recipient_pk,
            //          asset : quest,
            //          amount :'5',
               
            //          }))
            //      .build();   
            //      transaction.sign(sender_pair); 
            //      server.submitTransaction(transaction);
                
            //  })


        }
    </script>

        Hello world
    </head>
<body>
    <h1> Stellar Blockchain  </h1>

        <p> Create a trustline between two accounts</p>     

        <p id = demo>  </p>

        <button type="button" onclick="myFunction()">Create Trustline</button>
</body>
</html>

i get this error

stellar-sdk.js:9457 POST https://horizon-testnet.stellar.org/transactions 400 (Bad Request)
dispatchXhrRequest @ stellar-sdk.js:9457
xhrAdapter @ stellar-sdk.js:9291
dispatchRequest @ stellar-sdk.js:9972
Promise.then (async)
request @ stellar-sdk.js:8934
Axios.<computed> @ stellar-sdk.js:8954
wrap @ stellar-sdk.js:8848
submitTransaction @ stellar-sdk.js:3788
(anonymous) @ createTrustline.html:34
Promise.then (async)
myFunction @ createTrustline.html:23
onclick @ createTrustline.html:67
stellar-sdk.js:9514 Uncaught (in promise) Error: Request failed with status code 400
    at createError (stellar-sdk.js:9514)
    at settle (stellar-sdk.js:9484)
    at XMLHttpRequest.handleLoad (stellar-sdk.js:9356)
createError @ stellar-sdk.js:9514
settle @ stellar-sdk.js:9484
handleLoad @ stellar-sdk.js:9356
XMLHttpRequest.send (async)
dispatchXhrRequest @ stellar-sdk.js:9457
xhrAdapter @ stellar-sdk.js:9291
dispatchRequest @ stellar-sdk.js:9972
Promise.then (async)
request @ stellar-sdk.js:8934
Axios.<computed> @ stellar-sdk.js:8954
wrap @ stellar-sdk.js:8848
submitTransaction @ stellar-sdk.js:3788
(anonymous) @ createTrustline.html:34
Promise.then (async)
myFunction @ createTrustline.html:23
onclick @ createTrustline.html:67

can anyone please help me solve this

New contributor
Nandini Sharda is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Your Answer

Nandini Sharda is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.