1
votes

I was able to create and deploy a contract locally to Ganache using Truffle. I could set and get a value successfully as well. I deployed this contract to both Rinkeby and Ropsten and was able to call the get function, but the set function failed with the error:

Error: Invalid JSON RPC response: ""

Using MyEtherWallet/MetaMask, I was able to call both get and set functions successfully on Rinkeby. Is there anything that jumps out as to why it would work locally, but not on the testnets?

Set function:

ProcessHistoryStoreInstance.setStore(
    uuid,
    attribute,
    value,
    {from: account}
  ).then(function(result) {
      console.log('TX Hash: ' + result.tx);
      response.status(200).json({success: true, msg: result.tx});
  }, function(error) {
      console.log('Error setting attribute: ' + error);
      response.status(500).json({success: false, msg: error});
  });

Get function:

ProcessHistoryStoreInstance.getFromStore.call(uuid, attribute).then(function(result) {
      console.log('Result: ' + result);
      response.status(200).json({success: true, msg: result});
  }, function(error) {
      console.log('Error getting attribute: ' + error);
      response.status(500).json({success: false, msg: error});
  });

Solidity contract:

pragma solidity^0.4.11;

import "./AttributeStore.sol";

contract ProcessHistoryStore {
    AttributeStore.Data store;

    function getFromStore(bytes32 _UUID, string _attrName) public constant returns (uint) {
      return AttributeStore.getAttribute(store, _UUID, _attrName);
    }

    function setStore(bytes32 _UUID, string _attrName, uint _attrVal) public {
      AttributeStore.setAttribute(store, _UUID, _attrName, _attrVal);
    }

}
1

1 Answers

0
votes

Figured it out. I was using web3 to set my provider instead of truffle-hdwallet-provider.

web3 (wasn't working):

if (typeof web3 !== 'undefined') {
  web3 = new Web3(web3.currentProvider);
} else {
  // set the provider you want from Web3.providers
  web3 = new Web3(new Web3.providers.HttpProvider("http://127.0.0.1:7545"));
}

truffle-hdwallet-provider (now works):

new HDWalletProvider(mnemonic, "http://127.0.0.1:7545");