Skip to content

Commit

Permalink
Update alchemy implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
lowdisk17 committed Oct 15, 2024
1 parent 73b68ac commit 2e5adad
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 21 deletions.
18 changes: 0 additions & 18 deletions src/apiServices/customTokenApi.ts

This file was deleted.

23 changes: 23 additions & 0 deletions src/apiServices/tokenApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import log from '../lib/log';
import { getFromAlchemy } from '../services/tokenServices';

async function getTokenInfo(req, res) {
try {
let { network } = req.params;
network = network || req.query.contract;

let { address } = req.params;
address = address || req.query.address;

let value = await getFromAlchemy(address, network);

res.json(value);
} catch (error) {
log.error(error);
res.sendStatus(404);
}
}

export default {
getTokenInfo,
};
6 changes: 3 additions & 3 deletions src/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import actionApi from './apiServices/actionApi';
import ratesApi from './apiServices/ratesApi';
import ticketsApi from './apiServices/ticketsApi';
import feeService from './services/networkFeesService';
import customTokenApi from './apiServices/customTokenApi';
import tokenApi from './apiServices/tokenApi';

export default (app) => {
// return sync data
Expand Down Expand Up @@ -37,7 +37,7 @@ export default (app) => {
ticketsApi.postTicket(req, res);
});
// get key endpoint
app.get('/v1/alchemy/getkey', (req, res) => {
customTokenApi.getKey(req, res);
app.get('/v1/tokeninfo/:network/:address', (req, res) => {
tokenApi.getTokenInfo(req, res);
});
};
21 changes: 21 additions & 0 deletions src/services/tokenServices.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Alchemy, Network } from "alchemy-sdk";
import config from 'config';

export async function getFromAlchemy (contractAddress: any, network: any) {
let value : any;

// need to add here if new network with tokens
if (network == 'eth') {
value = Network.ETH_MAINNET;
} else {
value = Network.ETH_SEPOLIA;
}

const alchemy = new Alchemy({
apiKey: `${config.keys.alchemy}`,
network: value,
});

const metadata = await alchemy.core.getTokenMetadata(contractAddress);
return metadata;
}

0 comments on commit 2e5adad

Please sign in to comment.