Object Promise message is displayed

javascriptsolidityweb3js

    const readData = async () => {
      const data = window.contract.methods.getName().call();
      document.getElementById("dataArea").innerHTML = `Message is here: ${data}`;

why am i getting the message of Object Promise in ${data}

Best Answer

.call() returns a Promise, you need to wait for it to resolve:

      const data = await window.contract.methods.getName().call();
      document.getElementById("dataArea").innerHTML = `Message is here: ${data}`;
Related Topic