0

I am using Infura and web3j to query the Ethereum blockchain. My aim is to get information about certain blocks so i'm using the function web3.eth.getBlockByNumber, however it gives me incompatible types error: int cannot be converted to DefaultBlockParameter. How can we convert an integer to default block parameter? Current code:

System.out.println("here " +web3j.ethGetBlockByNumber(6777, true));
1

The datatype here would be BigInteger()

In the web3j Manual there is an example for a Transaction which uses BigIntegers:

Transaction transaction = Transaction.createContractTransaction(
<from address>,
<nonce>,
BigInteger.valueOf(<gas price>),
// we use default gas limit
"0x...<smart contract code to execute>"
);
org.web3j.protocol.core.methods.response.EthSendTransaction
transactionResponse = parity.ethSendTransaction(ethSendTransaction)
.send();
String transactionHash = transactionResponse.getTransactionHash();

Your could would be:

System.out.println("here " +web3j.ethGetBlockByNumber(BigInteger.valueOf(6777), true));
  • Now its giving the error big integer cannot be converted to default block parameter – mahamzaidi Oct 22 '18 at 10:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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