Skip to content

Commit

Permalink
Merge pull request #18 from RunOnFlux/custom-token-import
Browse files Browse the repository at this point in the history
Custom token import
  • Loading branch information
TheTrunk authored Oct 27, 2024
2 parents 4ce7355 + bc30a03 commit 2489bb8
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 8 deletions.
17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,28 @@
"author": "Tadeas Kmenta",
"license": "MIT",
"dependencies": {
"@runonflux/aa-schnorr-multisig-sdk": "~1.0.3",
"@runonflux/aa-schnorr-multisig-sdk": "~1.0.4",
"@runonflux/utxo-lib": "~1.0.0",
"apicache": "~1.6.3",
"axios": "~1.7.3",
"axios": "~1.7.7",
"bchaddrjs": "~0.5.2",
"bignumber.js": "~9.1.2",
"bitcoinjs-lib": "~6.1.6",
"chai": "~4.4.1",
"config": "~3.3.12",
"cors": "~2.8.5",
"express": "~4.19.2",
"firebase-admin": "~12.3.0",
"express": "~4.21.1",
"firebase-admin": "~12.6.0",
"freshdesk-client": "~1.9.1",
"lru-cache": "~11.0.0",
"lru-cache": "~11.0.1",
"mocha": "~10.7.0",
"mongodb": "~6.8.0",
"mongodb": "~6.10.0",
"morgan": "~1.10.0",
"node-cmd": "~5.0.0",
"qs": "~6.13.0",
"socket.io": "~4.7.5",
"viem": "~2.18.8",
"socket.io": "~4.8.0",
"viem": "~2.21.32",
"alchemy-sdk": "~3.4.4",
"zelcorejs": "https://github.com/zelcore-io/zelcorejs"
},
"devDependencies": {
Expand Down
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;

const value = await getFromAlchemy(address, network);

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

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

export default (app) => {
// return sync data
Expand Down Expand Up @@ -35,4 +36,8 @@ export default (app) => {
app.post('/v1/ticket', (req, res) => {
ticketsApi.postTicket(req, res);
});
// get key endpoint
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 2489bb8

Please sign in to comment.