4

I am working with https://github.com/ethereum/wiki/wiki/JSON-RPC api + curl .

And implementing custom api using this php library: https://github.com/Achse/geth-jsonrpc-php-client

below method is working fine for me for unlock before transaction:

$ curl -X POST --data '{"jsonrpc":"2.0","method":"personal_unlockAccount","params":["0x7642b...", "password", 3600],"id":67}' http://localhost:8545

But I want to unlock account using private key not by password. So is there any way to unlock account and do transaction using private key.

2
  • use a raw transaction instead
    – Badr Bellaj
    Commented Nov 4, 2017 at 23:31
  • @BadrBellaj can you please give example how can i use it with curl + json rpc Commented Nov 6, 2017 at 13:33

2 Answers 2

2
+50

you can generate a raw transaction as described here or use myetherwallet to get the signed raw transaction and then call

curl -X POST --data '{"jsonrpc":"2.0","method":"eth_sendRawTransaction","params":[{raw_transaction}],"id":1}'

// Result
{
  "id":1,
  "jsonrpc": "2.0",
  "result": "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331"
}

as explained here

besides as @yogesh has mentioned in his comment bellow Ethereumjs build for browser can be used to build the rawtransaction (in client side).

11
2

You don't need to unlock your account if you know your private key. The reason is that transactions are signed using your private key, and unlocking your account is needed to obtain your private key from your keyfile. So if you already know your private key, there is no need to unlock your account.

You can use myetherwallet.com or ethychat.io for making transactions using your private key.

If you want to make transactions using JSON-RPC and your private key, you would probably have to create a signed transaction and send this using eth_sendRawTransaction.

2
  • 2
    how can I signed transaction using private key Commented Nov 6, 2017 at 7:02
  • Isn't it that the private key is stored in an encrypted format, and the password is needed to decrypt it? So, even to sign the transaction, the password is needed, unless the OP has the unencrypted private key (which he did not specifically mention). Commented Nov 9, 2017 at 17:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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