2

As per stellar documentation they provide manageOffer function to create, update and delete an offer, i am enable to use this function can anybody please help me to give me some instructions or any code reference which help me to create new offers.

2 Answers 2

1

The manage offer operation is used to create a new offer. Just set the offer id to 0, or omit it.

offerId number | string optional

If 0, will create a new offer (default). Otherwise, edits an exisiting offer.

0
0
//initialize stellar sdk
var StellarSdk = require('stellar-sdk')
        StellarSdk.Network.useTestNetwork();
        var server = new StellarSdk.Server('https://horizon-testnet.stellar.org');
var op ={
                selling: selling_asset,
                buying: buying_asset,
                amount: amount,
                price: price,
                offerId:0 // for creating new offer id must be 0
              }
        var sourcePublicKey = sourceKeypair.publicKey();
        server.loadAccount(sourcePublicKey)
          .then(function(account) {
            var transaction = new StellarSdk.TransactionBuilder(account)
              // Add a manageOffer operation
              .addOperation(StellarSdk.Operation.manageOffer(op))
              .build();
//sign transaction
            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(err);                   
              });
          })
          .catch(function(e) {
            console.error(e);
          });
1
  • Would you mind improving your answer by adding explanations to your code. Feb 26, 2018 at 16:23

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.