1

I am using the python py-stellar-base to create a new offer operation.

To manage the offer in the future I want to be able to retrieve the created offer_id from the completed transaction.

builder.append_manage_offer_op(
    selling_code=selling_asset_code,
    selling_issuer=selling_issuer,
    buying_code=buying_asset_code,
    buying_issuer=buying_issuer,
    amount=amount,
    price=price,
    offer_id=0,
    source=seller_address
)
builder.add_text_memo('Offer')
builder.sign()

builder.submit()

I have gone through the documentation and can't see how I should retrieve the offer_id after doing the submit.

Does the builder return the ID after a successful transaction?

1

It's contained in the horizon response which can be decoded like this:

response = builder.submit()

result_bytes = base64.b64decode(response['result_xdr'])
tx_result = Xdr.StellarXDRUnpacker(result_bytes).unpack_TransactionResult()

offerId = tx_result.result.results[0].tr.manageOfferResult.success.offer.offer.offerID

print(offerId)

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.