2

I know I can get the public key from cleos for a given account but is the reverse possible? Basically, I am trying to find all the account names associated with a public key.

2 Answers 2

2

Yes, it's possible, you can just retrieve all the accounts for a given public key running the command cleos get accounts EOS_PUB_KEY

Another way to check the accounts for a public key, from an external application, is using the EOS RPC Api, check this out: https://developers.eos.io/eosio-nodeos/reference#get_key_accounts-1

4
  • I was using get account instead of get accounts :)
    – Kabir
    Commented Jun 27, 2018 at 2:24
  • Is there a public domain I can use instead of 127.0.0.1 for xhr.open("POST", "127.0.0.1:8888/v1/history/get_key_accounts"); ? Commented Dec 13, 2018 at 18:45
  • I don't see a function to get all accounts but one could do: keys=`cleos wallet keys | grep -v "[]\[]" | cut -f 2 -d "\""`; for i in $keys; do cleos get accounts $i; done
    – colin
    Commented Jan 14, 2019 at 4:49
  • this was working only with a now deprecated plugin for the node (history plugin)
    – colin
    Commented May 13, 2019 at 3:47
0

I implemented it using history_get_key_accounts. The history_get_key_accounts api calls to /v1/history/get_key_accounts.

Please reference the following code.

const { Api, JsonRpc } = require('eosjs');
const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args));

const rpc = new JsonRpc('http://localhost:8888', { fetch });
const accounts = await rpc.history_get_key_accounts(public_key);

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.