File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed
Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ import {
1414} from "./transactions-transfer-history" ;
1515import prisma from "./prisma" ;
1616import { tokens } from "./constants/tokens" ;
17+ import axios from "axios" ;
1718
1819dotenv . config ( ) ;
1920
@@ -275,6 +276,30 @@ app.get(
275276 }
276277) ;
277278
279+ app . get (
280+ "/api/ft-token-price" ,
281+ async ( req : Request , res : Response ) => {
282+ try {
283+ const { account_id } = req . query ;
284+
285+ const contract = account_id === 'near' ? 'wrap.near' : account_id ;
286+ const { data } = await axios . get (
287+ `https://api.nearblocks.io/v1/fts/${ contract } ` ,
288+ {
289+ headers : {
290+ Authorization : `Bearer ${ process . env . NEARBLOCKS_API_KEY } ` ,
291+ } ,
292+ }
293+ ) ;
294+ const contractData = data ?. contracts ?. [ 0 ] ;
295+ return res . send ( { price :parseFloat ( contractData . price ) || 0 } ) ;
296+ } catch ( error ) {
297+ console . error ( "Error fetching data:" , error ) ;
298+ return res . status ( 500 ) . send ( { error : "An error occurred" } ) ;
299+ }
300+ }
301+ ) ;
302+
278303// Start the server
279304if ( process . env . NODE_ENV !== "test" ) {
280305 app . listen ( port , hostname , ( ) => {
You can’t perform that action at this time.
0 commit comments