Calls work but transactions throw the error -
Error: Invalid JSON RPC response: ""
I am using web3 v0.19.0 & Truffle v3.4.9. Deploying contract using truffle,
truffle migrate --network ropsten
which successfully provides api and contract address.
My web3 provider and ropsten network (infura node) are defined in truffle.js on top of react-auth-box project.
I open truffle console --network ropsten
, and define web3 -
var Web3 = require('web3')
let web3 = new Web3()
web3.setProvider(new web3.providers.HttpProvider('https://ropsten.infura.io/my_access_token_here'))
There is no default account
web3.eth.defaultAccount
(returns null)
web3.eth.accounts
(returns [])
Set default account,
web3.eth.defaultAccount = '0xpersonalaccount'
Define contract instance,
let contract = web3.eth.contract(abi).at(address)
All good so far and Calls work -
contract.checkIdExists.call(1, {'from': account, 'to': address})
(Returns '0x0000000000')
contract.fetchDataById.call(1, {'from': account, 'to': address})
(Returns '0x')
1. Transactions fail -
contract.addRecord.sendTransaction(1, 'fjdnjsnkjnsd', '03:00:21 12-12-12', 'true', '', {'from': account, 'to': address})
Error: Invalid JSON RPC response: "" at Object.InvalidResponse (/var/www/html/react-auth-box/node_modules/web3/lib/web3/errors.js:38:16) at HttpProvider.send (/var/www/html/react-auth-box/node_modules/web3/lib/web3/httpprovider.js:91:22) at RequestManager.send (/var/www/html/react-auth-box/node_modules/web3/lib/web3/requestmanager.js:58:32) at Eth.send [as sendTransaction] (/var/www/html/react-auth-box/node_modules/web3/lib/web3/method.js:145:58) at SolidityFunction.sendTransaction (/var/www/html/react-auth-box/node_modules/web3/lib/web3/function.js:167:26) at evalmachine.:1:20 at ContextifyScript.Script.runInContext (vm.js:53:29) at Object.runInContext (vm.js:108:6) at TruffleInterpreter.interpret (/home/shivam/.npm-global/lib/node_modules/truffle/build/cli.bundled.js:213786:17) at bound (domain.js:301:14)
2. Makes me think I probably have to unlock account first (do I?)
web3.personal.unlockAccount(account, password)
Error: Invalid JSON RPC response: "" at Object.InvalidResponse (/var/www/html/react-auth-box/node_modules/web3/lib/web3/errors.js:38:16) at HttpProvider.send (/var/www/html/react-auth-box/node_modules/web3/lib/web3/httpprovider.js:91:22) at RequestManager.send (/var/www/html/react-auth-box/node_modules/web3/lib/web3/requestmanager.js:58:32) at Personal.send [as unlockAccount] (/var/www/html/react-auth-box/node_modules/web3/lib/web3/method.js:145:58) at evalmachine.:1:15 at ContextifyScript.Script.runInContext (vm.js:53:29) at Object.runInContext (vm.js:108:6) at TruffleInterpreter.interpret (/home/shivam/.npm-global/lib/node_modules/truffle/build/cli.bundled.js:213786:17) at bound (domain.js:301:14) at REPLServer.runBound [as eval] (domain.js:314:12)
Running pretty clueless by now. Any support will be appreciated. Thanks!