5

Is there any API available to check whether an account is locked/unlocked in geth ? If i try to unlock an account that is already in unlocked state, does geth look out for the cached decrypted key , instead of decrypting each time ?

Also what if there are concurrent requests for unlocking of the same account (which is initially locked) ? Can this result in out of Memory error ?

1
  • did you find the answer?
    – tatigo
    Nov 8 '17 at 21:04
6

At the geth console (invoked by geth attach), run personal.listWallets to see a list of wallets and their statuses:


[{
    accounts: [{
        address: "0xae9c2ed2209d2228c131cc99569233a5d506770b",
        url: "..."
    }],
    status: "Unlocked",
    url: "..."
}]

You're interested in the wallet status field which can be either "Locked" or "Unlocked".

2
  • 1
    web3.personal does not provide listWallets under nodejs @aupiff
    – alper
    Mar 13 '18 at 22:20
  • 1
    I was talking about the geth console in my response. geth console commands are not identical to those defined in the web3.js library.
    – aupiff
    Apr 2 '18 at 20:24
0

web3.geth.personal.list_wallets().

Delegates to personal_listWallets RPC Method

Returns the list of wallets managed by Geth.

>>> web3.geth.personal.list_wallets()
[{
    accounts: [{
        address: "0x44f705f3c31017856777f2931c2f09f240dd800b",
        url: "keystore:///path/to/keystore/UTC--2020-03-30T23-24-43.133883000Z--44f705f3c31017856777f2931c2f09f240dd800b"
    }],
    status: "Unlocked",
    url: "keystore:///path/to/keystore/UTC--2020-03-30T23-24-43.133883000Z--44f705f3c31017856777f2931c2f09f240dd800b"
}]
0

If you want to get the same result from inside node.js or the browser use this. Im using the personal_listWallets JSON-RPC method in a waitable promise'ify function. Just call listWallets().then();

async function listWallets() {
    try {
        const result = await sendRPC_personal_listWallets();
        return result;
    } catch (e) {
        return e;
    }
}

function sendRPC_personal_listWallets() {

    return new Promise((resolve, reject) => {

        web3.currentProvider.send({ method: "personal_listWallets", params: [], jsonrpc: "2.0", id: new Date().getTime() },
            function (error, result) { if (error) { reject(error); } else { resolve(result); } });
    }
    );
}

let wallets;
listWallets().then((r) => { console.log("ID:", r.id); wallets = r.result; console.log("Accounts:", wallets); }); 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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