Last active
May 10, 2022 13:52
-
-
Save Josh4324/f3953613aa15c6bdd3d888b6805c3c26 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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