Skip to content

Instantly share code, notes, and snippets.

@gregsantos
Created October 27, 2021 21:16
Show Gist options
  • Save gregsantos/ef83e9bafbf7454b2bb961f815cc7fef to your computer and use it in GitHub Desktop.
Save gregsantos/ef83e9bafbf7454b2bb961f815cc7fef to your computer and use it in GitHub Desktop.
get transaction hash before send
let txIdCalculated = null
const getTxHash = async () => {
const txIdFromChain = await sdk.decode(
await sdk.send(
await sdk.resolve(
await sdk.build([
sdk.transaction`transaction(msg: String) { prepare(acct: AuthAccount) {} execute { log(msg) } }`,
sdk.args([sdk.arg("Hello, Flow!", t.String)]),
sdk.payer(fcl.currentUser().authorization),
sdk.proposer(fcl.currentUser().authorization),
sdk.authorizations([fcl.currentUser().authorization]),
sdk.preSendCheck(async voucher => {
txIdCalculated = sdk.voucherToTxId(voucher)
}),
])
),
{node: "https://access-testnet.onflow.org"}
)
)
console.log("TX ID", txIdFromChain)
console.log("Pre calculated TxID", txIdCalculated)
invariant(txIdCalculated === txIdFromChain, "Uh oh, didn't work")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment