0
    pragma solidity ^0.4.21;

    contract TransManager {
        uint transCounter;

        struct MetaData{
            uint id;
            address owner;
            string docType;
            string fileHash;
        }

        mapping (address => MetaData[])  fileLogs;

        function regTransaction(string _docType, string _fileHash) public {
            transCounter++;
            MetaData memory fileLog = MetaData(transCounter, msg.sender, _docType, _fileHash );

            fileLogs[msg.sender].push(fileLog);
        }

        function getTransactions() public view returns (uint[]) {
            MetaData[] storage temp = fileLogs[msg.sender];

            uint[] memory ids = new uint[](transCounter);

            for (uint i = 0; i < transCounter; i++){
                ids[i]=temp[i].id;
            }

            return ids;
        }
    }

truffle console --network ganache
truffle(ganache)> TransManager.deployed().then(function(instance){app=instance;})
undefined
truffle(ganache)> app.regTransaction("EDI","Hash",{from: web3.eth.accounts[1]})
{ tx: '0x46785333bce5f682c586ccf995682203a78d26bfba54957bb0bd5593d6cc4542',
  receipt: 
   { transactionHash: '0x46785333bce5f682c586ccf995682203a78d26bfba54957bb0bd5593d6cc4542',
     transactionIndex: 0,
     blockHash: '0x26bf163083f35bade4aca17c2d05706846b4dd8f555efa7117cdea0b64da51ca',
     blockNumber: 5,
     gasUsed: 146345,
     cumulativeGasUsed: 146345,
     contractAddress: null,
     logs: [],
     status: 1 },
  logs: [] }
truffle(ganache)> app.getTransactions()
Error: VM Exception while processing transaction: invalid opcode
    at XMLHttpRequest._onHttpResponseEnd (/usr/local/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:509:1)
    at XMLHttpRequest._setReadyState (/usr/local/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:354:1)
    at XMLHttpRequestEventTarget.dispatchEvent (/usr/local/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:64:1)
    at XMLHttpRequest.request.onreadystatechange (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/httpprovider.js:128:1)
    at /usr/local/lib/node_modules/truffle/build/webpack:/~/truffle-provider/wrapper.js:134:1
    at /usr/local/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/requestmanager.js:86:1
    at Object.InvalidResponse (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/errors.js:38:1)
truffle(ganache)> 
1

You probably want this:

app.getTransactions({from: web3.eth.accounts[1]});

I imagine the issue is a missing msg.sender or at the very least not the one that has the stored transactions.

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.