Skip to content

Commit 5aab6e2

Browse files
committed
check for tx hash on failures
1 parent 22e0702 commit 5aab6e2

30 files changed

Lines changed: 600 additions & 761 deletions

src/constants/abis/erc1155Items.ts

Lines changed: 1 addition & 454 deletions
Large diffs are not rendered by default.

src/constants/bytecodes/erc1155Items.ts

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/routes/contract/deploy/contract.ts

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
import { prepareTransactionsForTenderlySimulation } from '~/routes/contract/utils/tenderly/getSimulationUrl'
99
import { TransactionService } from '~/services/transaction.service'
1010
import { logError, logRequest, logStep } from '~/utils/loggingUtils'
11-
import { getBlockExplorerUrl, getContractAddressFromEvent } from '~/utils/other'
11+
import { extractTxHashFromErrorReceipt, getBlockExplorerUrl, getContractAddressFromEvent } from '~/utils/other'
1212
import { getSigner } from '~/utils/wallet'
1313

1414
type DeployContractRequestBody = {
@@ -90,11 +90,13 @@ export async function deployContract(fastify: FastifyInstance) {
9090
schema: DeployContractSchema
9191
},
9292
async (request, reply) => {
93-
const tenderlyUrl: string | null = null
94-
try {
95-
logRequest(request)
93+
logRequest(request)
94+
95+
let tenderlyUrl: string | null = null
96+
let txHash: string | null = null
97+
const { chainId } = request.params
9698

97-
const { chainId } = request.params
99+
try {
98100
const { args, abi, bytecode } = request.body
99101

100102
if (!bytecode.startsWith('0x')) {
@@ -132,6 +134,7 @@ export async function deployContract(fastify: FastifyInstance) {
132134
const tx = await signer.sendTransaction({
133135
data
134136
})
137+
txHash = tx.hash
135138
logStep(request, 'Deploy transaction sent', { txHash: tx.hash })
136139

137140
const { simulationData, signedTx } =
@@ -185,17 +188,27 @@ export async function deployContract(fastify: FastifyInstance) {
185188
}
186189
})
187190
} catch (error) {
188-
request.log.error(error)
191+
// Extract transaction hash from error receipt if available
192+
const errorTxHash = extractTxHashFromErrorReceipt(error)
193+
const finalTxHash = txHash ?? errorTxHash
194+
195+
logError(request, error, {
196+
params: request.params,
197+
body: request.body,
198+
txHash: finalTxHash
199+
})
200+
201+
const errorMessage =
202+
error instanceof Error
203+
? error.message
204+
: 'Failed to deploy contract'
189205
return reply.code(500).send({
190206
result: {
191-
txHash: null,
192-
txUrl: null,
207+
txHash: finalTxHash,
208+
txUrl: finalTxHash ? getBlockExplorerUrl(Number(chainId), finalTxHash) : null,
193209
txSimulationUrl: tenderlyUrl,
194210
deployedContractAddress: null,
195-
error:
196-
error instanceof Error
197-
? error.message
198-
: 'Failed to deploy contract'
211+
error: errorMessage
199212
}
200213
})
201214
}

src/routes/contract/deploy/erc1155.ts

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
import { TransactionService } from '~/services/transaction.service'
1111
import { verifyContract } from '~/utils/contractVerification'
1212
import { logError, logRequest, logStep } from '~/utils/loggingUtils'
13-
import { getBlockExplorerUrl, getContractAddressFromEvent } from '~/utils/other'
13+
import { extractTxHashFromErrorReceipt, getBlockExplorerUrl, getContractAddressFromEvent } from '~/utils/other'
1414
import { getSigner } from '~/utils/wallet'
1515

1616
type ERC1155DeployRequestBody = {
@@ -89,11 +89,13 @@ export async function erc1155Deploy(fastify: FastifyInstance) {
8989
schema: ERC1155DeploySchema
9090
},
9191
async (request, reply) => {
92-
const tenderlyUrl: string | null = null
93-
try {
94-
logRequest(request)
92+
logRequest(request)
93+
94+
let tenderlyUrl: string | null = null
95+
let txHash: string | null = null
96+
const { chainId } = request.params
9597

96-
const { chainId } = request.params
98+
try {
9799
const { defaultAdmin, minter, name } = request.body
98100

99101
logStep(request, 'Getting tx signer', { chainId })
@@ -121,6 +123,7 @@ export async function erc1155Deploy(fastify: FastifyInstance) {
121123

122124
logStep(request, 'Sending deploy transaction')
123125
const tx = await signer.sendTransaction(deploymentTx)
126+
txHash = tx.hash
124127
logStep(request, 'Deploy transaction sent', { tx })
125128

126129
const { simulationData, signedTx } =
@@ -213,20 +216,27 @@ export async function erc1155Deploy(fastify: FastifyInstance) {
213216
}
214217
})
215218
} catch (error) {
219+
// Extract transaction hash from error receipt if available
220+
const errorTxHash = extractTxHashFromErrorReceipt(error)
221+
const finalTxHash = txHash ?? errorTxHash
222+
216223
logError(request, error, {
217224
params: request.params,
218-
body: request.body
225+
body: request.body,
226+
txHash: finalTxHash
219227
})
228+
229+
const errorMessage =
230+
error instanceof Error
231+
? error.message
232+
: 'Failed to deploy ERC1155'
220233
return reply.code(500).send({
221234
result: {
222-
txHash: null,
223-
txUrl: null,
235+
txHash: finalTxHash,
236+
txUrl: finalTxHash ? getBlockExplorerUrl(Number(chainId), finalTxHash) : null,
224237
txSimulationUrl: tenderlyUrl,
225238
deployedContractAddress: null,
226-
error:
227-
error instanceof Error
228-
? error.message
229-
: 'Failed to deploy ERC1155'
239+
error: errorMessage
230240
}
231241
})
232242
}

src/routes/contract/deploy/erc1155Items.ts

Lines changed: 52 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { TransactionReceipt, TransactionResponse } from 'ethers'
22
import type { FastifyInstance } from 'fastify'
3-
import { encodeDeployData, encodeFunctionData, zeroAddress } from 'viem'
3+
import { encodeDeployData, encodeFunctionData, numberToHex, pad, zeroAddress } from 'viem'
44
import { erc1155ItemsAbi } from '~/constants/abis/erc1155Items'
55
import { erc1155ItemsBytecode } from '~/constants/bytecodes/erc1155Items'
66
import {
@@ -9,7 +9,7 @@ import {
99
} from '~/routes/contract/utils/tenderly/getSimulationUrl'
1010
import { TransactionService } from '~/services/transaction.service'
1111
import { logError, logRequest, logStep } from '~/utils/loggingUtils'
12-
import { getBlockExplorerUrl, getContractAddressFromEvent } from '~/utils/other'
12+
import { extractTxHashFromErrorReceipt, getBlockExplorerUrl, getContractAddressFromEvent } from '~/utils/other'
1313
import { getSigner } from '~/utils/wallet'
1414

1515
type ERC1155ItemsDeployRequestBody = {
@@ -19,6 +19,8 @@ type ERC1155ItemsDeployRequestBody = {
1919
tokenContractURI: string
2020
royaltyReceiver: string
2121
royaltyFeeNumerator: string
22+
implicitModeValidator: string | undefined | null
23+
implicitModeProjectId: string | undefined | null
2224
}
2325

2426
type ERC1155ItemsDeployRequestParams = {
@@ -49,7 +51,9 @@ const ERC1155ItemsDeploySchema = {
4951
'tokenBaseURI',
5052
'tokenContractURI',
5153
'royaltyReceiver',
52-
'royaltyFeeNumerator'
54+
'royaltyFeeNumerator',
55+
'implicitModeValidator',
56+
'implicitModeProjectId'
5357
],
5458
properties: {
5559
owner: { type: 'string', description: 'Address of the contract owner' },
@@ -69,7 +73,17 @@ const ERC1155ItemsDeploySchema = {
6973
royaltyFeeNumerator: {
7074
type: 'string',
7175
description: 'Royalty fee numerator (e.g., 500 for 5%)'
72-
}
76+
},
77+
implicitModeValidator: {
78+
type: 'string',
79+
description: 'Address of the implicit mode validator',
80+
nullable: true
81+
},
82+
implicitModeProjectId: {
83+
type: 'string',
84+
description: 'Implicit mode project ID',
85+
nullable: true
86+
}
7387
}
7488
},
7589
params: {
@@ -117,18 +131,24 @@ export async function erc1155ItemsDeploy(fastify: FastifyInstance) {
117131
schema: ERC1155ItemsDeploySchema
118132
},
119133
async (request, reply) => {
120-
const deploymentSimulationUrl: string | null = null
121-
const initializationSimulationUrl: string | null = null
134+
logRequest(request)
135+
136+
let deploymentSimulationUrl: string | null = null
137+
let initializationSimulationUrl: string | null = null
138+
let deploymentTxHash: string | null = null
139+
let initializationTxHash: string | null = null
140+
const { chainId } = request.params
141+
122142
try {
123-
logRequest(request)
124-
const { chainId } = request.params
125143
const {
126144
owner,
127145
tokenName,
128146
tokenBaseURI,
129147
tokenContractURI,
130148
royaltyReceiver,
131-
royaltyFeeNumerator
149+
royaltyFeeNumerator,
150+
implicitModeValidator,
151+
implicitModeProjectId
132152
} = request.body
133153

134154
logStep(request, 'Getting tx signer', { chainId })
@@ -160,6 +180,7 @@ export async function erc1155ItemsDeploy(fastify: FastifyInstance) {
160180
const deployTx: TransactionResponse = await signer.sendTransaction({
161181
data: deployData
162182
})
183+
deploymentTxHash = deployTx.hash
163184
logStep(request, 'Deployment transaction sent', { deployTx })
164185

165186
const {
@@ -239,7 +260,9 @@ export async function erc1155ItemsDeploy(fastify: FastifyInstance) {
239260
tokenBaseURI,
240261
tokenContractURI,
241262
royaltyReceiver,
242-
BigInt(royaltyFeeNumerator)
263+
BigInt(royaltyFeeNumerator),
264+
implicitModeValidator ?? zeroAddress,
265+
pad(numberToHex(Number(implicitModeProjectId ?? 0)), { size: 32 })
243266
]
244267
})
245268
logStep(request, 'Initialize data prepared', { initializeData })
@@ -268,6 +291,7 @@ export async function erc1155ItemsDeploy(fastify: FastifyInstance) {
268291

269292
logStep(request, 'Sending initialization transaction')
270293
const initializeTx = await signer.sendTransaction(initializationTx)
294+
initializationTxHash = initializeTx.hash
271295
logStep(request, 'Initialization transaction sent')
272296

273297
logStep(request, 'Waiting for initialization receipt', {
@@ -319,25 +343,34 @@ export async function erc1155ItemsDeploy(fastify: FastifyInstance) {
319343
}
320344
})
321345
} catch (error) {
346+
// Extract transaction hash from error receipt if available
347+
const errorTxHash = extractTxHashFromErrorReceipt(error)
348+
const finalDeploymentTxHash = deploymentTxHash ?? errorTxHash
349+
const finalInitializationTxHash = initializationTxHash ?? errorTxHash
350+
322351
logError(request, error, {
323352
params: request.params,
324-
body: request.body
353+
body: request.body,
354+
deploymentTxHash: finalDeploymentTxHash,
355+
initializationTxHash: finalInitializationTxHash
325356
})
357+
358+
const errorMessage =
359+
error instanceof Error
360+
? error.message
361+
: 'Failed to deploy and initialize ERC1155Items contract'
326362
return reply.code(500).send({
327363
result: {
328-
deploymentTxHash: null,
329-
deploymentTxUrl: null,
330-
initializationTxHash: null,
331-
initializationTxUrl: null,
364+
deploymentTxHash: finalDeploymentTxHash,
365+
deploymentTxUrl: finalDeploymentTxHash ? getBlockExplorerUrl(Number(chainId), finalDeploymentTxHash) : null,
366+
initializationTxHash: finalInitializationTxHash,
367+
initializationTxUrl: finalInitializationTxHash ? getBlockExplorerUrl(Number(chainId), finalInitializationTxHash) : null,
332368
deployedContractAddress: null,
333369
txSimulationUrls: [
334370
deploymentSimulationUrl ?? '',
335371
initializationSimulationUrl ?? ''
336372
],
337-
error:
338-
error instanceof Error
339-
? error.message
340-
: 'Failed to deploy and initialize ERC1155Items contract'
373+
error: errorMessage
341374
}
342375
})
343376
}

src/routes/contract/deploy/erc20.ts

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
verifyContract
1515
} from '~/utils/contractVerification'
1616
import { logError, logRequest, logStep } from '~/utils/loggingUtils'
17-
import { getBlockExplorerUrl, getContractAddressFromEvent } from '~/utils/other'
17+
import { extractTxHashFromErrorReceipt, getBlockExplorerUrl, getContractAddressFromEvent } from '~/utils/other'
1818
import { getSigner } from '~/utils/wallet'
1919

2020
type ERC20DeployRequestBody = {
@@ -104,11 +104,13 @@ export async function erc20Deploy(fastify: FastifyInstance) {
104104
schema: ERC20DeploySchema
105105
},
106106
async (request, reply) => {
107-
const tenderlyUrl: string | null = null
108-
try {
109-
logRequest(request)
107+
logRequest(request)
108+
109+
let tenderlyUrl: string | null = null
110+
let txHash: string | null = null
111+
const { chainId } = request.params
110112

111-
const { chainId } = request.params
113+
try {
112114
const { initialOwner, name, symbol } = request.body
113115

114116
logStep(request, 'Getting tx signer', { chainId })
@@ -138,6 +140,7 @@ export async function erc20Deploy(fastify: FastifyInstance) {
138140
const tx = await signer.sendTransaction({
139141
data
140142
})
143+
txHash = tx.hash
141144
logStep(request, 'Deploy transaction sent', { tx })
142145

143146
const { simulationData, signedTx } =
@@ -242,18 +245,27 @@ export async function erc20Deploy(fastify: FastifyInstance) {
242245
}
243246
})
244247
} catch (error) {
248+
// Extract transaction hash from error receipt if available
249+
const errorTxHash = extractTxHashFromErrorReceipt(error)
250+
const finalTxHash = txHash ?? errorTxHash
251+
245252
logError(request, error, {
246253
params: request.params,
247-
body: request.body
254+
body: request.body,
255+
txHash: finalTxHash
248256
})
257+
258+
const errorMessage =
259+
error instanceof Error
260+
? error.message
261+
: 'Failed to deploy ERC20'
249262
return reply.code(500).send({
250263
result: {
251-
txHash: null,
252-
txUrl: null,
264+
txHash: finalTxHash,
265+
txUrl: finalTxHash ? getBlockExplorerUrl(Number(chainId), finalTxHash) : null,
253266
txSimulationUrl: tenderlyUrl,
254267
deployedContractAddress: null,
255-
error:
256-
error instanceof Error ? error.message : 'Failed to deploy ERC20'
268+
error: errorMessage
257269
}
258270
})
259271
}

0 commit comments

Comments
 (0)