0

I have a function which get a parameter as String and compare it like below.

function freezeAccount(string _value) onlyOwner public {
    if (keccak256(_value) == keccak256("true")){ isFrozen = "true"; }
    if (keccak256(_value) == keccak256("false")){ isFrozen = "false"; }
}

Above is my smart contract code. I wanna use this my method using web3 so I'm trying to make transition by send() function like below.

export const setFreezeAccount = value => {
console.log("setFreezeAccount :: value: ", value);
  const str = value.toString();

  myContract.methods
  .freezeAccount(str)
  .send({ from: TOKENOWNER })
  .then(receipt => {
    console.log("setFreezeAccount :: receipt: ", receipt);
  })
  .catch(err => {
    console.log("setFreezeAccount :: err: ", err);
  });
};

The freezeAccount() function is working well on Remix IDE but the Error: Invalid JSON RPC response: "" error returned When I execute the setFreezeAccount() function.

0

I am an idiot. I want to delete this question but I will remain it for other people who make same mistake like me. The reason why error occurred was the freezeAccount() function on Solidity is only can executed by owner. I added the access modifier named onlyOwner so that I have to make transaction data and signed it then send the transaction using Web3.

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.