Skip to content

How does the fundMe.provider.getBalance work? #378

Answered by PatrickAlphaC
cipher222 asked this question in Q&A
Discussion options

You must be logged in to vote

Great question!

So our fundMe variable is a contract object. That comes with a signer or provider.

When we call fundMe.fund(....) and send a transaction, it needs both a:

  • signer: someone to sign/send the transaction
  • provider: a blockchain connection to send it to (your RPC_URL)

When we created the contract, we did so with:

fundMe = await ethers.getContract("FundMe")

And a little magic happened here:

  1. It auto assigned our accounts[0] from our hardhat.config.js to be the signer
  2. Added whatever network we were on as the provider.

So, we can just access the provider directly with fundMe.provider.getBalance. Make sense?

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by PatrickAlphaC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants