I am using truffle and Ganache. I wrote the following code in remix and its working. But when I use the same code with javascript I am getting runtime error

pragma solidity ^0.4.17;

contract Delegation {
    //Structure definition to store various roles like IoT_Member.
    //It will store permissions associated to the role.
    struct RoleTypes {
        bytes32[] permTypes;
        uint index;

    //Mapping to map role name to role information for the purpose of indexing
    mapping (bytes32 => RoleTypes) role;
    //Array to check the existance of role
    bytes32[] chkRole;

    //Function to check the existance of role
    function checkRole(bytes32 _roleName) public view returns (bool) {
        return (chkRole[role[_roleName].index] == _roleName);


var deleg;
Delegation.deployed().then(function(instance) {
  deleg = instance;
  return deleg.checkRole.call(web3.fromAscii(roleName));
}).then(function(value) {


Uncaught (in promise) Error: Invalid JSON RPC response: {"id":2,"jsonrpc":"2.0"}
    at Object.InvalidResponse (app.js:10361)
    at app.js:48396
    at XMLHttpRequest.request.onreadystatechange (app.js:51022)
  • Are you saying you're trying to run the smart contract in a JavaScript environment? – JAG Feb 26 '18 at 20:16
  • I deployed smart contract on ganache and am calling the contract public functions from javascript. Essentially I am using truffle webpack box and modifying according to my needs. The problem is with bytes32. I am not able to call function with bytes32 as argument from javascript. – Nachiket tapas Feb 27 '18 at 6:15

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.