web3.eth.personal: "Método no encontrado"

Cuando invoco un método de web3.eth.personal, recibo el siguiente error:

> web3.eth.personal.getAccounts().then(console.log);
Promise {
  <pending>,
  domain: 
   Domain {
     domain: null,
     _events: 
      { removeListener: [Function: updateExceptionCapture],
        newListener: [Function: updateExceptionCapture],
        error: [Function: debugDomainError] },
     _eventsCount: 3,
     _maxListeners: undefined,
     members: [] } }
> (node:34481) UnhandledPromiseRejectionWarning: Error: Returned error: Method not found
    at Object.ErrorResponse (/home/s/node_modules/web3-core-helpers/src/errors.js:29:16)
    at /home/s/node_modules/web3-core-requestmanager/src/index.js:140:36
    at XMLHttpRequest.request.onreadystatechange (/home/s/node_modules/web3-providers-http/src/index.js:77:13)
    at XMLHttpRequestEventTarget.dispatchEvent (/home/s/node_modules/xhr2/lib/xhr2.js:64:18)
    at XMLHttpRequest._setReadyState (/home/s/node_modules/xhr2/lib/xhr2.js:354:12)
    at XMLHttpRequest._onHttpResponseEnd (/home/s/node_modules/xhr2/lib/xhr2.js:509:12)
    at IncomingMessage.<anonymous> (/home/s/node_modules/xhr2/lib/xhr2.js:469:24)
    at IncomingMessage.emit (events.js:185:15)
    at IncomingMessage.emit (domain.js:440:23)
    at endReadableNT (_stream_readable.js:1106:12)
    at process._tickCallback (internal/process/next_tick.js:178:19)
(node:34481) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:34481) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

¿Necesito instalar o definir algún requisito adicional? También he instalado web3-eth-personal de la siguiente manera:

npm install web3-eth-personal

Y luego uso los siguientes comandos:

var Personal = require('web3-eth-personal');
var personal = new Personal( new Personal.providers.HttpProvider("http://localhost:8545"));
web3.eth.personal.getAccounts().then(console.log);

PD. Encontré la solución: comencé con Parity Parity --chain tobalaba --jsonrpc-hosts all --jsonrpc-interface all --jsonrpc-cors '*' --jsonrpc-apis 'web3,eth,net,parity,traces,rpc,parity_set,personal'y ahora funciona.

¿Podría darme algunas pistas, cuál es esa parte de la paridad? ¿Dónde hago eso cuando uso Cloudflare como proveedor?

Respuestas (3)

Para paridad : como se documenta en las opciones, disponible en paridad --ayuda, no todas las API están expuestas de manera predeterminada. Sin embargo, simplemente puede habilitarlos ejecutando la paridad con la bandera: --jsonrpc-apis APISexp:

parity --jsonrpc-apis web3,rpc,personal,parity_accounts,eth,net,parity,parity_set,signer 

para geth comienza tu geth con--rpcapi "eth,net,web3,personal"

para usar websocket rpc en lugar de json rpc en Geth, reemplace flag --jsonrpc con --wsrpc

Usé web3.personaldirectamente y pude acceder a los métodos dentro de él nuevamente.

Esto es extraño porque en la consola, web3.eth.personalsigue siendo lo que funciona, pero en el script para un navegador, no funciona.

Espero que esto ayude.

GetAccounts() o cuentas, es un método de eth:

web3.eth.getAccounts().then(console.log);

de lo contrario, con personal puede crear una nueva cuenta, firmar una transacción en otro nodo (no localmente), así que asegúrese de que sea seguro.

Espero que ayude

phill