@@ -113,7 +113,7 @@ export const fetchAddressInfo = async (address: string): Promise<AddressResponse
113113export const fetchTransactionInfo = async ( txid : string ) : Promise < TransactionResponse > => {
114114 try {
115115 const response = await retryRequest ( ( ) =>
116- bitcoinApi . get ( `/tx /${ txid } ` )
116+ blockchainApi . get ( `/rawtx /${ txid } ?format=json ` )
117117 ) ;
118118
119119 if ( ! response . data ) {
@@ -122,23 +122,26 @@ export const fetchTransactionInfo = async (txid: string): Promise<TransactionRes
122122
123123 const data = response . data ;
124124
125- return {
126- txid : data . txid ,
127- blockHeight : data . blockHeight || 0 ,
128- blockTime : data . blockTime || Math . floor ( Date . now ( ) / 1000 ) ,
125+ // Process the transaction data
126+ const processedData : TransactionResponse = {
127+ txid : data . hash ,
128+ blockHeight : data . block_height || 0 ,
129+ blockTime : data . time || Math . floor ( Date . now ( ) / 1000 ) ,
129130 confirmations : data . confirmations || 0 ,
130- fees : data . fees || '0' ,
131+ fees : data . fee ? ( data . fee / 100000000 ) . toString ( ) : '0' , // Convert satoshis to BTC
131132 size : data . size || 0 ,
132- value : data . value || '0' ,
133- vin : ( data . vin || [ ] ) . map ( ( input : any ) => ( {
134- addresses : input . addresses || [ ] ,
135- value : input . value || '0'
133+ value : data . total ? ( data . total / 100000000 ) . toString ( ) : '0' , // Convert satoshis to BTC
134+ vin : ( data . inputs || [ ] ) . map ( ( input : any ) => ( {
135+ addresses : input . prev_out ?. addr ? [ input . prev_out . addr ] : [ ] ,
136+ value : input . prev_out ?. value ? ( input . prev_out . value / 100000000 ) . toString ( ) : '0' // Convert satoshis to BTC
136137 } ) ) ,
137- vout : ( data . vout || [ ] ) . map ( ( output : any ) => ( {
138- addresses : output . addresses || [ ] ,
139- value : output . value || '0'
138+ vout : ( data . out || [ ] ) . map ( ( output : any ) => ( {
139+ addresses : output . addr ? [ output . addr ] : [ ] ,
140+ value : output . value ? ( output . value / 100000000 ) . toString ( ) : '0' // Convert satoshis to BTC
140141 } ) )
141142 } ;
143+
144+ return processedData ;
142145 } catch ( error ) {
143146 console . error ( 'Error fetching transaction info:' , error ) ;
144147 if ( axios . isAxiosError ( error ) ) {
0 commit comments