Created
July 14, 2020 21:06
-
-
Save petejkim/e11980b9fa77ad6456d1b577052cddcd to your computer and use it in GitHub Desktop.
Introduction to Building on DeFi with Ethereum and USDC - Part 1 - getBalance.js - 2
This file contains hidden or 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 ethers = require("ethers"); | |
const wallet = require("./wallet"); | |
const provider = require("./provider"); | |
async function main() { | |
const account = wallet.connect(provider); | |
// Define contract interface | |
const usdc = new ethers.Contract( | |
"0x68ec573C119826db2eaEA1Efbfc2970cDaC869c4", | |
[ | |
"function balanceOf(address _owner) public view returns (uint256 balance)", | |
], | |
account | |
); | |
const ethBalance = await account.getBalance(); | |
console.log(`ETH Balance: ${ethers.utils.formatEther(ethBalance)}`); | |
// Call balanceOf function | |
const usdcBalance = await usdc.balanceOf(account.address); | |
console.log(`USDC Balance: ${ethers.utils.formatUnits(usdcBalance, 6)}`); | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment