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()...


8

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) ....


6

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 ...


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

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 ...


5

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 ...


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

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 ...


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 ...


4

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....


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 ...


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 ...


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

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

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 ...


3

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 indexed database and uses some analytics tools to display data to users.


3

I guess sort of for the first question. If you look at what a transaction is, to a node its just a big long byte string. If the bytes are convertible to ASCII, you can use use the web3.toAscii() That may or may not give you something. For instance, here's a tx a I did on Ropsten where you get some readable input data back and some non-readable data: ...


3

If you just want to check if the mint() function was called this is the part that you are interested in "input": "0x40c10f19000000000000000000000000a4d0fb50a216d005d0510743686bfca140856f4500000000000000000000000000000000000000000000003635c9adc5dea00000", The first 4 bytes of the payload are 0x40c10f19 and these uniquely identify the function signature mint(...


3

Two things you need for this: Infura Web3js Infura will allow you to connect to the ethereum network (and is free). Then you can use web3 to interact with your contract. Hope it helps.


3

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 privateKeyInBT = new BigInteger(privateKeyInHex, 16); ECKeyPair aPair = ECKeyPair.create(privateKeyInBT); BigInteger publicKeyInBT = aPair.getPublicKey(); ...


3

I found the solution to the problem, of how to get the private key after generate a wallet: Credentials credentials = Credentials.create(Wallet.decrypt(seed, wallet)); String privateKeyGenerated = credentials.getEcKeyPair().getPrivateKey().toString(16);


3

Presumably your <some private data> is ASCII encoded and Ethereum converts everything in byte code (machine readable) and returns everything in hexadecimal (base16) which mess up the encoding. So the solution consist in encoding your message in ASCII hex before sending the transaction. public static String ASCIItoHEX(String ascii) { // ...


3

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, provided you have the transaction hash: Optional<TransactionReceipt> transactionReceipt = web3j.ethGetTransactionReceipt(txHash).send()....


3

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 indexed player1, address indexed player2); event PlayerMoved(bytes32 indexed gameId, address indexed player); event GameEnded(bytes32 indexed gameId, address indexed ...


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