4

I would like to create a simple escrow account with two preauthorized timebound transactions, but not sure how to approach the problem. I am fairly new to Stellar, so correct me if I am wrong.

I have to build two transactions with different destinations but same sequence number (one higher than current on the acc). Third transaction will contain 2 signers with tx1.hash() and tx2.hash() with some weight e.g. 2 on both. This one will be signed and submitted.

How can I send same preauth transaction in the future so it matches the signer key? Do i have to store the original transactions as XDR? I am using stellar-sdk, building both works, signers are also getting created. Just need to get on the right track, maybe whole approach is completely wrong.

3
  • Looking for a few points of clarification here: - "How can I send same preauth transaction in the future so it matches the signer key?" -> are you asking how to submit a new 4th txn in the future that has the same properties (same hash and xdr) as the 3rd txn? Basically youre looking to automate a txn of a specific type? for your listed txns in the 2nd paragraph, can you clarify the source accounts and the operations youre thinking about? for your txn 3, which account is this happening on, and when do you set that these 2 txns must be signers? cont'd Commented Mar 16, 2018 at 18:10
  • are txn 1 and 2 submitted to the network? also something that might help is our guide on multisig escrow accounts : something that might help also is our stellar.org/developers/guides/walkthroughs/… :) Commented Mar 16, 2018 at 18:11
  • Apologize for the confusion. Let's start with the first point. The examples are good, but not much about preauth in action. I want to prepare future transaction and add the hash as a signer. Then at some point in the future i want to use this saved transaction (providing i created it with proper sequence number). Is it possible to store it using let encodedEnvelope = transaction.toEnvelope().toXDR().toString("base64") and use in the future as let tx2 = new StellarSdk.Transaction(encodedEnvelope) ? If above is correct, how do I sign? tx2.sign(keypair) or using the hash?
    – user1138
    Commented Mar 17, 2018 at 0:27

1 Answer 1

5

So after some exploration of pre-authorized transactions, I have written a medium post on my findings and an example use case here.

Yes, the basic approach is as follows:

  1. Create the two pre-authorized transactions with current sequence number + 2
  2. Create a third transaction with current sequence number + 1. This transaction will add the two transaction hashes from above as signers.
  3. Sign and submit transaction 3 to the network so that transactions 1 and 2 are added as signers.
  4. Submit either transaction 1 or transaction 2 (since these are added as signers, they are already pre-authorized and don't need to be signed). Once this is submitted, the transaction will be removed from the account as a signer.

Overall, I lay this all out in the article I linked to above, so give it a peak :)

I also have some example code in javascript here.

0

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.