total-torn-supply-watcher/server.ts

28 lines
809 B
TypeScript
Raw Normal View History

2023-06-15 01:14:47 +03:00
import express from "express";
import Web3 from "web3";
import BigNumber from "bignumber.js";
import * as dotenv from "dotenv";
dotenv.config();
import TornTokenABI from "./abi/tornTokenABI.json";
const web3 = new Web3(process.env.MAINNET_RPC_URL);
const app = express();
const tornTokenAddress = "0x77777FeDdddFfC19Ff86DB637967013e6C6A116C";
const tornTokenContract = new web3.eth.Contract(TornTokenABI, tornTokenAddress);
app.get("/", async (_, res) => {
try {
const totalSupplyInWei: BigInt = await tornTokenContract.methods.totalSupply().call();
const totalSupplyInEther = BigNumber(totalSupplyInWei.toString()).div(1e18);
res.send(totalSupplyInEther.toString());
} catch (e) {
console.log(e);
res.status(500);
}
});
app.listen(process.env.PORT);