2

I have a simple contract

pragma solidity ^0.4.4;

contract Main {

function getValue() constant returns (bool){
  return true;
 }
}

I just need to create a web interface that can fetch this value for me.

I unboxed webpack in empty repo by >truffle unbox webpack, deleted the previous contracts, changed the index.html and app.js files, changed the 2_deploy_contracts.js accordingly but the error i get on console of the browser is:

Uncaught (in promise) Error: VM Exception while processing transaction: revert

Here is my index.html and app.js file.

 <html>

   <head>
     <title>Truffle 3 Frontend Demo</title>
   </head>
   <body>
   </body>


   <script src="./app.js"></script>
   <script src="../node_modules/web3/dist/web3.js" type="text/javascript">       </script>
   <script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" type="text/javascript"</script>
</html>

and my app.js file is

import { default as Web3 } from 'web3'
import { default as contract } from 'truffle-contract'
import Main_artifact from '../../build/contracts/Main.json'

const TESTRPC_HOST = 'localhost'
const TESTRPC_PORT = '8545'

function component () {
  var element = document.createElement('div')
  console.error("hi");
  let provider = new Web3.providers.HttpProvider(`http://${TESTRPC_HOST}:${TESTRPC_PORT}`)
  let main = contract(Main_artifact)
  main.setProvider(provider)

  main.deployed().then(function(instance) {
      console.log(instance);

    var s = instance.getValue(); //instance.getValue.call() doesnt work either
    return s;
}).then(function(result){
    element.innerHTML = `value: ${result}`
    console.log(result)
});


  return element
}

document.body.appendChild(component());
1

I believe the problem is the constant keyword on your function.

Per this issue on the solidity repository:

the keyword constant is invalid on functions

Try removing that and redeploying the contract.

  • 1
    Sorry to revert back so late, I did remove it and still got an error, I upgraded my truffle to 4.0.4 from 4.0.1 and surprisingly it worked. I don't know if truffle did it or removing the keyword but it worked. Thanks for helping. – Atharva Gomekar Jan 2 '18 at 16:19

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.