[Ethereum] How to get contract’s ether balance at hardhat / waffle

ethers.jshardhatunittesting

I writing hardhat/ethers/waffle unit tests for my contract and need to know Ether balance of my contract.

Chai matcher changeEtherBalance needs Signer object to check balance, but I have address of my contract only.

I know, what ethers.js has provider object with getBalance(address) method, so I have installed nomiclabs-hardhat-ethers plugin and can call
ethers.provider.getBalance(address)

It works well for addresses from signers ethers.getSigners() but returns 0 for mycontract.address.

How I can know my contract Ethereum balance?
Please advice.

Best Answer

const { ethers, waffle} = require("hardhat");
const provider = waffle.provider;
const balance0ETH = await provider.getBalance(user1.address);
Related Topic