From f2e5a3b09879425b15f270a4899f87d1647a2205 Mon Sep 17 00:00:00 2001 From: mariacarmina Date: Mon, 23 Sep 2024 13:28:58 +0300 Subject: [PATCH] Add try/catch for failed transactions when deploying new NFT. --- package-lock.json | 4 +++- src/contracts/NFTFactory.ts | 38 ++++++++++++++++++++----------------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/package-lock.json b/package-lock.json index eca735ff..adf264d2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2973,7 +2973,8 @@ "node_modules/@oceanprotocol/contracts": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-2.0.3.tgz", - "integrity": "sha512-D2YtlsgmhBuSmF/Ue8zMWPtXNiB4zgW09NjUQzvDFrloUo0a7yC8r8L84LrVniw+0Nmly/PhLcdm8i018yc34g==" + "integrity": "sha512-D2YtlsgmhBuSmF/Ue8zMWPtXNiB4zgW09NjUQzvDFrloUo0a7yC8r8L84LrVniw+0Nmly/PhLcdm8i018yc34g==", + "license": "Apache-2.0" }, "node_modules/@octokit/auth-token": { "version": "3.0.3", @@ -7953,6 +7954,7 @@ "url": "https://www.buymeacoffee.com/ricmoo" } ], + "license": "MIT", "dependencies": { "@ethersproject/abi": "5.7.0", "@ethersproject/abstract-provider": "5.7.0", diff --git a/src/contracts/NFTFactory.ts b/src/contracts/NFTFactory.ts index 86a736ae..5b37e28b 100644 --- a/src/contracts/NFTFactory.ts +++ b/src/contracts/NFTFactory.ts @@ -67,23 +67,27 @@ export class NftFactory extends SmartContractWithAddress { ) if (estimateGas) return estGas // Invoke createToken function of the contract - const tx = await sendTx( - estGas, - this.signer, - this.config?.gasFeeMultiplier, - this.contract.deployERC721Contract, - nftData.name, - nftData.symbol, - nftData.templateIndex, - ZERO_ADDRESS, - ZERO_ADDRESS, - nftData.tokenURI, - nftData.transferable, - nftData.owner - ) - const trxReceipt = await tx.wait() - const events = getEventFromTx(trxReceipt, 'NFTCreated') - return events.args[0] + try { + const tx = await sendTx( + estGas, + this.signer, + this.config?.gasFeeMultiplier, + this.contract.deployERC721Contract, + nftData.name, + nftData.symbol, + nftData.templateIndex, + ZERO_ADDRESS, + ZERO_ADDRESS, + nftData.tokenURI, + nftData.transferable, + nftData.owner + ) + const trxReceipt = await tx.wait() + const events = getEventFromTx(trxReceipt, 'NFTCreated') + return events.args[0] + } catch (e) { + console.error(`Creation of AccessList failed: ${e}`) + } } /**