diff --git a/src/nit.ts b/src/nit.ts index 9ec3d38..207d549 100644 --- a/src/nit.ts +++ b/src/nit.ts @@ -315,7 +315,7 @@ export async function pull(assetCid: string, blockchainInfo) { // } //} -export async function commit(assetCid: string, commitData: string, blockchainInfo) { +export async function commit(assetCid: string, commitData: string, blockchainInfo, confirms: number = 1) { const commitString = addActionNameInCommit(commitData); let r; if (blockchainInfo.gasPrice != null) { @@ -324,7 +324,9 @@ export async function commit(assetCid: string, commitData: string, blockchainInf } else { r = await blockchainInfo.contract.commit(assetCid, commitString, { gasLimit: blockchainInfo.gasLimit }); } - return r; + + // Wait for the transaction to be mined + return await r.wait(confirms); } export async function log(assetCid: string, blockchainInfo, fromIndex: number, toIndex: number = null) { diff --git a/src/run.ts b/src/run.ts index 5347e37..1825c43 100644 --- a/src/run.ts +++ b/src/run.ts @@ -609,10 +609,14 @@ async function main() { } else { commitEventIndexCid = nit.assetCidMock; } - const commitResult = await nit.commit(commitEventIndexCid, JSON.stringify(commitData), blockchain); - console.log(`Commit Tx: ${commitResult.hash}`); - console.log(`Commit Explorer: ${blockchain.explorerBaseUrl}/${commitResult.hash}`); + try { + const transactionReceipt = await nit.commit(commitEventIndexCid, JSON.stringify(commitData), blockchain); + console.log(`Commit Tx: ${transactionReceipt.transactionHash}`); + console.log(`Commit Explorer: ${blockchain.explorerBaseUrl}/${transactionReceipt.transactionHash}`); + } catch (error) { + console.error(`Transaction error: ${error}`); + } // Reset stage await setWorkingAssetCid("");