Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

TypeError: miner.startMining is not a function #2877

Closed
king841997 opened this issue Jun 5, 2019 · 4 comments
Closed

TypeError: miner.startMining is not a function #2877

king841997 opened this issue Jun 5, 2019 · 4 comments
Labels
2.x 2.0 related issues Bug Addressing a bug

Comments

@king841997
Copy link

import {Miner} from "web3-eth-miner";

const options =  {
        defaultAccount: "0x78dB3e2129D58685444989dD9682DDDC70dd3C82",
        defaultBlock: 'latest',
        defaultGas: 3000000000,
        defaultGasPrice: 3000000,
        transactionBlockTimeout: 50,
        transactionConfirmationBlocks: 24,
        transactionPollingTimeout: 480,
      }
      const miner = new Miner(web3.givenProvider, null,options);
        await miner.startMining(2).then(console.log)

It still throws an error TypeError: miner.startMining is not a function

@nivida
Copy link
Contributor

nivida commented Jun 5, 2019

Thanks for opening this issue! Which version of Web3 are you using? and could you provide the whole script?

@sulenn
Copy link

sulenn commented Jun 6, 2019

the same question:
the Web3's version:[email protected]
the web3-eth-miner's version:@1.0.0-beta.55
geth version:Geth/v1.8.27-stable/linux-amd64/go1.12

script:

const Web3 = require("web3");
const net = require('net');
const {Miner} = require("web3-eth-miner")

const web3 = new Web3(new Web3.providers.IpcProvider('/home/qiubing/桌面/chain_creator_nodejs/sulenn5/data/geth.ipc', net));
// 连接 miner 服务
const miner = new Miner(new Web3.providers.IpcProvider('/home/qiubing/桌面/chain_creator_nodejs/sulenn5/data/geth.ipc', net))

web3.eth.getAccounts()
    .then(console.log("success"))
    .catch(err=>{
        console.log("err!")
        process.exit()
    })

miner.startMining("1").then(console.log)

result

2

thank you!

@king841997
Copy link
Author

king841997 commented Jun 6, 2019

Thanks for opening this issue! Which version of Web3 are you using? and could you provide the whole script?

I was using "web3": "^1.0.0-beta.37", and had installed web3-eth-miner from npm package.

I tried upgrading to the version "web3": "^1.0.0-beta.55", still same issue..
here is the whole script

import LandManagmentContract from "./contracts/LandManagment.json";
import getWeb3 from "./utils/getWeb3";
import {Miner} from "web3-eth-miner";

import Web3 from "web3";

import "./App.css";

class App extends Component {
  state = { web3: null,
            accounts: null,
            contract: null };

  componentDidMount = async () => {
    try {
      // Get network provider and web3 instance.
      const web3 = await getWeb3();

      // Use web3 to get the user's accounts.
      const accounts = await web3.eth.getAccounts();

      // Get the contract instance.
      const networkId = await web3.eth.net.getId();
      const deployedNetwork = LandManagmentContract.networks[networkId];
      const instance = new web3.eth.Contract(
        LandManagmentContract.abi,
        deployedNetwork && deployedNetwork.address,
      );

      console.log(web3.givenProvider)
      console.log(web3.eth.givenProvider)
      console.log(accounts)

      const provider = new Web3.providers.HttpProvider(
        "http://127.0.0.1:8545"
      );
      const options =  {
        defaultAccount: "0x78dB3e2129D58685444989dD9682DDDC70dd3C82",
        defaultBlock: 'latest',
        defaultGas: 3000000000,
        defaultGasPrice: 3000000,
        transactionBlockTimeout: 50,
        transactionConfirmationBlocks: 24,
        transactionPollingTimeout: 480,
      }
      const miner = new Miner(provider, null,options);

      
      console.log(accounts)
      console.log(miner)
      
      console.log(await miner.setEtherbase("0x78dB3e2129D58685444989dD9682DDDC70dd3C82"))
      //***************************** */
      //miner.setEtherBase returns TRUE
      //********************************* */

        await miner.startMining(1)
      
      this.setState({ web3, accounts, contract: instance });
    } catch (error) {
      // Catch any errors for any of the above operations.
      alert(
        `Failed to load web3, accounts, or contract. Check console for details.`,
      );
      console.error(error);
    }
  };

@nivida nivida added Needs Clarification Requires additional input and removed more information needed labels Jun 11, 2019
@baumstern
Copy link

I also got same error.

  • version info
    web3-eth-miner: 1.0.0-beta.55

@nivida nivida added the 2.x 2.0 related issues label Jun 20, 2019
@nivida nivida added Bug Addressing a bug and removed Needs Clarification Requires additional input labels Jul 15, 2019
@nivida nivida closed this as completed Jul 15, 2019
@nivida nivida mentioned this issue Aug 5, 2019
11 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
2.x 2.0 related issues Bug Addressing a bug
Projects
None yet
Development

No branches or pull requests

4 participants