Nota: actualicé el código html
/ JavaScript
de acuerdo con la respuesta y usé ESTE código de muestra de META MASK para el proveedor web3. Sin embargo, recibo el mismo error. Eventualmente no entendí que necesito ejecutar testRPC o no? .
Ejecuto el siguiente html
JavaScript
código para generar una firma después de ejecutar testRPC
y usar Meta Mask de la siguiente manera:
(1) ejecutar testRPC
:
PS C:\Users\s> testrpc
EthereumJS TestRPC v6.0.3 (ganache-core: 2.0.2
Available Accounts
==================
(0) 0xf4d2b942c3baebef5b81f4b909904015166b238a
(1) 0xef0d1e102d33252f232b39b31950f736ab2535aa
(2) 0x23064a138dc6b681a51a18b837a376f061fbc511
(3) 0x2dfaf5c48bc3c868f63741d6cd0489b336e74b03
(4) 0x372110011158860806d9d9b19aa67c045740727a
(5) 0x3faa74be50e1dfa86e5f6951a8c11b3e726edf65
(6) 0xaecc4c8f0b802b83a2cd84e6c98ecad6b0495c00
(7) 0x36b08ae47ec94870b98b0e0d98fca2646332ae87
(8) 0x1461cfb91f6fd2aca8d722dce9f67f7806732e49
(9) 0x1a0b2fd11e57f6473ae5f9b55e17cbfb6d8b504e
Private Keys
==================
(0) acb8b8ee76ce99fc390127ae88e246d3f8d8ac3db7
(1) 8957622705ccec21da4791f8535c70ab4726bfbe08
(2) 41181e3cf8c0294e949062a894bd96aea15e342db5
(3) c1bad63470c62b56032b034df0f0b827779e678cfd
(4) f49109620e9e56aa0bff9bdeb486d05ca75732cf1a
(5) ed1107372972a702c166924846f6d01234b9d277a7
(6) 10afce272e6a3d1d3474c385bf28be7e58de991995
(7) 0a92c9aa01497d29f01023cdeb50429954be06c949
(8) 87d0c56f9cab4c86ebc66749d0894719b647f72cea
(9) c8ca68e445b249a7d860fc3d76b210d6dd1a1c2197
HD Wallet
==================
Mnemonic: access invest retire civil eagl
Base HD Path: m/44'/60'/0'/0/{account_index}
(2) seleccionando 0xf4d2b942c3baebef5b81f4b909904015166b238a
como dirección del firmante.
(3) agregando 0xf4d2b942c3baebef5b81f4b909904015166b238a
a Meta Mask .
(4) ejecutando el siguiente html
/ JavaScript
código en Google Chrome
:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>EthereumJS - Browser Example</title>
</head>
<body>
<script src="https://rawgit.com/ethereumjs/browser-builds/master/dist/ethereumjs-abi/ethereumjs-abi-0.6.5.js"></script>
<script src="https://rawgit.com/ethereum/web3.js/develop/dist/web3.js"></script>
<script src="https://cdn.jsdelivr.net/gh/ethereum/web3.js/dist/web3.min.js"></script>
<script>
window.addEventListener('load', function() {
// Checking if Web3 has been injected by the browser (Mist/MetaMask)
if (typeof web3 !== 'undefined') {
// Use Mist/MetaMask's provider
web3 = new Web3(web3.currentProvider);
} else {
console.log('No web3? You should consider trying MetaMask!')
// fallback - use your fallback strategy (local node / hosted node + in-dapp id mgmt / fail)
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
}
// var Web3
// web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
function constructPaymentMessage(contractAddress, amount)
{
return ethereumjs.ABI.soliditySHA3(
["address", "uint256"],
[contractAddress, amount],
);
}
var message = constructPaymentMessage("0x0f0f422477d83bcbed227b0ae2fa3ace7ea3c653", 100);
console.log(message);
web3.personal.sign("0x" + message.toString("hex"), "0xF4D2B942c3baebef5B81F4B909904015166b238A", function(err, signature) {
console.log(signature);
console.log(err);
// Be sure to make use of the signature only here.
// It will not be defined until this callback is invoked.
});
})
</script>
</body>
</html>
Y el siguiente es el resultado:
Tenga en cuenta que
Uint8Array(32) [2, 16, 48, 216, 191, 103, 173, 178, 132, 121, 144, 241, 45, 224, 83, 239, 76, 206, 69, 151, 42, 86, 174, 144, 3, 97, 172, 171, 166, 231, 234, 10]
es el message
valor y el resultado de console.log(message);
y no el valor de la firma y cuando uso console.log(signature);
la salida es solo undefined
.
¿ Cómo puedo ver el valor de la firma ?
Y el siguiente es el mensaje de error, resultado de console.log(err);
:
Error: Método personal_sign no compatible
Error: Error: Method personal_sign not supported.
at GethApiDouble.handleRequest (C:\Users\s\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\build\cli.node.js:89858:16)
at next (C:\Users\s\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\build\cli.node.js:59378:18)
at GethDefaults.handleRequest (C:\Users\s\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\build\cli.node.js:89767:12)
at next (C:\Users\s\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\build\cli.node.js:59378:18)
at FilterSubprovider.handleRequest (C:\Users\s\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\build\cli.node.js:65832:7)
at next (C:\Users\s\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\build\cli.node.js:59378:18)
at DelayedBlockFilter.handleRequest (C:\Users\s\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\build\cli.node.js:89595:3)
at next (C:\Users\s\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\build\cli.node.js:59378:18)
at ReactiveBlockTracker.handleRequest (C:\Users\s\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\build\cli.node.js:89722:12)
at next (C:\Users\s\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\build\cli.node.js:59378:18)
at GethApiDouble.handleRequest (C:\Users\s\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\build\cli.node.js:89858:16)
at next (C:\Users\s\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\build\cli.node.js:59378:18)
at GethDefaults.handleRequest (C:\Users\s\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\build\cli.node.js:89767:12)
at next (C:\Users\s\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\build\cli.node.js:59378:18)
at FilterSubprovider.handleRequest (C:\Users\s\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\build\cli.node.js:65832:7)
at next (C:\Users\s\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\build\cli.node.js:59378:18)
at DelayedBlockFilter.handleRequest (C:\Users\s\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\build\cli.node.js:89595:3)
at next (C:\Users\s\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\build\cli.node.js:59378:18)
at ReactiveBlockTracker.handleRequest (C:\Users\s\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\build\cli.node.js:89722:12)
at next (C:\Users\s\AppData\Roaming\npm\node_modules\ethereumjs-testrpc\build\cli.node.js:59378:18)
at Object.InvalidResponse (https://rawgit.com/ethereum/web3.js/develop/dist/web3.js:3138:16)
at https://rawgit.com/ethereum/web3.js/develop/dist/web3.js:6375:36
at XMLHttpRequest.request.onreadystatechange (https://rawgit.com/ethereum/web3.js/develop/dist/web3.js:4377:7)
Pregunta relacionada: "ACTUALIZADO:" "Excepción de máquina virtual al procesar la transacción: revertir"
La firma se envía a su devolución de llamada, que está vacía en el código que compartió. Esto debería funcionar:
web3.personal.sign("0x" + message.toString("hex"), "0xF4D2B942c3baebef5B81F4B909904015166b238A", function(err, signature) {
console.log(signature);
// Be sure to make use of the signature only here.
// It will not be defined until this callback is invoked.
});
Aparte, tenga en cuenta que su código actual no usa MetaMask.
undefined
. Por cierto, en testrpc
la terminal recibo eth_getBlockByNumber
uno tras otro, ¿puede ser un problema? Graciaserr
.err
es Error: Method personal_sign not supported
_ ¿por qué? Graciastestrpc
no es compatible con el método personal_sign
. Deberá usar geth, Parity, MetaMask u otra cosa que admita ese método.MetaMask
y después de ejecutar testrpc
me conecto MetaMask
a private network
(localhost 8545)
. pero sin ejecutar testrpc
no puedo conectarme para localhost 8545
usar MetaMask
. Como puedó resolver esté problema ? gracias de nuevotestrpc
. Y sí, por supuesto, debe ejecutar testrpc
MetaMask para poder conectarse a él.HttpProvider("http://localhost:8545"))
con algo más MetaMast web3 proviver
? Si es así, ¿podría indicarme en qué se MetaMast provider
debe insertar HttpProvider(" ? "))
? GraciastestRPC
recibo el mensaje de error anterior y si no estoy conectado, testRPC
recibo este error: web3.js:4386 OPTIONS http://localhost:8545/ 0 ()
lo que significa que no estoy conectado a MetaMast provider
. Estoy realmente confundido ..... Graciastestrpc
: ibb.co/dFRQpJ ¿Finalmente no entendí que necesito ejecutar testrpc
este javascript
código o no? Graciaspersonal_sign not supported
y cuando lo detengo, recibo otro error: aquí hay una captura de pantalla del error cuando testrpc
NO se está ejecutando: ibb.co/dFRQpJ . Entonces, en ambos casos recibo un error. tal vez la prueba Ropsten
sería mejor ... no lo sé. Por favor revisa mi nuevo código, ya que lo modifiqué. Graciastestrpc
. (2) haga clic en el icono de MetaMask y seleccione localhost 8545
(3) seleccione uno de los private keys
generados por testrpc
(4) seleccione import account
de MetaMask y péguelo private key
en Paste your private key string here
(5) ahora el saldo de esta dirección es 100 eth
(6) pegue esta address
(clave pública) en web3.personal.sign ...
(7) abriendo html
archivo al Google Chrome
(8) recibir este mensaje: No web3? You should consider trying MetaMask!
& Error: Method personal_sign not supported
.captura de pantalla: ibb.co/i93oRy .Thxhttps://mainnet.infura.io/<APIKEY>
. ¿El problema está relacionado con ejecutar mi página localmente? (Según esta respuesta) Gracias.web3
, así que lo fue undefined
). Si está ejecutando su página desde una file://
URL, entonces sí, este es el problema. Debe ejecutarse desde una URL http://
o https://
. La ejecución local está bien, pero debe ser a través de un servidor web, no del sistema de archivos.Parity
para conectarse a ej. Ropsten
y luego use web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
en la parte superior del JavaScript
código y ejecute este JS
archivo usando node filename.js
? ¿Hay alguna forma mejor? Graciashttp://
URL. Cualquier servidor web servirá.
shawn tabrizi
Preguntador
shawn tabrizi
web3.min.js
archivo a menos que desee ver el código fuente. Ver Minificación (programación)Preguntador
smarx
necesito agregarMetaMast web3 provider
el código. ¿Significa que necesito reemplazarHttpProvider("http://localhost:8545"))
por otra cosa? Graciasshawn tabrizi
window.web3 = new Web3(web3.currentProvider);
Mira mi respuesta a tu otra pregunta.Preguntador
MetaMask
código de muestra: github.com/MetaMask/faq/blob/master/DEVELOPERS.md Sin embargo, si estoy conectado,testrpc
recibo el mismo error, es decir,Method personal_sign not supported
porquetestrpc
no es compatible y si soy NO conectado atestrpc
Recibo este error: ` localhost: 8545 0 ()` (captura de pantalla: ibb.co/dFRQpJ ) GraciasCody Django
1.0.0-beta.38
,web3.eth.personal.sign
ya no acepta unundefined
valor para el tercer argumento (contraseña de la cuenta).