Skip to main content
14 votes
Accepted

Generate private key and address using web3j

Below is my approach, verified by importing the result privatekey into MetaMask and get the same address as expected. private static JSONObject process(String seed){ JSONObject processJson ...
pyang's user avatar
  • 381
12 votes
Accepted

How to create accounts and also retrieving the ether balance with web3j in a java file?

The "ethGetBalance" method will return the balance of any given account. Pls see example below: // connect to node Web3j web3 = Web3j.build(new HttpService()); // defaults to http://localhost:8545/ ...
Adam Dreessen's user avatar
11 votes

why did it returned null after call miner.start()

Recently, there are so many people confused about miner.start(1) returning null, but it's actually not a problem, just a reasonable return value misunderstanding. If you aren't sure that your node is ...
BinGoBinBin's user avatar
  • 2,161
11 votes
Accepted

How to view custom token balance in ether wallet using web3

Here is my suggestions: ERC20 token balance Just to clarify, all ERC20 tokens have the same set of methods (ERC20 protocol). Now, there are two ways to accomplish your task: use ERC20 balanceOf(...
Vanja Dev's user avatar
  • 871
10 votes

how to get latest block number using web3j java APIs

This is the easiest way Web3j web3j = Web3j.build(new HttpService("https://rinkeby.infura.io/v3/.......")); Block block = web3j.ethGetBlockByNumber(DefaultBlockParameterName.LATEST, false).send()....
Majd TL's user avatar
  • 3,257
10 votes
Accepted

How to create a RawTransaction for contract interaction Web3j

Let's take for example the following simple storage contract: pragma solidity ^0.5.6; contract SimpleStorage { uint storedData; function set(uint x) public { storedData = x; } ...
Greg Jeanmart's user avatar
8 votes

Web3j listening to events

I know this question is old, but providing an answer here as I came across this issue and couldn't find a solution elsewhere... This appears to be a bug in Web3j that occurs when you pass in the ...
Adam Kipnis's user avatar
8 votes
Accepted

How to Query the state of a smart contract using web3j in Android?

Love that your using Web3J, I think with a little practice you will find that it's a great API for dealing with Ethereum :-) So regarding your question there are two things: I think your problem is ...
Max Binnewies's user avatar
8 votes
Accepted

Convert String to Bytes32 in web3j?

SOLVED!!! LONG/Detailed METHOD!!! (Shorter Version at bottom) The main problem was Bytes32(byte[]) only supports 32 length byte[]. Also keep in mind Numeric.hexStringToByteArray(strValueInHex) ...
wannamit's user avatar
  • 151
7 votes

send() or sendAsync() while using Web3j to call functions

You can send and confirm transaction without waiting using CompletableFuture and callback function. rc-> Instance that calls contract function through remote call. CompletableFuture<...
Apoorva Petkar's user avatar
7 votes
Accepted

How to change the nonce between transactions in web3j?

Under the hood, the Web3J SmartContract Java Wrapper calculates the nonce by getting the number of transactions getTransactionCount for the account (credential). EthGetTransactionCount ...
Greg Jeanmart's user avatar
7 votes
Accepted

How to point web3j to other networks such as BSC?

If you are using the smart contact wrapper then you usually need to give one of the available transaction managers as a parameter and then give the chain Id when you initialize it Web3j web3 = Web3j....
Majd TL's user avatar
  • 3,257
6 votes

why did it returned null after call miner.start()

try setting miner.setEtherbase(eth.coinbase) or step by step: start Mist browser (let the node synchronize completely) open console and type: geth attach miner.setEtherbase(eth.accounts[0]) miner....
Andi Erni's user avatar
  • 194
6 votes
Accepted

Convert ethereum balance getting in biginteger to ether

@Luiz Soares Thank you for giving me the clue of the value being in WEI but solution provided didn't worked me.After some digging the documentation again got the solution Convert.fromWei(...
Aman Vyas's user avatar
  • 133
6 votes
Accepted

How could I send transactions continuously by Web3j generated wrapper

I found the solution, please refer, #296 Use FastRawTransactionManager to speed up your transactions. Use RawTransactionManager to shorten the polling interval. If you need both, use the following ...
Kimi Wu's user avatar
  • 243
6 votes
Accepted

How to get public key from private key in Web3j

Yes, you can do it using following code import org.web3j.crypto.Credentials; import org.web3j.crypto.ECKeyPair; public static String getPublicKeyInHex(String privateKeyInHex) { BigInteger ...
pyang's user avatar
  • 381
6 votes

How to catch solidity contract revert message using web3j (Java)

In solidity 0.4.22 the require and revert reason were added. As can be seen here, they are abi-encoded as if it were a call to a function "Error(string)". You'll need to make an eth_call to your ...
Maarten Dhondt's user avatar
5 votes
Accepted

Solidity ecrecover and web3j Sign.signMessage() are not compatible, is it?

The problem was actually double hashing. Looking at the Web3j's signMessage() method Sign.SignatureData sig =Sign.signMessage(messageBytes, ecKeyPair); and signedMessageToKey() method String pubKey ...
earthouser's user avatar
5 votes
Accepted

web3.eth.getBalance returns me the strange values ?

It is the BigNumber representation of the wallet balance that is output by your script. Indeed, BigNumbers need to be transformed through toString(int) or toNumber() in order to become compatible ...
chab42's user avatar
  • 66
5 votes

How to get public key from private key in Web3j

I posted my own answer here in case someone else has the question. Web3j provides a ECKeyPair as util to process key and address conversion. Please see codes below: String privateKey = "{your ...
Frank Kong's user avatar
5 votes

How to use mnemonic to recovery my ethereum wallet

For Bip44 wallets Web3j will use the derivation path m/44/60'/0'/0. The more commonly used path is m/44/60'/0'/0/0 (with an extra /0). The following code will derive the correct address given a valid ...
Ismael's user avatar
  • 30.3k
5 votes
Accepted

Web3j how to get event args when parsing logs?

For the following event: event MyEvent(address indexed _arg1, bytes32 indexed _arg2, uint8 _arg3); You can extract the event arguments from the log like this // Event definition public static ...
Greg Jeanmart's user avatar
5 votes
Accepted

How can I get the TxReceipt of a transaction with web3j?

There's the Transactions page in the Web3j docs that mentions transaction receipts a few times, and I browsed through some of the autocompletes in IntelliJ. It looks like you can do the following, ...
Rosco Kalis's user avatar
  • 2,147
5 votes
Accepted

Contract.methods.transfer is a not a function error using web3

If you are using web3 v0.x then you can send transaction by following: // creation of contract object var MyContract = web3.eth.contract(abi); // initiate contract for an address var ...
sjMalik's user avatar
  • 224
5 votes
Accepted

How to apply EthFilter to specific address?

OK, let's say you have a smart contract deployed on the address CONTRACT_ADDRESS which can trigger different type of events Event definitions: event GameStarted(bytes32 indexed gameId, address ...
Greg Jeanmart's user avatar
5 votes
Accepted

Offline transaction signing with web3j?

I think something like this should work // Create the Transaction RawTransaction rawTransaction = RawTransaction.createEtherTransaction(<nonce>, <gasPrice>, <gasLimit>, <...
Majd TL's user avatar
  • 3,257
4 votes
Accepted

How to store user private keys and details

If you store keys and password anywhere else than on the users device then you are back to square one, should stop right here, go back to using a traditional webservice and payment integration using ...
SCBuergel's user avatar
  • 8,784
4 votes
Accepted

Using Web3j to load a smart contract, how do i specify my credentials?

To generate the Credentials if you have a plain public key and private key, you need to convert them in to the hex representation and then pass them in to the constructor for Credentials String ...
zaf187's user avatar
  • 151
4 votes

How fetch transaction history for account quickly using Web3j?

There is no workaround besides of the links you´ve posted. It will depend of your CPU power, network and database. I believe they (etherscan team) gets data from the blockchain and stores in an ...
Luiz Soares's user avatar
  • 1,054
4 votes

How to view custom token balance in ether wallet using web3

Web3 has been updated since @Vanja Dev's answer var tokenInst = new web3.eth.Contract(tokenABI,tokenAddress); tokenInst.methods.balanceOf('0x260c25f991171850f48889eb9d8aF11998D20c30').call()....
Code Tree's user avatar
  • 140

Only top scored, non community-wiki answers of a minimum length are eligible