Search code examples
javascriptethereumsolidity

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

  • 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