Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Add formatting for future viewers
Source Link
Shane Fontaine
  • 18.3k
  • 20
  • 56
  • 83
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)

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 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 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)
The solution is working fine in Remix but not in truffle console
Source Link
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 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)

Source Link

Smart contract returning values as zeros

pragma solidity ^0.4.18;

contract TransManager {
  //state variables

  // contract owner
  address private creator;

  uint transCounter;

  // File Meta metaData
  struct metaData{
    uint id;
    address owner;
    string docType;
    string fileHash;
  }

  //Array to store tranasactions
  mapping (address => metaData[])  fileLogs;


  //Send a trnsactionId

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

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

  }

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

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

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

  // constructor
    function TransManager() {
        creator = msg.sender;
    }

  // kills contract and sends remaining funds back to creator
   function kill() {
       if (msg.sender == creator) {
           selfdestruct(creator);
       }
   }

}

getTransactions - is always returning array of zeros. But I am expecting to return the indexed number.