Skip to content

Instantly share code, notes, and snippets.

@petejkim
Created July 14, 2020 21:06
Show Gist options
  • Save petejkim/e11980b9fa77ad6456d1b577052cddcd to your computer and use it in GitHub Desktop.
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
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