Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request for an official support to calculate the Transaction hash #704

Closed
andys-ab opened this issue Jul 7, 2021 · 2 comments
Closed

Request for an official support to calculate the Transaction hash #704

andys-ab opened this issue Jul 7, 2021 · 2 comments
Assignees
Labels
Feature JS Seen 👀 This Issue has been seen by the Flow-JS-SDK Maintainers and they are thinking about it.

Comments

@andys-ab
Copy link

andys-ab commented Jul 7, 2021

Right now, there isnt a way to get the transaction hash before it is being sent to the blockchain. The only way to do it is to take out a part of the code in @onflow/sdk to create a transaction object and apply a SHA3 onto the transaction object to get the transaction hash. Then every time the sdk updates, that part of code needs to be updated as well. That would be great if there is an official support for this.

Pre-calculating the transaction hash is important. This allows us to perform error recovery if there are any network connection issues during the submission of the transaction.

@orodio orodio added JS Seen 👀 This Issue has been seen by the Flow-JS-SDK Maintainers and they are thinking about it. and removed Feedback labels Jul 7, 2021
@orodio
Copy link
Contributor

orodio commented Jul 7, 2021

@andys-ab this has come up a couple times now, thanks for creating an issue for it.

Would something like this work?

var txId = await fcl.send([
  fcl.transaction(CODE),
  fcl.payer(fcl.authz),
  fcl.proposer(fcl.authz),
  fcl.authorizations([fcl.authz]),
  
  // we would add this ability as a middleware
  // It would be executed/resolved right before transaction is sent
  // it would wait for the callback function to complete before sending the transaction
  // if the callback throws an error it would halt the transaction
  fcl.preSendCheck(async voucher => {
    // we would supply the ability to go from the voucher to the hash (txId)
    var txId = fcl.voucherToTxId(voucher)
    
    // you can make an async to your backend to keep track of the hash
    await sendHashToBackend(txId)
    
    // could throw an error here if you wanted which would halt the transaction.
  })
])

For safety you shouldnt be able to modify the voucher or the transaction that will be sent at this point, so its really just giving you a hook that enables you to pause before sending, do your business, and then continue if everything is good or throw an error.

with the newer mutate syntax i would imagine it would look something like this

var txId = await mutate({
  cadence: CODE,
  preSendCheck: async voucher => {
    // ... do your stuff here
  }
})

Would the above solve your issues? If it doesn't can you elaborate on why it wouldn't.

@orodio orodio self-assigned this Jul 7, 2021
@andys-ab
Copy link
Author

andys-ab commented Jul 8, 2021

Hi @orodio,

This would definitely work for us. One thing bothers me is the voucher variable. Are you referring to the object that includes the payloadSigs and the envelopeSigs ? if yes, I think the name voucher is a bit confusing. Apart from this, everything looks good.

So do you have an estimated time to roll this out? Just want to have an estimation about having this update in my production servers.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature JS Seen 👀 This Issue has been seen by the Flow-JS-SDK Maintainers and they are thinking about it.
Projects
None yet
Development

No branches or pull requests

3 participants