[Ethereum] Truffle: how to get balance of any address or contract’s address

soliditytestingtruffleweb3js

For example I have a testing block like this:

contract('CreeptomaPresale', function(accounts) {
    describe("adopted over allow quantity", function () {
        it("test get balance", async function () {
            let instance = await CreeptomaPresale.deployed();
            console.log("deployed address:" +  address)
        });
    });
});

I can get deployed address. But now, I don't know how to get balance of this address or any other addresses.

Thanks

Best Answer

Try

contract('CreeptomaPresale', function(accounts) {
    describe("adopted over allow quantity", function () {
        it("test get balance", async function () {
            let instance = await CreeptomaPresale.deployed();
            console.log("deployed address:" +  instance.address);
            let balance = await web3.eth.getBalance(instance.address)
        });
    });
});
Related Topic