0

I have connect to my rpc geth via web3 successfully, but I can't connect web3-eth-miner to my server. Here is my code

I started my rpc server as

geth --datadir ./tolotolo  --rpc --rpcapi="db,eth,net,web3,personal,web3,miner" --rpcport 5200 --rpcaddr 192.168.1.99 --rpccorsdomain "http://192.168.1.53:5050" --allow-insecure-unlock


var Web3 = require('web3');
var web3 = new Web3();
web3.setProvider(new web3.providers.HttpProvider(config.ethUrl));
const { Miner } = require("web3-eth-miner");
const options = {
    defaultAccount: config.adminAccount,
    defaultBlock: 'latest',
    defaultGas: 1,
    defaultGasPrice: 0,
    transactionBlockTimeout: 50,
    transactionConfirmationBlocks: 24,
    transactionPollingTimeout: 480,
}
web3.eth.net.isListening()
    .then(() => {
        console.log('web3 is connected'); // Here web3 is connected
        const miner = new Miner(new web3.providers.HttpProvider(config.ethUrl), null, options);
        console.log(miner);
        // miner.startMining(1).then(console.log);
    })
    .catch(e => console.log(e));

Miner console shows

givenProvider: null,
  _currentProvider: CustomProvider {
    host: 'CustomProvider',
    connection: HttpProvider {
      withCredentials: false,
      timeout: 0,
      headers: undefined,
      agent: undefined,
      connected: false,
      host: 'http://192.168.1.99:5200',
      httpAgent: [Agent]
    }
  }

Any idea about how to connect web3-eth-miner to my rpc server?

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.