4

I am trying to get the ETH balance of a contract:

const balance = await contract.getBalance();

but it fails:

TypeError: contract.getBalance is not a function

What I do wrong and how to fix the error?

7

getBalance is a function of the Ether.js blockchain provider object, it is used this way :

const balance = await provider.getBalance("address");

Note that you can use contract.address to obtain the address of the contract instance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.