'Getting Promise Object when Calling Solidity Functions

I have a function in my smart contract where I am trying to return some data that has been stored in the blockchain,

    function showOrg(address org) external view returns(uint international_securities_identifier, string memory organization_name, bool hasActivityStatus, string memory businessClassifier, string memory RegisteredAddress, string memory isDomiciledIn, bool sanStatus){
    require(orgs[org].admins[msg.sender] == true, "You are not authorized to view this data!");
    return(orgs[org].international_securities_identifier, orgs[org].organization_name, orgs[org].hasActivityStatus, orgs[org].businessClassifier, orgs[org].RegisteredAddress, orgs[org].isDomiciledIn, orgs[org].sanStatus);
}

I am using the following to call this function,

var result = AMLContract.methods.showOrg('0xCe37A39e3EaB674572EDd4b37f33841774750b2F').send({from: contractAddress})
console.log(result);

However, what I keep getting is a Promise object, is there any way that I can view the actual data? Or is my approach wrong?



Solution 1:[1]

You need a callback function to resolve a promise. Use your function like this

AMLContract.methods.showOrg('0xCe37A39e3EaB674572EDd4b37f33841774750b2F')
  .send({from: contractAddress}).then(function(receipt){
      console.log(receipt)
  });

receipt will hold the information about the transaction. And you can use events in your smart contract to emit the desired information from any function and then catch them with Web3.

Read more about Web3.js functionality here

Solution 2:[2]

I think this you should use await before calling the view function I solved my problem with this thing

const demo=await democontract.fn(params...)
   cosole.log(demo)

because if you call contracts function without its is going to return a pending promise :)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Taimoor
Solution 2 baibars313