4

I'm using the JS-SDK to make offers.

An issue I am having though is getting the offerId from a new offer. The offerId is required to manage a pre-existing offer. As such, it seems that the offerId should be returned with the response object from a submitted transaction.

Once a transaction is submitted to the network an object is returned xdr.ManageOfferOp. I feel the offerId should be available within that object but I am not finding any straight-forward way of extracting that offerId.

Is there something I am missing? There doesn't seem to be much documentation on the response object xdr.ManageOfferOp.

Thank you.

UPDATE

In the above scenario I was able to fish out the offerId:

_attributes.result._value[0]._value._value._value._attributes.offersClaimed[0]._attributes.offerId

from the response object. The offerId is nested in both result_xdr and result_meta_xdr.

However, this seems very hacky.

Moreover, offerId is an object:

"offerId": {"low":6703677, "high":0, "unsigned":true}

What is low and high?

In this particular scenario, the offer was consumed the moment it went on the exchange as there was a pre-existing offer that matched to it. hat pre-existing offer, looking through the data, was assigned the offerId of 6703677. So does low indicate the offerId of the consuming offer? Had my offer persisted on the network and been assigned it's own offerId, would that then be assigned to offerId.high?

Some documentation or insight on this object itself would be useful.

3

I had the same problem with offer id after the ManageOffer operation, and I came to the same solution. If you don't have a lot of orders and don't mind to make an extra request, you can also pull account offers endpoint after submitting the ManageOffer to get all active offers and update you client-side offers state. Since OfferCreated/OfferRemoved effects are not implemented, it's the only way to get current offer status.

Offer ID is saved in int64 format. XDR format supports 64-bit integers, however JavaScript does not support 64-bit integers natively.

That's why bigint numbers are encoded as two 32-bit numbers (low and high). unsigned means that the encoded bigint number is an unsigned integer.

In order to work with bigint numbers in JavaScript (NodeJS or browser), one have to use libraries like bignumber.js.

  • 1
    Thank you for the response. I was thinking about calling the account offers endpoint as a work around. Glad to know I'm not alone. Appreciate your explanation on int64 and XDR. The 'offerId' object makes much more sense knowing that. Thank you again. – Luk3 Apr 17 '18 at 5:01

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.