5

This question already has an answer here:

I'm currently developing an application on top of Ethereum's JSON RPC. I would like to be able to unlock and lock the wallet as needed, similar to how Bitcoin does it. However, it seems that at the moment it's only possible to unlock a geth wallet with the console through personal.unlockAccount. I'm wondering - is that the only way to unlock a geth wallet, or is there some way to do it through some other means, ideally with JSON RPC?

marked as duplicate by soc1c Aug 16 '16 at 14:10

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

7

It is safer to use the Go Ethereum - Management APIs - personal_sendTransaction API to unlock your account AND send your transaction at the same time:

personal_sendTransaction

Validate the given passphrase and submit transaction.

The transaction is the same argument as for eth_sendTransaction and contains the from address. If the passphrase can be used to decrypt the private key belogging to tx.from the transaction is verified, signed and send onto the network. The account is not unlocked globally in the node and cannot be used in other RPC calls.

Client    Method invocation
Console   personal.signAndSendTransaction(tx, passphrase)
RPC       {"method": "personal_sendTransaction", "params": [tx, string]}

Note, prior to Geth 1.5, please use personal_signAndSendTransaction as that was the original introductory name and only later renamed to the current final version.

Examples

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

Your account is only unlocked for the specified transaction.

You will have to enable the personal API over the RPC interface using the geth API option:

geth --rpc --rpcapi "eth,net,web3,personal" [other option] console


You may want to read the following links about the safety of allowing the personal API over RPC:



Update 21/07/2016 - Responding to comment below

I searched the geth github repository for personal_sendTransaction and could not find the text. I however found internal/web3ext/web3ext.go#L435-L440:

new web3._extend.Method({
    name: 'signAndSendTransaction',
    call: 'personal_signAndSendTransaction',
    params: 2,
    inputFormatter: [web3._extend.formatters.inputTransactionFormatter, null]
})

Like you said, the documentation seems outdated.

  • Hmm, I tried your method and it didn't work - I got an error of The method personal_sendTransaction does not exist/is not available. However, I did manage to use personal_listAccounts and personal_unlockAccount - I'm not entirely sure what would cause those to work, but not the sendTransaction... – ThePiachu Jul 21 '16 at 12:28
  • Hmm, it looks like personal_signAndSendTransaction is working - the Maangement APIs document seems to be outdated... – ThePiachu Jul 21 '16 at 12:33
  • 1
    Just use the sendRawTransaction api call – Matt Jul 25 '16 at 8:54
2

Yes, using the "personal_unlockAccount" API call

{
    'jsonrpc':'2.0',
    'method':'personal_unlockAccount',
    'params':[address, password, seconds],
    'id':1
};

Not the answer you're looking for? Browse other questions tagged or ask your own question.