{"id":16153683,"url":"https://github.com/moneroexamples/spendkey","last_synced_at":"2025-08-29T14:46:40.923Z","repository":{"id":70343748,"uuid":"46101497","full_name":"moneroexamples/spendkey","owner":"moneroexamples","description":"Recover Monero address using the private spend key","archived":false,"fork":false,"pushed_at":"2017-01-31T21:12:21.000Z","size":34,"stargazers_count":11,"open_issues_count":2,"forks_count":6,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-28T11:56:31.244Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/moneroexamples.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-11-13T05:14:33.000Z","updated_at":"2023-10-13T19:35:04.000Z","dependencies_parsed_at":"2023-03-04T22:15:41.365Z","dependency_job_id":null,"html_url":"https://github.com/moneroexamples/spendkey","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moneroexamples%2Fspendkey","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moneroexamples%2Fspendkey/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moneroexamples%2Fspendkey/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moneroexamples%2Fspendkey/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/moneroexamples","download_url":"https://codeload.github.com/moneroexamples/spendkey/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243945561,"owners_count":20372897,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-10T01:14:10.208Z","updated_at":"2025-08-29T14:46:40.885Z","avatar_url":"https://github.com/moneroexamples.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Recover Monero address using the private spend key\n\n[Monero](https://getmonero.org/) `simplewallet` has a command called `spendkey` which prints\nout your private spend key. However, its not clear what to do with this private key.\n\nIt turns out, that this private key is the hexadecimal representation of the 25 word\nmnemonic seed, which `simplewallet` gives you when you create a new wallet. For example, the following mnemonic seed:\n\n```\nvinegar talent sorry hybrid ultimate template nimbly jukebox axes inactive veered toenail pride plotting chrome victim agnostic science bailed paddles wounded peaches king laptop king\n```\n\ncorresponds to this private spend key:\n\n```\n6ee02ef8647856f4080882a1ec4fabee19ec047ca24d3abb13c0ce589a46f702\n```\n\nSince mnemonic seed allows you to restore deterministic `simplewallet` wallet address. The same thing can be done\nwith just the private spend key. This includes recovery of your private view key.\n\nMore on Monero's keys and addresses can be found on [Address Generation Tests](https://xmr.llcoins.net/) website.\n\n\n\n# Monero address\n\nMonero address is as a combination of public spend and view keys. The public keys\nare obtained directly from the corresponding private spend and view keys, respectively.\nThe private view key is obtained from the private spend key (in `simplewallet`),\nwhich in turn can be obtained from the mnemonic seed. This means that\nspend key is much more important than the view key, since it allows\n to recover your private view key (revers is not true). So what it means, is that you should not be disclosing your private spend key to strangers!\n\n\n\n Please note that this is not the only way of deriving private keys. For example, [MyMonero](https://mymonero.com/) is using a different procedure, which is not compatible with that in `simplewallet`. The procedure presented here is same as the one used in `simplewallet`. More on this is\n[here](https://xmr.llcoins.net/)\nand [here](https://en.reddit.com/r/Monero/comments/3s80l2/why_mymonero_key_derivation_is_different_than_for/).\n\n\n# Pre-requisites\n\nThe example was tested on Ubuntu 16.04 x64 and Monero 0.9.\n\nInstruction for Monero 0.9 compilation and setup of Monero's header files and libraries are at:\n - [Compile Monero 0.9 on Ubuntu 16.04](https://github.com/moneroexamples/compile-monero-09-on-ubuntu-16-04)\n\n# C++ code\nThe most interesting C++ file is `main.cpp`.\nTherefore, I will present only that file here. Full source code is\nat [github](https://github.com/moneroexamples/spendkey.git). The github's version can\nalso be slightly different than the code presented here, as it might be updated\nmore frequently.\nSo for the latest version\nof this example, please check the github repository directly.\n\n## main.cpp\nThis is the main file of the example. The program takes\ntwo input arguments:\n\n - `spendkey,s` - the private spend key.\n - `mnemonic,m` - 25 word mnemonic representation of the spend key.\n\n\n```c++\nint main(int ac, const char* av[]) {\n\n    // get command line options\n    xmreg::CmdLineOptions opts {ac, av};\n\n    // if help was chosen, display help text and finish\n    if (opts.help_requested())\n    {\n        return 0;\n    }\n\n    // default language for the mnemonic\n    // representation of the private spend key\n    string language {\"English\"};\n\n    // get private spend key options\n    auto spendkey_opt = opts.get_option\u003cstring\u003e(\"spendkey\");\n    auto mnemonic_opt = opts.get_option\u003cstring\u003e(\"mnemonic\");\n\n    // get the program command line options, or\n    // some default values for quick check\n    string spendkey_str = spendkey_opt ? *spendkey_opt : \"af6082af29108abda69cc385dfed2102b892a871695367cb22a4b9b6df8b3206\";\n    string mnemonic_str = mnemonic_opt ? *mnemonic_opt : \"spout midst duckling tepid odds glass enhanced avatar ocean rarest eavesdrop egotistic oxygen trying future airport session nanny tedious guru asylum superior cement cunning eavesdrop\";\n\n\n    crypto::secret_key private_spend_key;\n\n\n    if ((spendkey_opt \u0026\u0026 !mnemonic_opt) || (!spendkey_opt \u0026\u0026 !mnemonic_opt))\n    {\n        // if spend key is given or nothing is provided by the user,\n        // then derive the mnemonic using either key provided or the default one\n\n        if (spendkey_opt)\n        {\n            // use provided spend key by the user\n            spendkey_str = *spendkey_opt;\n        }\n\n        // parse string representing given private spend key\n        if (!xmreg::parse_str_secret_key(spendkey_str, private_spend_key))\n        {\n            cerr \u003c\u003c \"Cant parse the spend key: \" \u003c\u003c spendkey_str \u003c\u003c endl;\n            return 1;\n        }\n\n        // derive the mnemonic version of the spend key.\n        // 25 word mnemonic that is provided by the simplewallet\n        // is just a word representation of the private spend key\n        if (!bytes_to_words(private_spend_key, mnemonic_str, language))\n        {\n            cerr \u003c\u003c \"\\nCant create the mnemonic for the private spend key: \"\n                 \u003c\u003c private_spend_key \u003c\u003c endl;\n            return 1;\n        }\n    }\n    else if (!spendkey_opt \u0026\u0026 mnemonic_opt)\n    {\n        // if mnemonic is given, then derive the spend key\n        if (!words_to_bytes(*mnemonic_opt, private_spend_key, language))\n        {\n            cerr \u003c\u003c \"\\nCant create private spend key for the mnemonic: \"\n                 \u003c\u003c *mnemonic_opt \u003c\u003c endl;\n            return 1;\n        }\n    }\n\n\n    cout \u003c\u003c \"\\n\"\n         \u003c\u003c \"Mnemonic: \" \u003c\u003c mnemonic_str \u003c\u003c endl;\n\n    // the seed for generation of private view key later on\n    // is the private spend key.\n    cout \u003c\u003c \"\\n\"\n         \u003c\u003c \"Hexadecimal seed : \" \u003c\u003c private_spend_key \u003c\u003c endl;\n\n\n    cout \u003c\u003c \"\\n\"\n         \u003c\u003c \"Private spend key: \" \u003c\u003c private_spend_key \u003c\u003c endl;\n\n\n    // we have private_spend_key, so now\n    // we need to get the corresponding\n    // public_spend_key\n    crypto::public_key public_spend_key;\n\n\n    // generate public key based on the private key\n    crypto::secret_key_to_public_key(private_spend_key, public_spend_key);\n\n\n    cout \u003c\u003c \"Public spend key : \"  \u003c\u003c public_spend_key  \u003c\u003c endl;\n\n\n    // now its time to get the view keys.\n    // in monero's simplewallet, the private view key\n    // is generated using keccak hash of the private spend\n    // key. in other words, the hash of the private spend key\n    // is used for generating the private view key,\n    // and subsequently, its corresponding public view key.\n\n\n    crypto::hash hash_of_private_spend_key;\n\n    // calculate keccak hash of the private spend key\n    xmreg::keccak_hash(private_spend_key, hash_of_private_spend_key);\n\n\n    crypto::secret_key private_view_key;\n    crypto::public_key public_view_key;\n\n    // get the view keys using the hash_of_private_spend_key\n    // as the seed.\n    crypto::generate_keys(public_view_key, private_view_key,\n                          xmreg::get_key_from_hash\u003ccrypto::secret_key\u003e(hash_of_private_spend_key),\n                          true /* recover keys*/);\n\n\n    cout \u003c\u003c \"\\n\"\n         \u003c\u003c \"Private view key : \"  \u003c\u003c private_view_key \u003c\u003c \"\\n\"\n         \u003c\u003c \"Public view key  : \"  \u003c\u003c public_view_key  \u003c\u003c endl;\n\n\n    // once we have both private view and spend keys, we can get our\n    // address. Monero's address is a combination of the two\n    // public keys.\n    cryptonote::account_public_address address {public_spend_key, public_view_key};\n\n\n    cout \u003c\u003c \"\\n\"\n         \u003c\u003c \"Monero address   : \"  \u003c\u003c address \u003c\u003c endl;\n\n    cout \u003c\u003c \"\\n\"\n         \u003c\u003c \"End of program.\" \u003c\u003c endl;\n\n    return 0;\n}\n```\n\n# Output example 1\nExecuting the program as follows:\n\n```bash\n./spendkey\n```\n\nResults in the following output:\n\n```bash\nMnemonic: spout midst duckling tepid odds glass enhanced avatar ocean rarest eavesdrop egotistic oxygen trying future airport session nanny tedious guru asylum superior cement cunning eavesdropspout midst duckling tepid odds glass enhanced avatar ocean rarest eavesdrop egotistic oxygen trying future airport session nanny tedious guru asylum superior cement cunning eavesdrop\n\nHexadecimal seed : \u003caf6082af29108abda69cc385dfed2102b892a871695367cb22a4b9b6df8b3206\u003e\n\nPrivate spend key: \u003caf6082af29108abda69cc385dfed2102b892a871695367cb22a4b9b6df8b3206\u003e\nPublic spend key : \u003c7aff30fbdc005ecb03f57a11e250e0d665621ffde1d44c6aa84a8212cc0d1236\u003e\n\nPrivate view key : \u003c157874dc4e2961c872f87aaf4346146d0f596e2f116a51fbac01b693a8e3020a\u003e\nPublic view key  : \u003c25c1b6920540fbcfcb0e36bd2c88f5c1e62e5ef1d621279e7230b47648e64a63\u003e\n\nMonero address   : \u003c46HSxE7KoiDaxWFWR1wmJfcrunNj4TLiPJqiCJkQn345A4JJzgBNhUvbkrYWJX4EVJZS4kJGfGj7CTW8GEUHsbEZCEupMt6\u003e\n```\nThese results agree with those obtained using\n [Address Generation Tests](https://xmr.llcoins.net/) website.\n\n# Output example 2\n\nExecuting the program as follows:\n\n```bash\n./spendkey -s 11830f8a232b7b0152a709340bb653357d2aa92985f83b6e0dcf7cb2bf11330d\n```\nResults in the following output:\n\n```bash\nMnemonic: spout midst duckling tepid odds glass enhanced avatar ocean rarest eavesdrop egotistic oxygen trying future airport session nanny tedious guru asylum superior cement cunning eavesdropsiblings together icing idols sovereign sprig suture aloof egotistic speedy diplomat impel wise glass long cafe perfect awakened ought enforce voted mime fight goggles egotistic\n\nHexadecimal seed : \u003c11830f8a232b7b0152a709340bb653357d2aa92985f83b6e0dcf7cb2bf11330d\u003e\n\nPrivate spend key: \u003c11830f8a232b7b0152a709340bb653357d2aa92985f83b6e0dcf7cb2bf11330d\u003e\nPublic spend key : \u003c269e626955fe97f3853d768e0ad02bf92d0a95a8c03704fd8a96d5ad6a38c42a\u003e\n\nPrivate view key : \u003c21e63fb10d4adad609a327395e42d737bbd772dce53d64d2733c4aacc69eb300\u003e\nPublic view key  : \u003cb4e0cf1d4c7c60b590081db50e877e7576a36fb2c257f5f94932222d23d34b36\u003e\n\nMonero address   : \u003c435zP7PmQwYhjTJu7AmU8SigKVMsY9j3yjQfnwnfjRZM89Jp2ZxEpsyXNPKkr5hfwBLeYTiZeqfaLihPNWWEzbgN77gqFHp\u003e\n```\n\nThese results also agree with those obtained using\n [Address Generation Tests](https://xmr.llcoins.net/) website.\n\n# Output example 3\nExecuting the program as follows:\n```bash\n./spendkey -m \"essential future brunt cajun upper ammo incur smelting usual tyrant tattoo virtual long hectare idols guarded blender usage ghost sample eagle shelter does dozen usage\"\n\n```\nResults in the following output:\n\n```bash\nMnemonic: essential future brunt cajun upper ammo incur smelting usual tyrant tattoo virtual long hectare idols guarded blender usage ghost sample eagle shelter does dozen usage\n\nHexadecimal seed : \u003c0a0214cf7716292246d277214830411b20d3cd08cd119dcd9e149d7bd1151e02\u003e\n\nPrivate spend key: \u003c0a0214cf7716292246d277214830411b20d3cd08cd119dcd9e149d7bd1151e02\u003e\nPublic spend key : \u003c7e9f73449c1b3a9a83c25a641a95c8f74f7ccd309dd3fba5222ce349052af567\u003e\n\nPrivate view key : \u003cbd613fbad795df25b8218a7e4f80f4e3158db0646d1cb7d22d84f0b603a0f60b\u003e\nPublic view key  : \u003cfad7d278ee9fedf0034da1812115c5a369d6bd67e1b076afbc4aee579a609ce3\u003e\n\nMonero address   : \u003c46RRCV68frZSqzBsh9TWf9iNDrYhPkABUUd16zFLoPECJPjd3AtuTyeh9RhSWAqiCLULKGf9SC1UHWPra64ykRiTSg3RPmW\u003e\n```\n\nThese results also agree with those obtained using\n [Address Generation Tests](https://xmr.llcoins.net/) website.\n\n\n## Compile this example\nThe dependencies are same as those for Monero, so I assume Monero compiles\ncorrectly. If so then to download and compile this example, the following\nsteps can be executed:\n\n```bash\n# download the source code\ngit clone https://github.com/moneroexamples/spendkey.git\n\n# enter the downloaded sourced code folder\ncd spendkey\n\n# create the makefile\ncmake .\n\n# compile\nmake\n```\n\nAfter this, `spendkey` executable file should be present in spendkey\nfolder.\n\n## How can you help?\n\nConstructive criticism, code and website edits are always welcome. They can be made through github.\n\nSome Monero are also welcome:\n```\n48daf1rG3hE1Txapcsxh6WXNe9MLNKtu7W7tKTivtSoVLHErYzvdcpea2nSTgGkz66RFP4GKVAsTV14v6G3oddBTHfxP6tU\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoneroexamples%2Fspendkey","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmoneroexamples%2Fspendkey","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoneroexamples%2Fspendkey/lists"}