1

I have tested it in remix and the function does work, I also removed inputs just for testing purposes but it seems that it doesn't work anyway.

Here is the function:

struct Message{
    string Message;
    int Vote;
    uint timeSubmit;
    bool isImportant;
    uint senderId;
}
Message[] messageArr; 
function getMessageString() public view returns(string memory){
        return messageArr[2].Message;
    }

I am calling it in web3.js like this:

  function getString() {
        messageInstance.getMessageString(function(error, result){
          if (error) {
              console.log(error)
          }
          else {
        console.log("yes")

      }})
    }

I am using truffle but it keeps giving me this error.

1 Answer 1

1

Function getMessageString takes 0 parameters, yet you are calling it with 1 parameter.

Therefore, change this:

messageInstance.getMessageString(function(error, result)

To something like this:

messageInstance.getMessageString().then(function(result)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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