Skip to content

Commit 4f81739

Browse files
committed
add get FT price endpoint
1 parent 8679c39 commit 4f81739

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/server.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
} from "./transactions-transfer-history";
1515
import prisma from "./prisma";
1616
import { tokens } from "./constants/tokens";
17+
import axios from "axios";
1718

1819
dotenv.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
279304
if (process.env.NODE_ENV !== "test") {
280305
app.listen(port, hostname, () => {

0 commit comments

Comments
 (0)