How can I generate an ID of a transaction before submitting it to an RPC node? I know I can get a transaction signature as a result of web3.sendAndConfirmTransaction call but is it possible to generate the signature deterministically?
1 Answer
You can manually sign the transaction before sending it, and then retrieve signature:
const bs58 = require('bs58');
// build a transaction
const transaction = new Transaction(...);
// sign it explicitly
transaction.sign(...signers);
// retrieve the signature as base58
const signature = bs58.encode(transaction.signature())
You will need to already have a blockhash defined and set against the transaction for this to work.
This will not work with sendTransaction
, which re-signs everything. So serialize the message directly to send:
const message = transaction.serialize();
connection.sendRawTransaction(message)
signature[0]
), not hashes. I'd suggest updating your question to clarify this fact and avoid propagating misinformation