Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/lemon-squids-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@relayprotocol/relay-sdk': patch
---

Fix tenderly error api
68 changes: 62 additions & 6 deletions packages/sdk/src/utils/getTenderlyDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,76 @@ import { axios } from './axios.js'

export type TenderlyErrorInfo = {
error_message?: string
address?: string
error?: string
}

export const getTenderlyDetails = (
chainId: number,
txHash: string
): Promise<TenderlyErrorInfo | null> => {
return new Promise((resolve) => {
axios
.get(`https://api.tenderly.co/api/v1/explorer/${txHash}`, {
timeout: 5000
})
.get(
`https://api.tenderly.co/api/v1/public-contract/${chainId}/trace/${txHash}`,
{
timeout: 5000
}
)
.then((response) => {
if (response && response.data && response.data.error_info) {
resolve(response.data.error_info)
if (response && response.data) {
// Extract error message from stack_trace
if (
response.data.stack_trace &&
response.data.stack_trace.length > 0
) {
const errorTrace = response.data.stack_trace.find(
(trace: any) => trace.error_message
)
if (errorTrace) {
resolve({
error_message: errorTrace.error_message,
error: errorTrace.error
})
return
}
}

// Fallback to call_trace if no error message in stack_trace
if (response.data.call_trace) {
// Check root call_trace first
if (response.data.call_trace.error_message) {
resolve({
error_message: response.data.call_trace.error_message,
error: response.data.call_trace.error
})
return
}

// Check nested calls
if (
response.data.call_trace.calls &&
Array.isArray(response.data.call_trace.calls)
) {
const callWithError = response.data.call_trace.calls.find(
(call: any) => call && call.error_message
)
if (callWithError) {
resolve({
error_message: callWithError.error_message,
error: callWithError.error
})
return
}
}

// If no error_message found in call_trace, at least return the error
if (response.data.call_trace.error) {
resolve({
error: response.data.call_trace.error
})
return
}
}
}
resolve(null)
})
Expand Down
3 changes: 3 additions & 0 deletions packages/sdk/src/utils/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,12 @@ export async function sendTransactionSafely(
if (signal.aborted) {
return
}

let tenderlyError: TenderlyErrorInfo | null = null

if (receipt && (receipt as TransactionReceipt).transactionHash) {
tenderlyError = await getTenderlyDetails(
chainId,
(receipt as TransactionReceipt).transactionHash
)
}
Expand Down