Metamask: insufficient funds for gas * price + value in ropsten network with web3j (java)

I can guide you through the creation of an HTTP server with the Web3J Java directory to interact with the Ropsten test network. This is how you can do:

`Java

Import io.web3j.client.client;

Import io.web3j.client.rpcexception;

Import io.web3j.client.rpcrespronsse;

Import Io.web3j.protocol.core.Methods.repse.ethtransaction;

Import io.web3j.protocol.core.Methods.repse.web3requestparams;

Import io.web3j.protocol.core.types.transection;

public class Ropstenhttpserver {

Private static final string host = "ropsten.infura.io";

Private static final int port = 8545; // default port for infura

public static void main (string [] args) {

Client client = new client ("https: //" + host + ":" + port);

// Set the request parameters

Web3rquestparams Params = New Web3rquestparams ()

.Sethost (hosts)

.Setport (port);

if (args.length> 0 &&! args [0] .startswith ("-")) {

System.out.println ("Usage: Java Ropstenhttpserver [Args]");

System.exit (1); // exit with error code

}

while (true) {

Try {

// Get a list of transactions sent with another account on Ropsten

List txlist = client.gettransactionsbyaddress ("your_account_address", params);

// processing the transaction response

for (transaction tx: txlist) {

System.out.println (TX);

}

} Catch (rpcexception e) {

System.out.println (e.getmessage ());

}

Try {

Thread.sleep (100); // sleep for 1 second before checking again

} Catch (interrupted expection ex) {

System.out.println ("interrupted during sleep:" + ex);

}

}

}

}

Please note the following:

  • You must replace “” your_account_address “with the title of actual Ethereum account.

  • Replace with the URL of https: // ropsten.infura.io/ and 8545 URL with the URL of the Infura Workspace and the Ropsten Test Network (which 8545).

  • Use this code as a starting point. Depending on how you want to handle errors, it is recommended to execute error handling mechanisms.

To compile the Java program, save it to “Ropstenhttpserver.java” and run with the following command:

`Bash

javac ropstenhttpserver.java -cp “:” Org.web3j.protocol.core.optimizationlivel.high -d output.jar

java -jar output.jar

`

Replace the “” “Output.jar” `the way to access the "Ropstenhttpserver.jar file compiled.


Reacties

Geef een reactie

Je e-mailadres wordt niet gepubliceerd. Vereiste velden zijn gemarkeerd met *