2

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

5

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:" +  address);
            let balance = await web3.eth.getBalance(address)
        });
    });
});
  • thanks. it worked. Can I have a little question: I write a payable function (sending transfer money from sender to contract's owner). My question is: I have list of accounts. which accounts is being used. thanks :D – hqt Apr 18 '18 at 5:03
  • 1
    The first one. Truffle does some setup, and you're neatly passing accounts into your test. Transactions are signed {from: accounts[0]} by default. As a matter of style, I like to set up some vars for roles like owner=accounts[0], funder=, sponsor=, etc. up front and then specify who is talking every step of the way, e.g. {from: funder1} – Rob Hitchens - B9lab Apr 18 '18 at 5:14
  • thanks so much. I have used this style, but it seems not work. can you take a look for me in this post. thanks. ethereum.stackexchange.com/questions/46066/… – hqt Apr 18 '18 at 16:14

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.