-
[Intern] Range api 트랜잭션 반환 데이터 확인 / 해시값 조회시 출발 및 도착 체인 정보 반환하도록 구현Intern/Project 2024. 12. 11. 18:59
✏ 근무 내용
- range api 사용해 프론트 연동 개발
⭐근무 결과
[range api 활용해 개발]
파라미터로 해시값만 넣었을 때 원하는 데이터가 모두 조회된다!
{ "resources": [ { "sorting_key": "2024-11-20 01:41:23+00ethereum/0x33a6efd2d5dc0b012dce53d8fc6a4fcf608cb20bd2bc087b1fe733c2e129faaa/139318", "id": "ethereum/0x33a6efd2d5dc0b012dce53d8fc6a4fcf608cb20bd2bc087b1fe733c2e129faaa/139318", "burn_hash": "0x33a6efd2d5dc0b012dce53d8fc6a4fcf608cb20bd2bc087b1fe733c2e129faaa", "mint_hash": null, "transfer_hash": "0xaee2ca3e0e7ad134f0ba21d32974d06100f0f0b52b8214e1bae813434fed0634", "from": "0xf18f923480dc144326e6c65d4f3d47aa459bb41c", "destination": "0xf18f923480dc144326e6c65d4f3d47aa459bb41c", "minter": null, "from_network": "ethereum", "destination_network": "arbitrum", "amount": "12106555272", "denom": "uusdc", "status": "SUCCEEDED", "from_timestamp": "2024-11-20T01:41:23.000Z", "destination_timestamp": "2024-11-20T01:58:52.000Z", "from_block": "21225730", "destination_block": "276291452", "nonce": "139318", "is_forwarding": null, "forwarding_channel": null, "forwarding_target": null, "forwarding_address": null, "created_at": "2024-11-20T03:41:09.598Z", "txn_type": "MAINNET", "details": null, "is_synced_to_payments": true } ], "metadata": { "count": 1, "txnType": "MAINNET", "direction": "first", "limit": "5", "txHash": "0x33a6efd2d5dc0b012dce53d8fc6a4fcf608cb20bd2bc087b1fe733c2e129faaa", "source": "", "destination": "", "status": "", "min_usd": "", "max_usd": "" } }
위 api를 사용해 해시값 넣으면 출발 및 도착 체인 정보 반환하도록 아래 코드 구현했다
- api.service.ts 주요 코드
async getTransactionDetails(txHash: string) { try { const apiUrl = `https://usdc.range.org/usdc/api/transfers?txHash=${txHash}&txnType=MAINNET&limit=5&direction=first&source=&destination=&status=&min_usd=&max_usd=`; const response = await axios.get(apiUrl); const data = response.data.resources; if (data && data.length > 0) { return { enteredTx: txHash, // 입력한 해시값 bridge: `${data[0].from_network} -> ${data[0].destination_network}`, sourceTx: { chain: data[0].from_network, timestamp: data[0].from_timestamp, address: data[0].from, hash: data[0].burn_hash, value: data[0].amount, }, destinationTx: { chain: data[0].destination_network, timestamp: data[0].destination_timestamp, address: data[0].destination, hash: data[0].transfer_hash, value: data[0].amount, }, status: data[0].status, }; } return null; } catch (error) { console.error(error.message); throw new Error('Failed to fetch transaction details'); } }
- index.html 주요 코드
function displayBridge(txHash, bridge, sourceTx, destinationTx) { const container = document.getElementById('bridgeInfo'); const explorers = { 'bsc': 'https://bscscan.com', 'arbitrum': 'https://arbiscan.io', 'Arbitrum': 'https://arbiscan.io', 'ethereum': 'https://etherscan.io', 'Mainnet': 'https://etherscan.io', 'base': 'https://basescan.org' // 필요한 다른 체인과 익스플로러 링크를 여기 추가 }; container.innerHTML = ` <div class="bridge-info-card"> <h3>Entered Tx:</h3> ${txHash} <p><strong>Bridge:</strong> ${sourceTx.chain} -> ${destinationTx.chain}</p> </div> <div class="bridge-info-card"> <h3>Source Tx (${sourceTx.chain})</h3> <p><strong>Date:</strong> ${new Date(sourceTx.timestamp).toLocaleString()} UTC</p> <p><strong>Sender:</strong> <a href="${explorers[sourceTx.chain]}/address/${sourceTx.address}" target="_blank">${sourceTx.address}</a></p> <p><strong>Tx Hash:</strong> <a href="${explorers[sourceTx.chain]}/tx/${sourceTx.hash}" target="_blank">${sourceTx.hash}</a></p> <p><strong>Value:</strong> ${sourceTx.value}</p> </div> <div class="bridge-info-card"> <h3>Destination Tx (${destinationTx.chain})</h3> <p><strong>Date:</strong> ${new Date(destinationTx.timestamp).toLocaleString()} UTC</p> <p><strong>Receiver:</strong> <a href="${explorers[destinationTx.chain]}/address/${destinationTx.address}" target="_blank">${destinationTx.address}</a></p> <p><strong>Tx Hash:</strong> <a href="${explorers[destinationTx.chain]}/tx/${destinationTx.hash}" target="_blank">${destinationTx.hash}</a></p> <p><strong>Value:</strong> ${(destinationTx.value / 10**18).toFixed(4)}</p> </div> `; }
반응형'Intern > Project' 카테고리의 다른 글
[Intern] 캐싱 및 redis 사용 검색 속도 향상 적용 (0) 2024.12.12 [Intern] Source 트랜잭션 value 값 확인 및 검증 (0) 2024.12.11 [Intern] Moralis api 데이터 검증 / 대체 api 찾기 (0) 2024.12.09 [Intern] Moralis api로 조회 안되는 데이터들 조회되도록 구현 (토큰의 양) (0) 2024.12.08 [Intern] 해시값 조회 안되는 체인 데이터 조회되도록 구현 / Moralis api 데이터 log분석 (0) 2024.12.08