My main goal is to call web3.shh
functions using RPC API
, Web3.py
or Web3.js
. I can call web3.shh
functions when I use geth attach
; which is my last option to do.
I am following this answer.
- geth version:
1.8.0-unstable
I am running
geth
with--shh
flag and--rpcapi "admin,eth,net,web3,debug,shh"
console.log(web3.version);
returns: api:'0.20.5'
.
When I run following script:
Web3 = require("web3");
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
if(!web3.isConnected()){ //[email protected]
//if(!web3.eth.net.isListening().then(console.log)){ //[email protected]
console.log("notconnected");
process.exit();
}
var kId = web3.shh.newSymKey(); //Error occurs.
var kId = web3.shh.newSymKey();
gives following error with web3@'0.20.5'
:
Error: The method shh_newSymKey does not exist/is not available
at Object.InvalidResponse (/home/alper/eBlocBroker/node_modules/web3/lib/web3/errors.js:38:16)
at RequestManager.send (/home/alper/eBlocBroker/node_modules/web3/lib/web3/requestmanager.js:61:22)
at Shh.send [as newSymKey] (/home/alper/eBlocBroker/node_modules/web3/lib/web3/method.js:145:58)
at Object.<anonymous> (/home/alper/eBlocBroker/dd.js:9:20)
at Module._compile (module.js:649:30)
at Object.Module._extensions..js (module.js:660:10)
at Module.load (module.js:561:32)
at tryModuleLoad (module.js:501:12)
at Function.Module._load (module.js:493:3)
at Function.Module.runMain (module.js:690:10)
Please note that I have tried it with [email protected]
that also gives this error that seems like the same error:
Promise { <pending> }
true
(node:16162) UnhandledPromiseRejectionWarning: Error: Returned error: The method shh_newSymKey does not exist/is not available
at Object.ErrorResponse (/home/alper/eBlocBroker/node_modules/web3-shh/node_modules/web3-core-helpers/src/errors.js:29:16)
at /home/alper/eBlocBroker/node_modules/web3-shh/node_modules/web3-core-requestmanager/src/index.js:140:36
at XMLHttpRequest.request.onreadystatechange (/home/alper/eBlocBroker/node_modules/web3/node_modules/web3-providers-http/src/index.js:77:13)
at XMLHttpRequestEventTarget.dispatchEvent (/home/alper/eBlocBroker/node_modules/xhr2/lib/xhr2.js:64:18)
at XMLHttpRequest._setReadyState (/home/alper/eBlocBroker/node_modules/xhr2/lib/xhr2.js:354:12)
at XMLHttpRequest._onHttpResponseEnd (/home/alper/eBlocBroker/node_modules/xhr2/lib/xhr2.js:509:12)
at IncomingMessage.<anonymous> (/home/alper/eBlocBroker/node_modules/xhr2/lib/xhr2.js:469:24)
at IncomingMessage.emit (events.js:185:15)
at endReadableNT (_stream_readable.js:1101:12)
at process._tickCallback (internal/process/next_tick.js:114:19)
(node:16162) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:16162) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
[Q] How could I fix this error? What do I do wrong?
Please note that available shh
functions could be seen here; output of console.log(web3.shh)
.
console.log(web3.version)
and it returns:api: '0.20.5'
@KakiMasterOfTimegeth attach
) ? if not try it and see ifshh
is correctly activated.