[Ethereum] Truffle console.log is not working

consoletruffle

I've installed Truffle by npm, and running testrpc, but console.log is not working in Truffle console. A simple console.log('test'); do nothing. Any idea?

Best Answer

I don't have a complete answer, but I believe it has to do with the console's automatic resolution of javascript promises. For example,

Contract.deployed().then(instance => instance.contract)

the truffle console will actually wait for the final .then promise to resolve and will then print instance.contract. That said, I would imagine that

new Promise(() => console.log('test'))

would work, or even

new Promise(() => 'test')

but they don't for me. I don't know enough about promises or the truffle console to understand why that doesn't work. Hopefully this gets fixed in the future. For now, you can do

Contract.deployed().then(() => console.log('test'))

or

Contract.deployed().then(() => 'test')

as workarounds.

Related Topic