0

I have two transactions with different signers. First transaction changes the account state, and the second one requires that account state to be changed as a constraint (it's some boolean value). I use confirmTransaction() method to wait for the first transaction to end. When I specify confirmed commitment as a parameter in the method, the second transaction fails since the state is not changed yet. When I specify finalized commitment, second transactions passes but the conformations takes too long (about 10 seconds)

Is there any way to speed up this process without waiting so long for conformation of the first one?

1 Answer 1

1

You can create multiple instructions in thesame transaction.

instruction1 = TransactionInstruction(accounts, constants.PROGRAM_ID, instruction_data)
instruction 2 = TransactionInstruction(accounts2, constants.PROGRAM_ID, instruction_data2)

transaction = Transaction()

transaction.add(instruction1)
transaction.add(instruction2)

client.send_transaction(transaction, signer1, signer2)

that way it will execute in thesame transaction, but instruction 1 will execute before instruction 2, and you wouldn't have to wait for 10s or more.

Note: This will fail if the second instruction needs to run atleast 1 slot later than instruction 1, or at a timestamp different from the timestamp of instruction 1

3
  • Can you explain why slot and timestamp matters. What needs to be aware of when writing the instructions?
    – Void
    Commented Sep 21, 2022 at 17:30
  • Single transaction with multiple signers solved our problem. @CyrialKamda-InglDAO please answer the question I ask above. Or give me a hint where should I learn those issues that you mentioned.
    – Void
    Commented Sep 22, 2022 at 10:30
  • 1
    Slot and Timestamp only matter if you have a transaction that can't be executed earlier than a specific slot or time, for example, if Instruction 1 were to include a timer, and said if instruction2 is called within the next 30 mins or 60 slots, then the instruction fails, Then Including both instructions in the transaction will always fail. Commented Sep 22, 2022 at 19:33

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.