0

I'm trying to interact with a private blockchain from a JavaScript code, for that i've provided an RPC address to each node and extended multiple apis using -rpcapi . Now if I'm using geth attach http://127.0.0.1:8546 I'm able to use admin apis in new console, but when I use a web3 object with same address, it doesn't recognize admin api.

    var Web3 = require('web3');
    console.log(Web3);
    web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8546"));
    console.log(web3.eth.accounts);
    document.getElementById("acs").innerHTML = web3.eth.accounts[1];
    console.log(web3.admin);
    console.log(web3.net);
    console.log(web3.personal);

It gives perfect response for everything except web3.admin for which it shows undefined, am I missing anything? or is it not accessible JavaScript but only in geth attach console.

  • Usually admin is not exported with RPC (for security reasons), but you can enable it with the --rpcapi option. To use from javascript you need support from web3js, and that depends on what version are you using. – Ismael Jul 3 '18 at 20:13
  • @Ismael As I mentioned, I enabled admin using -rpcapi option and I am able to use it in a separate cmd using geth attach.Only problem is using it through web3, can you specify which version (of web3 or geth ) allows that. – sp4c3 Jul 5 '18 at 7:26
  • For web3 v0.20 I've used web3_extend or web3admin. I don't know if there's an equivalent for web3 v1.0 – Ismael Jul 6 '18 at 14:41

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.