I have a simple async/await function get the total supply of my contract. It returns a promise, however.

async function supply() {
    const supply = await contract.methods.totalSupply().call()
    return supply

  const s = supply()

The actual promise contains the correct value, and gets logged;

[[PromiseState]]: "fulfilled"

[[PromiseResult]]: "3"

How do I get the value?

1 Answer 1


You need await your own async functions

  const s = await supply()
  • I have to wrap that in its own async then. This would mean I could never call it outside of a function? Jul 18, 2021 at 10:59
  • Correct. Everything must follow async path. If you want to easier to understand and simpler execution threaded model, please try Python and Web3.py: web3py.readthedocs.io Jul 18, 2021 at 11:00
  • 1
    I'm using React Hooks, where you cannot call async functions within the main component function. Is it just impossible to fetch the value then? Jul 18, 2021 at 11:20
  • That is a different question. Please ask the question on stackoverflow.com or React forums how to use React, as it is not relevant for Web3.js discussion. Jul 18, 2021 at 13:06

Not the answer you're looking for? Browse other questions tagged or ask your own question.