Using web3js 0.20.2 and truffle-contract, I have been getting public properties of my contract by doing
Foo.deployed().then(function(instance) {
instance.rate.call().then((r) => {
console.log(r)
})
});
Came across a less verbose way of writing the same code [here], which does something like
Foo.deployed().then(function(instance) {
console.log(instance.rate())
});
In the linked webpage, the author suggested the following where k is the contract instance:
for(i = 0; i < k.size(); i++) {
someFunc( k.balances(k.addressLUT(i)) );
}
to avoid
for(i = 0; i < k.size(); i++) {
k.addressLUT(i).call().then((res) => {
k.balances(res).call().then((res) => {
someFunc(res)
})
})
}
However when I try out the second method, why is instance.name() giving me a promise, similar to using instance.name.call()? Shouldnt we get the value immediately without waiting for the Promise to be resolved?
instance.rate()
> instance.rate()
Promise {[[PromiseStatus]]: "pending", [[PromiseValue]]: undefined}
__proto__: Promise
[[PromiseStatus]]: "resolved"
[[PromiseValue]]: BigNumber
instance.rate.call()
> instance.rate.call()
Promise {[[PromiseStatus]]: "pending", [[PromiseValue]]: undefined}
__proto__: Promise
[[PromiseStatus]]: "resolved"
[[PromiseValue]]: BigNumber