2

I am using web3j and Geth and created a private network. However, I want to do the mining manually whenever required, since don't want to jam the server when I am in the development phase. For that, I found JsonRpc2_0Geth update in web3j and used it. However, mining does not start. Please help me where I am going wrong.

pom.xml

<dependency>
        <groupId>org.web3j</groupId>
        <artifactId>core</artifactId>
        <version>4.0.1</version>
    </dependency>
    <dependency>
        <groupId>org.web3j</groupId>
        <artifactId>geth</artifactId>
        <version>4.0.1</version>
    </dependency>

Then, i called the Geth aPI through my java file as follows:

static public Web3j web3j = Web3j.build(new HttpService("<geth ip>:<port>"));
static public JsonRpc2_0Geth geth = new JsonRpc2_0Geth(new HttpService("<geth ip>:<port>"));
geth.minerStart(1000);
9
  • geth.minerStart(1000); asks miner to use 1000 threads, you can try following troubleshooting. 1. Try 1 thread geth.minetStart(1) and try start mining from console. Do any of these work ? Dec 5, 2018 at 3:38
  • mining from geth console works. Not from the java file though. How can i troubleshoot for java ? Dec 5, 2018 at 4:16
  • Does it work with geth.minerStart(1) Dec 5, 2018 at 4:19
  • And what is the full command line that is used to start geth ? Dec 5, 2018 at 4:21
  • No, geth.minerStart(1) did not work for me. The way i used it is mentioned in my original draft. The way i started geth node is : geth --port 3000 --networkid 1996 --nodiscover --datadir=./datadir --maxpeers=0 --rpc --rpcport 8585 --rpcaddr 127.0.0.1 --rpccorsdomain "*" --rpcapi "eth,net,web3,personal,miner, admin, txpool" console Dec 5, 2018 at 5:27

1 Answer 1

1

Posting to RPC URL is a way to start mining from any language

{"jsonrpc":"2.0","method":"miner_start","params":[1],"id":74}

I.e. post this data to RPC URL.

Command line example is :

curl -X POST --data '{"jsonrpc":"2.0","method":"miner_start","params":[4],"id":74}' localhost:8545

https://github.com/ethereum/go-ethereum/wiki/Management-APIs

This page has example of sending a POST request from Java.

https://www.mkyong.com/java/how-to-send-http-request-getpost-in-java/

1
  • I am trying this solution. Thanks for the response . Will update you soon. Dec 6, 2018 at 4:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.