personalUnlockAccount.accountUnlocked() dando NullPointerException incluso si se ha insertado la frase de contraseña correcta

Cuando intento desbloquear la cuenta con el método personalUnlockAccount.accountUnlocked() de la clase PersonalUnlockAccount de la biblioteca web3j, está dando NullPointerException incluso si estoy ingresando la contraseña correcta.

Señale el mal que estoy cometiendo en el siguiente código.

package com.kaushik.blockchain;

import java.io.IOException;
import java.math.BigInteger;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.web3j.protocol.admin.Admin;
import org.web3j.protocol.admin.methods.response.PersonalUnlockAccount;
import org.web3j.protocol.core.DefaultBlockParameterName;
import org.web3j.protocol.core.methods.request.Transaction;
import org.web3j.protocol.core.methods.response.EthGetBalance;
import org.web3j.protocol.core.methods.response.EthGetTransactionCount;
import org.web3j.protocol.core.methods.response.EthGetTransactionReceipt;
import org.web3j.protocol.core.methods.response.EthSendTransaction;
import org.web3j.protocol.core.methods.response.TransactionReceipt;
import org.web3j.protocol.http.HttpService;
import org.web3j.utils.Convert;

public class MainTransferApp {
    private static final Logger log =
            LoggerFactory.getLogger(MainTransferApp.class);
    public static void main(String[] args) throws Exception {
        new MainTransferApp().run();
    }
    private void run() throws IOException, InterruptedException {
        String from = "0xe8fbbddf73c128e50f824ec6af65cb15c237fe58";
        String to =   "0x288a49996ae58aa9999389912cba8cf908a0990e";
        Admin web3j = Admin.build(new HttpService());
        //web3j
        log.info("Connected to Ethereum client version: "
                + web3j.web3ClientVersion().send().getWeb3ClientVersion());
        PersonalUnlockAccount personalUnlockAccount = web3j.personalUnlockAccount(from, "passPhrase").send();
        log.info("Unlocked: "+personalUnlockAccount.accountUnlocked());
        if(personalUnlockAccount.accountUnlocked()){
        EthGetTransactionCount transactionCount = 
                web3j.ethGetTransactionCount(from, DefaultBlockParameterName.LATEST).send();
        BigInteger value = Convert.toWei("45.0", Convert.Unit.ETHER).toBigInteger();
        Transaction transaction = Transaction.createEtherTransaction(from, 
                transactionCount.getTransactionCount(), 
                BigInteger.valueOf(10000), BigInteger.valueOf(4500000), 
                to, value);
        EthSendTransaction response = web3j.ethSendTransaction(transaction).send();
        if (response.getError() != null) {
            log.info("Transaction error: {}", response.getError().getMessage());
        }
        log.info("Transaction: {}", response.getResult());
        EthGetTransactionReceipt receipt = 
                web3j.ethGetTransactionReceipt(response.getTransactionHash()).send();
        if (receipt.getTransactionReceipt().isPresent()) {
            TransactionReceipt r = receipt.getTransactionReceipt().get();
            log.info("Tx receipt: from={}, to={}, gas={}, cumulativeGas={}", r.getFrom(), r.getTo(), r.getGasUsed().intValue(), r.getCumulativeGasUsed().intValue());
        }
        Thread.sleep(5000);
        EthGetBalance balance = web3j.ethGetBalance(from, DefaultBlockParameterName.LATEST).send();
        log.info("Balance: address={}, amount={}", from, balance.getBalance().longValue());
        balance = web3j.ethGetBalance(to, DefaultBlockParameterName.LATEST).send();
        log.info("Balance: address={}, amount={}", to, balance.getBalance().longValue());
        }else{
            log.info("Error occurred while unlocking account");
        }

    }
}

Ahora bien, este es el error que estoy recibiendo. Por favor, ayúdame.

[main] INFO com.kaushik.blockchain.MainTransferApp - Connected to Ethereum client version: Geth/nodeSOL/v1.8.13-stable-225171a4/windows-amd64/go1.10.3
[main] INFO com.kaushik.blockchain.MainTransferApp - Unlocked: null
Exception in thread "main" java.lang.NullPointerException
    at com.kaushik.blockchain.MainTransferApp.run(MainTransferApp.java:35)
    at com.kaushik.blockchain.MainTransferApp.main(MainTransferApp.java:24)

