Skip to content

Instantly share code, notes, and snippets.

@Josh4324
Last active May 10, 2022 13:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Josh4324/f3953613aa15c6bdd3d888b6805c3c26 to your computer and use it in GitHub Desktop.
Save Josh4324/f3953613aa15c6bdd3d888b6805c3c26 to your computer and use it in GitHub Desktop.
const getPrice = async () => {
const data = await axios.get(
"https://api.coingecko.com/api/v3/simple/price?ids=ethereum&vs_currencies=usd"
);
setPrice(data.data.ethereum.usd);
};
const getBalance = async () => {
try {
//setLoading(true);
const provider = new ethers.providers.JsonRpcProvider(
"https://eth-rinkeby.alchemyapi.io/v2/0mjCfRXMhCmlg6NpHLkztqcvtEbqG9__"
);
const paymentContract = new ethers.Contract(
contractAddress,
contractABI,
provider
);
const contractBalance = await paymentContract.getBalance();
setContractBalance(Number(BigNumber.from(contractBalance)) / 10 ** 18);
} catch (error) {
console.log(error);
}
};
useEffect(() => {
getBalance();
getPrice();
}, []);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment