Learn how to import exported zerocoins from a wallet that you are retiring in favor of a fresh new wallet. No need for spending and reminting. Export them and import them. Instantly stake on the new wallet.
I made a video some time ago demonstrating (on testnet) how to replace a wallet.dat that has grown to hundreds of megabytes due to heavy use over a year or more. The ability to do this without spending and then reminting all of the zerocoins is built in to the Veil wallet. This allows you to continue staking the already matured zerocoins.
Key Steps from the Tutorial
The process uses command-line interface (CLI) commands in the Veil wallet. It's recommended to practice on testnet first, as exported zerocoin data is sensitive (treat it like private keys). On mainnet, verify balances after each step.
- Export Zerocoins (normally you should do this in Terminal rather than the Debug Console):
- Run the command: exportzerocoins false
(the false ensures that only valid, unspent zerocoins are exported). - Redirect the output to a JSON file, e.g., > zerocoins.json
(add a date or identifier to the filename for organisation). - The file will contain sensitive data, so store it securely.
(Exported zerocoins can be imported into any wallet and spent, so treat the exported file like you would a file containing private keys. However, private keys hold permanent power over an address, while exported zerocoins can only be spent or staked once. so after staking, the originally exported zerocoins no longer exist.)
- Run the command: exportzerocoins false
- Prepare the Exported Data (in a programmer's text editor):
- Ensure that the square brackets are the first and last characters in the file, ... no leading or trailing spaces.
- If the JSON file is longer than 2000 lines split it into smaller parts. The split will always be on the 1,993rd line as you can't split in the middle of a zerocoin's data. Maybe you can use a script like json_split in Python 3 for this, but I always use a text editor (BBEdit on macOS) to remove all whitespace, including line breaks, creating a single continuous line of JSON data.
- Hopefully your text editor (if a proper programmer's text editor) will have a simple way to do this, as BBEdit allows me simply to use Find and Replace with Regex (regular expressions) turned on, replacing "\s" with nothing.
- Import Zerocoins into the New Wallet (using the Terminal or Command Line):
- If using the GUI Qt wallet (veil-qt) ensure the new wallet is running in server mode (add server=1 to your veil.conf file) to accept CLI commands. Of course you would have needed that for the old wallet in order to do it in the Terminal, because the Debug Console would likely not be able to handle the size of the export, unless just a small number of zerocoins.
- Paste the data carefully, no extra spaces or quotes. Repeat for each split file if needed.
- For testnet, use: "./veil-cli -testnet importzerocoins '...'", where the ... is where you paste the data you've copied out of the exported zerocoins files. For mainnet, do the same, but without " -testnet".
- Verify the Import:
- The importzerocoins command will confirm the number and value of the zerocoins imported, but just in case you've included the same zerocoins more than once, verify that the balance has increased by the full amount of the old wallet's balance. (Recheck balances after each import).
- Use getbalances and/or listzerocoinamounts to confirm the zerocoins and their values.
- Imported zerocoins won't show in listtransactions since they're directly injected, not blockchain-transferred.
Important Notes and Warnings
- This is ideal for migrating after long-term wallet use to avoid bloat from thousands of staking wins or spending thousands of ten denomination zerocoins, in the process of converting rewards into larger zerocoin denominations.
- Do not export spent zerocoins, as they don't exist anymore, can't be spent or staked again (zerocoins that win a stake are always replaced with a fresh zerocoin with zero transaction history), and including them would create a ridiculously large export file from which only a small percentage would be valid.
- On mainnet, handle data with care, as you risk of loss if someone copies and imports your file of currently valid zerocoins. On testnet it is also a good idea to not build any bad (or insecure) habits.