1

What is op_cross_self error? I can create offers for 2 Assets ( selling and buying ).

But when creating a reverse offer for same asset, it's throwing :

    { transaction: 'tx_failed', operations: [ 'op_cross_self' ] }

This is how i'm making an offer:

module.exports.makingOfferNativetoUSD = async (clientSK,amt,rate,cutDown) => {

  const client = StellarSdk.Keypair.fromSecret(clientSK);
  let rate_converted = parseFloat(rate).toFixed(7);
  let total_amt = parseFloat( parseFloat(amt).toFixed(7) * 
  (rate_converted)).toFixed(7);
  let USD = new StellarSdk.Asset('USD', source.publicKey());
  if(cutDown){
  rate_converted = parseFloat(rate_converted - 0.01).toFixed(7);
  }

  var op ={
    selling: StellarSdk.Asset.native(),
    buying:  USD,
    amount: amt+"",
    price: rate_converted+"",
    offerId:0 
  }

 return server.loadAccount(client.publicKey())
    .then(function(account) {
      var transaction = new StellarSdk.TransactionBuilder(account)
      .addOperation(StellarSdk.Operation.changeTrust({
        asset: USD
      }))
        .addOperation(StellarSdk.Operation.manageOffer(op))
        .setTimeout(10000)
        .build();
      transaction.sign(StellarSdk.Keypair.fromSecret(client.secret()));
      return server.submitTransaction(transaction);

    })
    .catch(function(err) {
      console.error(err);
      return err; 
    });

}

And creating another offer to accept it :

module.exports.sellRevOfferUSDtoNative = async (clientSK,amt,rate,cutDown) => {

  const client = StellarSdk.Keypair.fromSecret(clientSK);
  let USD = new StellarSdk.Asset('USD', source.publicKey());
  let rate_converted = parseFloat(rate).toFixed(7);
  let total_amt = parseFloat(amt).toFixed(7);
  let buyPrice =  parseFloat (1 / rate_converted).toFixed(7) ;

  if(cutDown){
    buyPrice = parseFloat(buyPrice - 1.5).toFixed(7);
    }
  let op ={
    selling: USD,
    buying:  StellarSdk.Asset.native(),
    amount: total_amt+"",
    price: buyPrice+"",
    offerId:0 
  }

 return server.loadAccount(client.publicKey())
    .then(function(account) {
      var transaction = new StellarSdk.TransactionBuilder(account)
        .addOperation(StellarSdk.Operation.manageOffer(op))
        .setTimeout(10000)
        .build();
      transaction.sign(StellarSdk.Keypair.fromSecret(client.secret()));
      return server.submitTransaction(transaction);

    })
    .catch(function(err) {
      console.error(err.response.data);
      return err.response.data.extras.result_codes; 
    });

}

What does op_cross_self actually mean? And also each time offer ID is 0.

  • If you indeed want to accept the offer you created, you should use a different account to post the second offer. – ire_and_curses Apr 18 at 18:11
2

It is the MANAGE_OFFER_CROSS_SELF error described in the guides and it prevents you from unintentionally fullfilling your own previous offer:

The account has opposite offer of equal or lesser price active, so the account creating this offer would immediately cross itself.

You should have a look at passive offers for this case.

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.