Console.log - Solidity contract

How to log text and value, in Solidity contract,
during development
ex.

let value = instance.balance;
console.log("value: {}", value);

does not work.

Hey @SpiritOfThe9

it("Should return the contract value:", async function(){
     let balance = await web3.eth.getBalance(People.address);
     console.log('the contract balance is: ' + balance);
  })

Schermata 2020-09-02 alle 12.23.20

Documentation

2 Likes

Thx. I understand.

However, instance.balance is declared as:
uint public balance;

but during runtime it’s a function,

  it("should earn when person added", async function(){
    let instance = await People.deployed();
    let before = instance.balance;
    console.log('before: ' + before);
  })

displays:

before: function() {
      var defaultBlock = "latest";
      ...
     return promiEvent.eventEmitter;
}

I guess it’s a JS thing !?
I thought I could access balance with dot-notation, since I have the instance.

Can you please explain what I’m missing here !?

If you have a public variable in your contract, you can do the following to access it from your test.js file.

  it("Should return the contract value:", async function(){
    instance.balance.call().then(function (res) {
      console.log(res.toNumber())
    })
  })
1 Like