web3j ethGetBalance () всегда дает ноль в случае, если мой локальный кошелек установлен на Ubuntu - PullRequest
0 голосов
/ 27 марта 2019

Я установил Ethereum Wallet на свою Ubuntu AWS. Затем я запускаю Ethereum Wallet, используя эту команду (sudo geth --syncmode "fast" --cache=2048 --maxpeers=128 --metrics --rpc --rpcapi "db,eth,net,web3,personal,web3" --rpcaddr "0.0.0.0" --rpcport 8545 --rpcvhosts "*"). Затем запускается кошелек ethereum. Затем я создал 1 кошелек, используя web3j Java

public Map<String, Object> createWallet(){
        String password = "your_password";
        ECKeyPair keyPair = Keys.createEcKeyPair();
        WalletFile wallet = Wallet.createStandard(password, keyPair);
        Map<String, Object> map = new HashMap<String, Object>();
        if (!MethodUtils.isObjectisNullOrEmpty(wallet)) {
            map.put("account", wallet.getAddress());
            LOGGER.debug("createWallet() : Account is {}.", wallet.getAddress());
        }
        if (!MethodUtils.isObjectisNullOrEmpty(keyPair)) {
            String privateKey = keyPair.getPrivateKey().toString(16);
            map.put("privateKey", keyPair.getPrivateKey().toString(16));
            LOGGER.debug("createWallet() : Private key is {}.", keyPair.getPrivateKey().toString(16));
            Credentials cs = Credentials.create(privateKey);
            privateKey = cs.getEcKeyPair().getPrivateKey().toString(16);
            String publicKey = cs.getEcKeyPair().getPublicKey().toString(16);
            String address = cs.getAddress();
            map.put("publicKey", publicKey);
            map.put("address", address);
        }
        return map;
}

Поддержка, которую я получил по адресу = "0xE433A747ea68A558D49Fc2B558E36029bAC757d8" Затем я пополняю баланс некоторым эфиром по вышеуказанному адресу. Затем я использовал ниже Java-код web3j, чтобы проверить баланс

@Override
    public Map<String, Object> ethGetBalance(String address) throws InterruptedException, ExecutionException {

        Web3j web3 = Web3j.build(new HttpService("http://my_ip_address_of_aws_ubuntu:8545"))); // (Error : 0 Balance)
        // Below commented line gives correct balance
        //Web3j web3 = Web3j.build(new HttpService("https://mainnet.infura.io/v3/your_token"))); // (Correct Balance)
        EthGetBalance ethGetBalance = web3j.ethGetBalance(address, DefaultBlockParameterName.LATEST).sendAsync().get();

        Map<String, Object> map = new HashMap<String, Object>();
        if (!MethodUtils.isObjectisNullOrEmpty(ethGetBalance)) {

            map.put("id", ethGetBalance.getId());
            map.put("jsonRpc", ethGetBalance.getJsonrpc());
            map.put("result", ethGetBalance.getResult());
            map.put("rowResponse", ethGetBalance.getRawResponse());

            map.put("balance", ethGetBalance.getBalance());
        }

        return map;
    }

Вывод (ошибка: баланс равен 0, но у меня баланс больше нуля)

{ «результат»: «0x0», «баланс»: 0, "id": 1, "rowResponse": ноль, "jsonRpc": "2.0" } * +1010 *

Объяснение вывода

1. Web3j web3 = Web3j.build(new HttpService("http://my_ip_address_of_aws_ubuntu:8545")));
   Note : if i connect Web3j with my local ethereum wallet of my aws ubuntu then it gives balance 0 every time.
2. Web3j web3 = Web3j.build(new HttpService("https://mainnet.infura.io/v3/your_token"))); 
   Note : but if i connect Web3j with infura instread of local wallet then it gives correct balance
...