I'm trying to make a call to my smart contract and write data to my blockchain, which is successful. However, after that completes I want to make an entry in a firebase database. The code appears to hang after the smart contract call though.

React code:

addToBlockchain = async(_ipfsLink, _key) => {

       /* const rand = uniqueRandom(1, 10000000)
        var key = rand()

        let newDate = new Date()
        newDate = newDate.getTime()
        var _account = this.state.account[0]
        var _uid = this.state.uid

        await storehash.methods.sendDocument(_ipfsLink, newDate, _key, _uid).send({from: _account})
        .then( () =>{
            var _uid = this.state.uid
            var _studentName = this.state.StudentName
            var _studentNumber = this.state.StudentNumber
            var _courseCode = this.state.CourseCode
            var _courseName = this.state.CourseName
            var _idForBlockchain = _key

            const db = firebase.database()
                    studentName: _studentName,
                    courseCode: _courseCode,
                    courseName: _courseName,
                    blockchainKey: _idForBlockchain 

            alert("Student added")

        return (_key)


and here's the contract is that's of any help:

pragma solidity 0.5.0;

// Basic app of how to store and retrieve a document id for IPFS stored on Ethereum network
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;
    // uploaders id on firebase database
    string userID;

// 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,
    string memory _userID
    documentCount ++;
    ListOfDocuments[_key] = documentStore(documentCount, _ipfsLocation, msg.sender, _uploadDate, _userID);

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

I'm running the smart contract locally using Ganache and the transaction is completing but the code never seems to get to the firebase step. Does anyone know why?

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.