3

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.

  • 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 – EndingWithAli Mar 16 '18 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/… :) – EndingWithAli Mar 16 '18 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? – igorescento Mar 17 '18 at 0:27
4

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.

  • hey I had a question on this. You could in theory, from your example, can you have more than one payout of the same thing? Like if Entity A wants to pay for two different services and the second service completes first, but is setup the same way? You would just have to manage the sequence number? Or does the first transactions have to complete first before A can spend more stellar? – thekevshow Jun 22 '18 at 14:48

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.