I'm trying to call a method that pushes data to my Blockchain and then returns back the ID of the new struct I created. This is how I'm calling the method in my React code:

const documentId = await storehash.methods.sendDocument(this.state.IPFSlink, newDate).send({from: this.state.account}).call()

And here is my smart contract method:

function sendDocument(
    string memory _ipfsLocation, 
    uint256 _uploadDate 
returns (uint256)
    documentCount ++;
    ListOfDocuments[documentCount] = documentStore(documentCount, _ipfsLocation, msg.sender, _uploadDate);
    return documentCount ;

So it should created the new struct and return back the ID. However, it causes the following error:

Unhandled Rejection (Error): invalid tuple value (coderType="tuple", value="QmStXLfxUJuc4xTtSGQxmF1PXrjVmsosqL6Wyi5EuQiYNH", version=4.0.26)

Can anyone help me understand what I'm doing wrong?

p.s sorry if I've formatted this badly, it's my first time using a stackexchange.

  • Don't think you can do send(...).call(). You should await for send(...) to complete, and then call the view function which returns the data that you need. – goodvibration Mar 14 at 17:14
  • @goodvibration Sorry, I'm a bit new to this, can you elaborate what you mean by view function? – Neil Grogan Mar 14 at 17:35
  • A function which doesn't change the state of the blockchain, i.e., doesn't change any of the state-variables of the contract it belongs to, and doesn't call any other function (in this contract or in another) which does. When a non-view function is called from the off-chain, it returns (to the off-chain caller) the transaction hash, not the value in the return statement. – goodvibration Mar 14 at 21:10
  • So would I be able to have 1 method which creates the new struct and returns the id to me or is this impossible in 1 method? Thank you for your help by the way. – Neil Grogan Mar 14 at 22:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.