@Test public void testEthGetBalance() { buildResponse( "{\n" + " \"id\":1,\n" + " \"jsonrpc\": \"2.0\",\n" + " \"result\": \"0x234c8a3397aab58\"\n" + "}" ); EthGetBalance ethGetBalance = deserialiseResponse(EthGetBalance.class); assertThat(ethGetBalance.getBalance(), equalTo(BigInteger.valueOf(158972490234375000L))); }
public BigInteger getBalance() { return Numeric.decodeQuantity(getResult()); } }
@Override public BigInteger execute(final JsonRequestFactories node) { try { final EthGetBalance result = node.eth().ethGetBalance(account.getAddress(), LATEST).send(); assertThat(result).isNotNull(); assertThat(result.hasError()).isFalse(); return result.getBalance(); } catch (final IOException e) { throw new RuntimeException(e); } } }
@Test public void testEthGetBalance() throws Exception { EthGetBalance ethGetBalance = web3j.ethGetBalance( config.validAccount(), DefaultBlockParameter.valueOf("latest")).send(); assertTrue(ethGetBalance.getBalance().signum() == 1); }
public BigInteger getBalance(String fromAddress){ BigInteger balance = null; try { EthGetBalance ethGetBalance = web3j.ethGetBalance(fromAddress, DefaultBlockParameterName.PENDING).send(); balance = ethGetBalance.getBalance(); } catch (IOException e) { e.printStackTrace(); } System.out.println("address " + fromAddress + " balance " + balance + " wei"); return balance; }
/** * Returns the balance (in Wei) of the specified account address. */ public static BigInteger getBalanceWei(Web3j web3j, String address) throws InterruptedException, ExecutionException { EthGetBalance balance = web3j .ethGetBalance(address, DefaultBlockParameterName.LATEST) .sendAsync() .get(); return balance.getBalance(); }
/** * 获取余额 * * @param address 钱包地址 * @return 余额 */ private static BigInteger getBalance(String address) { BigInteger balance = null; try { EthGetBalance ethGetBalance = web3j.ethGetBalance(address, DefaultBlockParameterName.LATEST).send(); balance = ethGetBalance.getBalance(); } catch (IOException e) { e.printStackTrace(); } System.out.println("address " + address + " balance " + balance + "wei"); return balance; }
@Override public EthValue getBalance(EthAddress address) { return EthValue.wei(web3JFacade.getBalance(address).getBalance()); }
/** * getBalance function is used to get Balance and it returns the BigInteger value. * @throws InterruptedException * @throws ExecutionException * @return */ public static BigInteger getBalance(){ Future<EthGetBalance> ethGetBalanceFuture = web3.ethGetBalance(credentials.getAddress(), DefaultBlockParameterName.LATEST).sendAsync(); try { return ethGetBalanceFuture.get().getBalance(); }catch (Exception e){ return BigInteger.ONE; } }
@Override public boolean addressExists(EthAddress address) { return web3JFacade.getTransactionCount(address).intValue() > 0 || web3JFacade.getBalance(address).getBalance().intValue() > 0 || !web3JFacade.getCode(address).isEmpty(); }
@InvokeOnHeader(Web3jConstants.ETH_GET_BALANCE) void ethGetBalance(Message message) throws IOException { String address = message.getHeader(Web3jConstants.ADDRESS, configuration::getAddress, String.class); DefaultBlockParameter atBlock = toBlockParameter(message.getHeader(Web3jConstants.AT_BLOCK, configuration::getAtBlock, Object.class)); Request<?, EthGetBalance> request = web3j.ethGetBalance(address, atBlock); setRequestId(message, request); EthGetBalance response = request.send(); boolean hasError = checkForError(message, response); if (!hasError) { message.setBody(response.getBalance()); } }
public static BigDecimal getBalanceInEther(Credentials credentials, Web3j web3j) throws Exception { EthGetBalance ethGetBalance = web3j.ethGetBalance(credentials.getAddress(), DefaultBlockParameterName.LATEST).send(); return Convert.fromWei(ethGetBalance.getBalance().toString(), Convert.Unit.ETHER); }
DefaultBlockParameterName.LATEST).send().getBalance(); runOnUiThread(new Runnable() { @Override
@ScalarFunction("eth_getBalance") @Description("Returns the balance of an address") @SqlType(StandardTypes.DOUBLE) public static double ethGetBalance(@SqlType(StandardTypes.VARCHAR) Slice address, @SqlType(StandardTypes.BIGINT) long blockNumber) throws IOException { return web3j.ethGetBalance(address.toStringUtf8(), DefaultBlockParameter.valueOf(BigInteger.valueOf(blockNumber))).send().getBalance().doubleValue(); }
@Override public Single<BigInteger> balanceInWei(Wallet wallet) { return Single.fromCallable(() -> Web3jFactory .build(new HttpService(networkRepository.getDefaultNetwork().rpcServerUrl, httpClient, false)) .ethGetBalance(wallet.address, DefaultBlockParameterName.LATEST) .send() .getBalance()) .subscribeOn(Schedulers.io()); } }
@ScalarFunction("eth_getBalance") @Description("Returns the balance of an address") @SqlType(StandardTypes.DOUBLE) public static double ethGetBalance(@SqlType(StandardTypes.VARCHAR) Slice address) throws IOException { return web3j.ethGetBalance(address.toStringUtf8(), DefaultBlockParameter.valueOf(LATEST)).send().getBalance().doubleValue(); }
@ScalarFunction("eth_getBalance") @Description("Returns the balance of an address") @SqlType(StandardTypes.DOUBLE) public static double ethGetBalance(@SqlType(StandardTypes.VARCHAR) Slice address, @SqlType(StandardTypes.VARCHAR) Slice blockName) throws IOException { return web3j.ethGetBalance(address.toStringUtf8(), DefaultBlockParameter.valueOf(blockName.toStringUtf8())).send().getBalance().doubleValue(); }
any(DefaultBlockParameterName.class))).thenReturn(balanceRequest); when(balanceRequest.send()).thenReturn(ethGetBalance); when(ethGetBalance.getBalance()).thenReturn(BigInteger.valueOf(100)); when(transfer.sendFunds(anyString(), any(BigDecimal.class),