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.

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.

| improve this answer | |
  • Can you have a source code reference because i am trying so many source code but nothing helps me to create a new offer as i have tried the offerId param to 0 also may be my code didn't work. – Aman Kamboj Feb 21 '18 at 6:35
  • It should be very similar to stellar.org/developers/js-stellar-sdk/reference/examples.html except with manage offer instead of payment operation. Please update your question with what you have tried and what the error is. – Synesso Feb 21 '18 at 7:23
  • I am getting below error: TypeError: opts.selling.toXDRObject is not a function at Function.manageOffer – Aman Kamboj Feb 22 '18 at 6:08
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);
          });
| improve this answer | |
  • Would you mind improving your answer by adding explanations to your code. – Bartek Nowotarski Feb 26 '18 at 16:23
  • How did you resolve : : opts.selling.toXDRObject is not a function at Function.manageOffer ? I am also getting same error. – Prashant Prabhakar Singh Apr 3 '18 at 10:58
  • @PrashantPrabhakarSingh did you try to use above code source ? – Aman Kamboj Apr 9 '18 at 1:05
  • Yes, I did. The problem was the way I was declaring asset names. Resolved it. :) – Prashant Prabhakar Singh Apr 9 '18 at 5:25

Your Answer

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

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