在geth客户端通过console命令执行转账时抛出以下异常:

Error: could not decrypt key with given passphrase
    at web3.js:3104:20
    at web3.js:6191:15
    at web3.js:5004:36
    at <anonymous>:1:1

但是在在此之前已经进行了unlockaccount操作却是成功的。

> personal.unlockAccount(eth.accounts[2], "thepassword", 150000)
true

是什么原因导致的呢?这是因为使用personal.sendTransaction时,需要两个参数。如果像下面这样只传递一个参数是会出现上面的异常的:

personal.sendTransaction({from:eth.accounts[2], to: eth.accounts[1], value: 20000000})

如果换成另外一个两参数的方法转账,便不会出现上面的问题,同时也不用先解锁了。

> var tx = {from: "0x391694e7e0b0cce554cb130d723a9d27458f9298", to: "0xafa3f8684e54059998bc3a7b0d2b0da075154d66", value: web3.toWei(1.23, "ether")}
undefined
> personal.sendTransaction(tx, "passphrase")
0x8474441674cdd47b35b875fd1a530b800b51a5264b9975fb21129eeb8c18582f

注意,此处personal.sendTransaction的第二个参数为密码。如果像第一种方式不传递密码,personal.sendTransaction默认为密码是空,因此也就认为密码错误了。

而如果此时使用eth.sendTransaction方法进行转账,就不会出现上面的问题。

原文链接《personal.unlockaccount可以解锁但转账could not decrypt key with given passphrase



personal.unlockaccount可以解锁但转账could not decrypt key with given passphrase插图

关注公众号:程序新视界,一个让你软实力、硬技术同步提升的平台

除非注明,否则均为程序新视界原创文章,转载必须以链接形式标明本文链接

本文链接:http://choupangxia.com/2019/10/12/personal-unlockaccount%e5%8f%af%e4%bb%a5%e8%a7%a3%e9%94%81%e4%bd%86%e8%bd%ac%e8%b4%a6could-not-decrypt-key-with-given-passphrase/