alchemy/get-token-metadata: stripped DB logic, now pure API call viem/get-transaction-details: stripped DB logic, now pure viem call tokens/get-metadata: new DB-first wrapper for token metadata transactions/get-details: new DB-first wrapper for tx details transactions/get-history: stores individual Alchemy transfers in tx_history table with blockNum, from, to columns for searchable ordering
51 lines
1.3 KiB
TypeScript
51 lines
1.3 KiB
TypeScript
import { isHex, type PublicClient } from 'viem'
|
|
|
|
export const getTransactionDetails = async (
|
|
client: PublicClient,
|
|
hash: string,
|
|
) => {
|
|
if (!isHex(hash)) return null
|
|
|
|
const [tx, receipt] = await Promise.all([
|
|
client.getTransaction({ hash }),
|
|
client.getTransactionReceipt({ hash }),
|
|
])
|
|
|
|
return {
|
|
tx: {
|
|
hash: tx.hash,
|
|
from: tx.from,
|
|
to: tx.to ?? null,
|
|
value: tx.value,
|
|
blockNumber: tx.blockNumber ?? null,
|
|
gasPrice: tx.gasPrice ?? null,
|
|
gas: tx.gas,
|
|
input: tx.input,
|
|
nonce: tx.nonce,
|
|
type: tx.type ?? 'legacy',
|
|
blockHash: tx.blockHash ?? null,
|
|
maxFeePerGas: tx.maxFeePerGas ?? null,
|
|
maxPriorityFeePerGas: tx.maxPriorityFeePerGas ?? null,
|
|
transactionIndex: tx.transactionIndex ?? null,
|
|
v: tx.v ?? null,
|
|
r: tx.r?.toString() ?? null,
|
|
s: tx.s?.toString() ?? null,
|
|
yParity: tx.yParity ?? null,
|
|
},
|
|
receipt: {
|
|
blockHash: receipt.blockHash,
|
|
blockNumber: receipt.blockNumber,
|
|
from: receipt.from,
|
|
to: receipt.to ?? null,
|
|
cumulativeGasUsed: receipt.cumulativeGasUsed,
|
|
gasUsed: receipt.gasUsed,
|
|
status: receipt.status,
|
|
effectiveGasPrice: receipt.effectiveGasPrice ?? null,
|
|
contractAddress: receipt.contractAddress ?? null,
|
|
type: receipt.type,
|
|
transactionIndex: receipt.transactionIndex,
|
|
logsBloom: receipt.logsBloom?.toString() ?? null,
|
|
},
|
|
}
|
|
}
|