Hot answers tagged

11

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 mining, please execute eth.hashrate to check, if the return value is greater than zero, it is mining, otherwise, it is not. Now let's analyze why miner.start(...


11

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 = new JSONObject(); try { ECKeyPair ecKeyPair = Keys.createEcKeyPair(); BigInteger privateKeyInDec = ecKeyPair.getPrivateKey()...


9

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/ // send asynchronous requests to get balance EthGetBalance ethGetBalance = web3 .ethGetBalance("0xAccountAddress", DefaultBlockParameterName.LATEST) ....


7

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) converts any HexString to byte[]. This is the process: String => Hex => 32 length Hex (ie. 64 length HexString) => byte[] => Bytes32 Note: "00" = 1 Hex ...


7

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(address _owner) method // Get the account balance of another account with address _owner function balanceOf(address _owner) public constant returns (uint256 balance)...


7

You can send and confirm transaction without waiting using CompletableFuture and callback function. rc-> Instance that calls contract function through remote call. CompletableFuture<TransactionReceipt> transactionReceiptCompletableFuture = rc.sendAsync(); transactionReceiptCompletableFuture.thenAccept(transactionReceipt -> { // then accept ...


6

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.start() Even if it returns null you can see in the buttom left corner of Mist broser, that mining has startet. It takes a while till the hashrate incrases. You ...


6

@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(ethGetBalance.getBalance().toString(), Unit.ETHER);


6

Under the hood, the Web3J SmartContract Java Wrapper calculates the nonce by getting the number of transactions getTransactionCount for the account (credential). EthGetTransactionCount ethGetTransactionCount = web3.ethGetTransactionCount(credentials.getAddress(), DefaultBlockParameterName.PENDING).send(); BigInteger nonce = ethGetTransactionCount....


5

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 contract address as part of your filter. EthFilter filter = new EthFilter(DefaultBlockParameterName.EARLIEST, DefaultBlockParameterName.LATEST, contract....


5

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 the third line in your code. The list "outputParameters" should contain all return variables of the method. So if you are expecting a String you should do ...


5

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 with javascript int or string. You can read more about this here and here. To understand the object output, I found on BigNumbers's git that: The value of a ...


5

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 contract. This blog post gives an example: an eth_call to a function function myFunction(uint256 input) public view returns (uint256) { require(input >= 5, ...


4

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 = Sign.signedMessageToKey(messageBytes, sig).toString(16); These methods internally hash(sha3) the input messageBytes before signing and on verification. This ...


4

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 hexPrivateKey = String.format("%040x", new BigInteger(1, privateKey.getBytes())); String hexPublicKey = String.format("%040x", new BigInteger(1, publicKey.getBytes())...


4

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 code, pollingInterval = 3000; // 3 seconds FastRawTransactionManager fastRawTxMgr = new FastRawTransactionManager(web3, credentials, new ...


4

This is the easiest way Web3j web3j = Web3j.build(new HttpService("https://rinkeby.infura.io/v3/.......")); Block block = web3j.ethGetBlockByNumber(DefaultBlockParameterName.LATEST, false).send().getBlock(); System.out.println(block.getNumber().toString());


4

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 myContractInstance = MyContract.at(contractAddress); // send a transaction to a function myContractInstance.myStateChangingMethod('someParam1', {value: xxx, gas: xxxx}); If ...


4

Opcode 0x1c is SHR or right shift, which was introduced in the recent update (more here). It was not available prior to February, 2019. It is likely that your Java tool (web3j?) is out dated and does not recognize this opcode. You may be able to upgrade to a newer version which has Constantinople/St. Petersburg support.


4

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; } function get() public view returns (uint) { return storedData; } } You can send a transaction to a (already deployed) smart contract with the ...


3

The result variable in console.log(result) is an object which contains these fields (see the docs): Object - An event object as follows: address: String, 32 Bytes - address from which this log originated. args: Object - The arguments coming from the event. blockHash: String, 32 Bytes - hash of the block where this log was in. null when its pending. ...


3

I figured out what was wrong. My GAS_PRICE and GAS_LIMIT values were not proper. I later figured out that Web3j has default GAS_PRICE and GAS_LIMIT, see updated code below BigInteger GAS = Contract.GAS_LIMIT; BigInteger GAS_PRICE = Contract.GAS_PRICE; Contract.GAS_LIMIT and Contract.GAS_PRICE are deprecated. Hence, use the below constants ...


3

The null is expected. If you are mining you will see lots of messages in your console like this: INFO [07-25|18:46:25] Successfully sealed new block number=72 hash=d0316eā€¦36554e INFO [07-25|18:46:25] šŸ”— block reached canonical chain number=67 hash=a89be4ā€¦5a73be INFO [07-25|18:46:25] šŸ”Ø mined potential block number=72 ...


3

You can use CURL command or use request module inside your code to call create account API - CURL command for your reference: curl -X POST --data '{"jsonrpc":"2.0","method":"personal_newAccount","params":["pass"],"id":74}' http://localhost:8545 Also, you must run the geth node with the "personal" api enabled to make this method available: geth --rpc --...


3

I am not sure about how did you configure your Blockchain on Azure, i assume that you have created a mining node(s) while you are creating your private blockchain, if so, we need to connect to that node with SSH,, to do so, lookup for the mining node address,, you can find it in : Deployments > Microsoft-azure-blockchain.azure-multi.... Now, copy the ...


3

I finally figured out what was wrong with my code. I debugged the Web3j codes and found that since Mining nodes were not accepting the transaction after 40 retries with Sleep duration of 15000 the TransactionTimeoutException is thrown and the TransactionReceipt is not generated. See below Web3j code from TransactionManager.java Source of the Exception ...


3

Non-constant solidity functions can not return a value. This is generally because you have to send the value out to the network to be processed for an indeterminate amount of time. This makes it kind of difficult to get any data back to you, the sender. What you could do, is use events, or just follow up later with a constant function call.


3

Web3j documentation explains most of the things. I found this android ethereum wallet created using web3j. Might help you. https://github.com/matthiaszimmermann/ethereum-paper-wallet Alternate: I would recommend cross-compiled go-ethereum for Android. This is a light client for mobile devices and does not require you to download the entire blockchain. After ...


3

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 Stripe or alike. A secure way to go, is to implement a hardware wallet such as this one or this one. Geth can interface them and they also come with APIs that ...


3

The API for the web3.js v1.0 changed. The tutorial is using the web3 api v0.x.x. Thus, you must either update your node to use the proper API npm install ethereumjs-testrpc web3@0.20.1 or, you must update the code to use the v1.0 implementation. I.E: web3.eth.getAccounts(console.log); You can also refer to the github from mjhm who did a great job ...


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