question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Truffle console: Assignments involving an await return undefined

See original GitHub issue

Issue

In Truffle Console, if you enter an assignment expression, and the right-hand-side involves an await, the return value incorrectly shows as undefined.

Both the assignment and the await seems to be necessary. For instance, both x = 3 and await 3 correctly show 3; however, x = await 3 shows undefined.

This also happens in more complicated assignments involving await, such as x = (await 3) + 1. Of course, note that more complicated expressions like this may not work at all, as per #1546! Indeed I assume this issue is probably related to #1546 somehow… (but maybe it’s easier to fix? IDK).

Steps to Reproduce

Open truffle console in a Truffle project.

Enter:

x = await 3

x = (await 3) + 1

Expected Behavior

The return values should be 3 and 4, respectively.

Actual Results

The return values are both undefined.

Environment

  • Operating System: Release Linux Mint 20 Ulyana 64-bit
  • Ethereum client: Ganache CLI v6.10.1 (ganache-core: 2.11.2)
  • Truffle version (truffle version): 5.1.41
  • node version (node --version): v10.15.3
  • npm version (npm --version): 6.14.5

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:15 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
mdg215199commented, Feb 20, 2022

Thank you for the video, I had to watch it a second time, as the first, I was skipping through instead of fully watching the last part of it. Absolutely solved the issue I was having.

1reaction
haltman-atcommented, Jun 10, 2021

@cds-amal, I think that statement needs some elaboration!

What Amal actually did is not to somehow pass the equivalent of the --experimental-repl-await flag to the repl library, but rather to pass the actual --experimental-repl-await flag to the instance of Node that’s running Truffle! That is to say, we could add it to the shebang line in @truffle/core!

It’s a little unclear whether this suffices for our purposes, but it just might… after all, it’s not like we create a REPL from any other package!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Truffle console keep showing "undefined". Solved by rolling ...
The expression myContract.x() returns a promise, which when resolved, yields a BigNumber instance. You should generally resolve the promise ...
Read more >
Interact with your contracts - Truffle Suite
When you execute a contract's function via a transaction, you cannot receive that function's return value because the transaction isn't processed ...
Read more >
Using async/await still returns undefined - Stack Overflow
the thread can move on before the return value is assigned to like . That may be where you're seeing undefined issues.
Read more >
Using Truffle with the Avalanche C-Chain - Figment Learn
Then, in the console, create the account: truffle(development)> let account = await web3.eth.personal.newAccount(). This returns: undefined.
Read more >
How To Build A Blockchain App with Ethereum, Web3.js ...
Truffle Blockchain Smart Contract Development Framework ... Your console might return undefined , but that's ok! You can obtain the value of ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found