4

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?

  • which truffle version are you using, which testrpc version are you using, what's your operating system, can you provide sample code? – Miguel Mota Jan 7 '18 at 7:38
  • "bumped to the homepage by Community"? Whose idea was that??? – goodvibration May 14 '18 at 7:22
1

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.

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.