Por favor sugiérame al revés. En mi proyecto, quiero enviar desde la dirección y la contraseña desde la interfaz de usuario. ¿Hay algún otro enfoque con el que pueda ir, que debería ser fácil desde la perspectiva del usuario?

¿Cuál es el comando que se usa para iniciar geth? ¿Está personalhabilitada la API?
@Ismael Estoy usando el siguiente comando. geth --datadir=E:/BC_Private/node1 --networkid 2061 --port 30304 --nodiscover --rpc --rpcaddr 127.0.0.1 --rpcport 8545 --ipcpath=E:/BC_Private/node1/geth.ipc - -mine --minerthreads 1 --gasprice "10000" --etherbase 0xd0831f602d3e10c2c4442918abb0a84cef5582f5 --targetgaslimit "5800000" --verbosidad 3 consola
A partir de esta respuesta , ethereum.stackexchange.com/a/1414 , debe habilitarlo explícitamente para RPC con --rpcapi "db,eth,net,web3,personal".
@Ismael Si no estoy usando esta bandera, significa que por defecto tendrá "db,eth,net,web3,personal". ¿no es así? Por favor aclara mi duda.
Por razones de seguridad personal, no está habilitado en RPC, debe habilitarlo explícitamente.
@Ismael Probaré esta solución y te actualizaré. :)
Tengo el mismo problema. personal está claramente habilitado en --rpcapi , usando la opción de adjuntar cliente de script de Java confirma esto donde personal.unlockAccount devuelve verdadero con la misma dirección y opción de paso, sin embargo, se devuelve nulo de la llamada API usando web3j ... Se agradece cualquier solución
@Abelgo Pruebe todos estos indicadores explícitamente --rpcapi "db,eth,net,web3,personal". O comparte tu código.
Habilité el registro de seguimiento en la biblioteca java web3j. Mi conclusión es. Las llamadas funcionan, la cuenta está desbloqueada y se registra la respuesta correcta de Json RPC. Sin embargo, web3j está roto, aún devuelve nulo independientemente. También probé usando IPC donde el personal debería estar habilitado de forma predeterminada... el mismo resultado, web3j parece estar roto aquí.
También hay un método para desbloquear y enviar en la misma transacción. ver "personal_sendTransaction" guardará el paso de desbloqueo. org.web3j.protocol.core.methods.request.Transaction txn = org.web3j.protocol.core.methods.request.Transaction.createEtherTransaction(eth_address, nonce.incrementAndGet(), gassPrice, gassLimit, toAddress, value); EthSendTransaction sentTXN = node_admin.personalSendTransaction(txn, this.getPrivateKey() ).send();
¿Puedes desbloquear tu cuenta dentro geth?

Respuestas (2)

Necesito usar explícitamente la API personal para RPC. Usar esta bandera funcionó para mí.

--rpcapi "db,eth,net,web3,personal"

Gracias @Ismael por la ayuda.

Un poco más de información. Parece que estoy obteniendo algunos resultados inconsistentes aquí. En este segmento de código, RawResponce es nulo, sin embargo, el valor booleano se devuelve correctamente.

                LOG.info("CALLING UNLOCK !!");
                PersonalUnlockAccount ok = RPC_ADMIN.personalUnlockAccount(HOT_WALLET, ac.getPrivateKey(), ACCOUNT_UNLOCK_SECONDS).send();
                LOG.info("RAW RESPONCE IS: " + ok.getRawResponse());
                LOG.info( "BOOLEAN IS:"  +  ok.accountUnlocked().toString());

10:35:42.550 [principal] INFORMACIÓN com.abelgo.eth.EthAdaptor - ¡DESBLOQUEO DE LLAMADAS! 10:35:42.552 [principal] DEPURAR org.web3j.protocol.ipc.IpcService - >> {"jsonrpc":"2.0","método":"personal_unlockAccount","params":["0xf1b0725bd64cbe62a5160357d53e92c54788f2e5","-SECRET -",7],"id":13} 10:35:43.245 [principal] DEPURAR org.web3j.protocol.ipc.IpcService - << {"jsonrpc":"2.0","id":13,"resultado ":verdadero}

10:35:43.247 [principal] INFORMACIÓN com.abelgo.eth.EthAdaptor - LA RESPUESTA SIN PROCESAR ES: nula 10:35:43.247 [principal] INFORMACIÓN com.abelgo.eth.EthAdaptor - BOOLEAN ES: verdadero