1

I have two geth nodes, each has an account:

node1(IP:192.168.43.12): account1
node2(IP:192.168.43.39): account2

the two accounts are created using geth --datadir /root/chain/node1/data account new, the keystore files are generated and saved on each node.

I use web3 to attach node1 in nodejs environment:

const Web3 = require('web3');
const web3 = new Web3('http://192.168.43.12:8545');

and try to unlock account2 created on node2 before sending a token transaction like below:

await web3.eth.personal.unlockAccount(account2, "account2 password", 1000);

I got an error like below:

Error: Node error: {"code":-32000,"message":"no key for given address or file"}

I also tried if attach to node2 and the unlock process is correct.

const Web3 = require('web3');
const web3 = new Web3('http://192.168.43.39:8545');
await web3.eth.personal.unlockAccount(account2, "account2 password", 1000);

How can I unlock an account use web3 without the limitation of node connection?

Thanks.

4
  • did you test your code locally with ganache and checked if its working? since from the code posted i can see you are using a node on a remote server.
    – wandos
    Jun 12, 2019 at 14:41
  • the code can work as I said in the post. the problem is how to unlock any account created in node1 when attaching node2 using web3 lib. If I have already known the private key, how to make web3 object aware of it. In this way, I should not need to call "we3.eth.personal.unlockAccount()"?
    – user53451
    Jun 13, 2019 at 1:42
  • I want to unlock an account created on remote node. the account's keystore file is also saved in that node.
    – user53451
    Jun 13, 2019 at 2:11
  • you will need to connect to that node directly by setting the web3 provider and then unlock your account.
    – wandos
    Jun 13, 2019 at 5:06

1 Answer 1

0

The account files are located in /root/chain/node1/data/keystore folder (in your case), so you need to copy both keys to both nodes, because the accounts are local per node

2
  • Can I specify the path of keystore file when unlock account using web3.eth.personal.unlockAccount(account, "account password", unlocktime)? if possible, then I can put keystore file on other computer instead of /root/chain/node1/data/keystore folder
    – user53451
    Jun 12, 2019 at 8:31
  • The key files are local per node, so you just need to copy the files from the other comuter
    – KNK
    Jun 13, 2019 at 9:35

Your Answer

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