How to obtain the ContractId : Java

Can we obtain the contractId on the submission of the command on the ledger? If so then how.

Like in JS we get it in callback response, so is there any functionality available in java for the same.

Are there any methods or sample projects available for reference?

1 Like

If you are using the CommandClient you can submitAndWaitForTransaction, which returns a Transaction object that represents the result of the command you submitted, which in turn contains all the persistent events, including contract creations with their contract identifier. If you are interested in seeing the full transaction, including transient and non-consuming events you can use the submitAndWaitForTransactionTree method, which returns TransactionTrees for your command.

If you are using a mix of the CommandSubmissionClient, CommandCompletionClient and TransactionClient the latter offers methods to read both Transactions and TransactionTrees for the relevant commands you submitted.

You can read more about all of these in the reference documentation for the Java bindings (here for version 1.14.0).