0

Keep getting this error and really not sure what's causing it.

Smart contract:

contract BasaltStore {
  // struct of how a document will be stored
  struct documentStore {
    // unique id of the doc
    uint256 id;
    // the url of the ipfs node where the document is stored
    string ipfsHash;
    // wallet address of who uploaded the document
    address uploader;
    // date the document was uploaded (created here)
    uint dateUploaded;
  }

  // mapping of all documents
  mapping (uint64 => documentStore) public ListOfDocuments; 
  // count of all documents stored
  uint256 public documentCount;

  /** Stores the newly created document details */
  function sendDocument(
    string memory _ipfsLocation, 
    uint256 _uploadDate,
    uint64 _key
  ) 
  public
  {
    documentCount ++;
    ListOfDocuments[_key] = documentStore(documentCount, _ipfsLocation, msg.sender, _uploadDate);
  }

  /** Retrieves docuement details */
  function getDocument(
    uint64 _id
  ) 
  public 
  view
  returns (string memory, address, uint256)
  {
    // return the attributes of the documentStore we need
    string memory ipfsHash = ListOfDocuments[_id].ipfsHash;
    address uploader = ListOfDocuments[_id].uploader;
    uint256 dateUploaded = ListOfDocuments[_id].dateUploaded;
    return (ipfsHash, uploader, dateUploaded);
  }
}

React code calling smart contract:

var key = this.state.StudentNumber + this.state.account[0]
key = parseInt(hash(key), 10)
this.setState({idForBlockchain: key})
console.log(key)

//get todays date
let newDate = new Date()
newDate = newDate.getTime()
var _ipfsLink = this.state.IPFSlink
var _account = this.state.account[0]

await storehash.methods.sendDocument(_ipfsLink, newDate, key).send({from: _account})

//call the smart contract method to create a new document
//storehash.methods.sendDocument(this.state.IPFSlink, newDate).send({from: this.state.account})
console.log("adding student")
await this.createStudent(e)
console.log("student added")

It seems to fail after calling the

await storehash.methods.sendDocument(_ipfsLink, newDate, key).send({from: _account})

Can anyone help me figure out what's going wrong?

  • You need to check transaction receipt. Probably your transaction didn't fail, but just consumed exactly the amount of gas you allowed it to consume. There is a bug in old versions of Web3js that may cause such behavior. – Mikhail Vladimirov Apr 27 at 17:46
0

You need to use await calls inside of an async function. Otherwise you will end up having a promise/resolve error.For example, try wrapping the await call inside an async function and call it immediately after..just to try it out. Like this:

var key = this.state.StudentNumber + this.state.account[0]
    key = parseInt(hash(key), 10)
    this.setState({idForBlockchain: key})
    console.log(key)

    //get todays date
    let newDate = new Date()


     newDate = newDate.getTime()
        var _ipfsLink = this.state.IPFSlink
        var _account = this.state.account[0]




  const test =async () => {

            await storehash.methods.sendDocument(_ipfsLink, newDate, key).s

end({from: _account})
        };

test();
  • Sorry, I should've shown that it's running inside an async function so do you think that's still the issue? – Neil Grogan Mar 27 at 13:10

Your Answer

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

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