In the following code, the console.log returns an empty string, but the truffle test works fine!

const certificate = contract(Certificate);
var certificateInstance = 
return certificateInstance
    .ownerName() // state variable in the contract
    .then(function(_ownerName) {
      // getParam2 is the function with onlyOwner modifier
      return certificateInstance.getParam2({ from: owner });
    .then(function(_value) {

Below are my truffle test code:

return Certificate.at(certAddress);
    certInstance = instance;
    return certInstance.getParam2({from: owner});
    assert.equal(_value, "param2value", "modifier function returns correct value"

Please check out this documentation

You should call as in that example. E.g:

return certificateInstance
   .then( ...
  • Truffle has a different syntaxis than web3.js v1 more like web3.js v0.20.
    – Ismael
    Oct 24 '18 at 16:38
  • @Ismael that's correct, but how it's related to my answer. In question it's being asked why this is not working in browser with web3 & I replied why. Oct 24 '18 at 20:12

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.