Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot Read properties of undefined(reading 'provider') #3

Open
Twonarly1 opened this issue Sep 27, 2022 · 1 comment
Open

Cannot Read properties of undefined(reading 'provider') #3

Twonarly1 opened this issue Sep 27, 2022 · 1 comment

Comments

@Twonarly1
Copy link

I was having issues with this error while running through the tutorial and wanted to share a solution.

Problem:
TypeError: Cannot read properties of undefined (reading 'provider') at getBalance (/coffee-contracts/scripts/buy-coffee.js:5:44).

Solution
//buy-coffee.js

const { ethers } = require("hardhat")
const hre = require("hardhat")

// Returns the Ether balance of a given address.
async function getBalance(address) {
    const balanceBigInt = await ethers.provider.getBalance(address)
    return hre.ethers.utils.formatEther(balanceBigInt)
}
@jameslimjy
Copy link

thanks for the solution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants