docs_rpc_dumpprivkey - reddcoin-project/reddcoin GitHub Wiki
Reddcoin RPC Command: dumpprivkey
Overview
The dumpprivkey
RPC command exports the private key associated with a specific Reddcoin address from your wallet. This command is essential for wallet backup purposes, moving funds between wallets, or integrating with external applications that require direct access to private keys.
Primary use cases:
- Creating manual backups of specific addresses
- Exporting keys for cold storage solutions
- Migrating addresses to different wallet software
- Integration with third-party applications
- Paper wallet creation
⚠️ Security Warning
CRITICAL SECURITY NOTICE: Private keys provide complete control over the associated cryptocurrency funds. Anyone with access to a private key can spend all funds from that address.
- Never share private keys with untrusted parties
- Store exported keys securely using encryption
- Use secure, offline environments when handling private keys
- Delete temporary copies after secure storage
- Consider the security implications before exporting keys
Command Syntax
dumpprivkey "address"
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
address | string | Yes | The Reddcoin address for which to export the private key |
Return Value
Type | Description |
---|---|
string | The private key in Wallet Import Format (WIF) |
Example Usage
Command Line Interface (CLI)
# Export private key for a specific Reddcoin address
reddcoind dumpprivkey "RoKXkMJiYRGNtL5eCcJwCHJLzwFBhQqyK9"
# Using reddcoin-cli
reddcoin-cli dumpprivkey "RoKXkMJiYRGNtL5eCcJwCHJLzwFBhQqyK9"
JSON-RPC Format
{
"jsonrpc": "2.0",
"id": "dumpprivkey_example",
"method": "dumpprivkey",
"params": ["RoKXkMJiYRGNtL5eCcJwCHJLzwFBhQqyK9"]
}
cURL Example
curl -X POST \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": "dumpprivkey_request",
"method": "dumpprivkey",
"params": ["RoKXkMJiYRGNtL5eCcJwCHJLzwFBhQqyK9"]
}' \
http://127.0.0.1:45443/
Example Response
Successful Response
{
"result": "6KfM8rYJZ7sBzV4gF3hN2pX9wE5qT1mR8cL4dK7sA3bN9hG2fJ5pQ6wX",
"error": null,
"id": "dumpprivkey_example"
}
Error Response
{
"result": null,
"error": {
"code": -4,
"message": "Private key for address RoKXkMJiYRGNtL5eCcJwCHJLzwFBhQqyK9 is not known"
},
"id": "dumpprivkey_example"
}
Notes
Important Considerations
- Wallet must be unlocked: If your wallet is encrypted, you must unlock it using
walletpassphrase
before callingdumpprivkey
- Address must exist in wallet: The command only works for addresses that are already in your wallet
- WIF format: The returned private key is in Wallet Import Format, which can be imported into other compatible wallets
- Network compatibility: Ensure the private key is used on the correct network (mainnet vs testnet)
- Backup verification: Always verify that imported private keys work correctly in the destination wallet
Common Error Codes
- -4: Address not found in wallet
- -13: Wallet is locked (use
walletpassphrase
to unlock) - -14: Wallet encryption error
Related Commands
Complementary RPC Commands
importprivkey
- Import a private key into the walletlistaddresses
- List all addresses in the walletgetnewaddress
- Generate a new addresswalletpassphrase
- Unlock an encrypted walletdumpwallet
- Export all wallet keys to a filebackupwallet
- Create a backup of the entire walletvalidateaddress
- Verify address format and ownership
Workflow Examples
# Complete key export workflow
reddcoin-cli walletpassphrase "your_password" 300
reddcoin-cli dumpprivkey "RoKXkMJiYRGNtL5eCcJwCHJLzwFBhQqyK9"
reddcoin-cli walletlock
Python Implementation Example
import requests
import json
class ReddcoinRPC:
def __init__(self, host='127.0.0.1', port=45443, username='', password=''):
self.url = f"http://{host}:{port}/"
self.auth = (username, password) if username else None
self.headers = {'Content-Type': 'application/json'}
def call(self, method, params=None):
"""Make RPC call to Reddcoin daemon"""
payload = {
"jsonrpc": "2.0",
"id": "python_rpc",
"method": method,
"params": params or []
}
try:
response = requests.post(
self.url,
data=json.dumps(payload),
headers=self.headers,
auth=self.auth,
timeout=30
)
response.raise_for_status()
result = response.json()
if result.get('error'):
raise Exception(f"RPC Error: {result['error']}")
return result.get('result')
except requests.exceptions.RequestException as e:
raise Exception(f"Connection error: {e}")
def dump_private_key(self, address):
"""Export private key for specified address"""
return self.call('dumpprivkey', [address])
def unlock_wallet(self, passphrase, timeout=300):
"""Unlock encrypted wallet"""
return self.call('walletpassphrase', [passphrase, timeout])
def lock_wallet(self):
"""Lock wallet"""
return self.call('walletlock')
# Usage example
def export_private_key_safely(address, passphrase):
"""Safely export private key with proper wallet locking"""
rpc = ReddcoinRPC()
try:
# Unlock wallet
rpc.unlock_wallet(passphrase, 60) # 1 minute timeout
# Export private key
private_key = rpc.dump_private_key(address)
# Immediately lock wallet
rpc.lock_wallet()
return private_key
except Exception as e:
# Ensure wallet is locked even if error occurs
try:
rpc.lock_wallet()
except:
pass
raise e
# Example usage
if __name__ == "__main__":
address = "RoKXkMJiYRGNtL5eCcJwCHJLzwFBhQqyK9"
passphrase = "your_wallet_passphrase"
try:
private_key = export_private_key_safely(address, passphrase)
print(f"Private key for {address}: {private_key}")
# Immediately secure the private key
# (encrypt, store in secure location, etc.)
except Exception as e:
print(f"Error exporting private key: {e}")
Security Best Practices
Private Key Handling
-
Secure Environment
- Use offline or air-gapped systems when possible
- Ensure system is free from malware
- Use trusted, updated software
-
Storage Security
- Encrypt private keys before storage
- Use hardware security modules (HSMs) for high-value keys
- Create multiple encrypted backups in separate locations
- Consider paper wallet storage for long-term holdings
-
Access Control
- Limit access to authorized personnel only
- Use multi-signature schemes when possible
- Implement proper authentication mechanisms
- Maintain audit logs of key access
-
Operational Security
- Minimize time wallet remains unlocked
- Clear clipboard after copying private keys
- Use secure communication channels
- Regularly rotate encryption passwords
Code Security
# Example of secure private key handling
import os
import tempfile
from cryptography.fernet import Fernet
def secure_key_export(address, wallet_passphrase, encryption_key):
"""Export and immediately encrypt private key"""
rpc = ReddcoinRPC()
try:
# Unlock wallet briefly
rpc.unlock_wallet(wallet_passphrase, 30)
# Export private key
private_key = rpc.dump_private_key(address)
# Immediately encrypt
cipher = Fernet(encryption_key)
encrypted_key = cipher.encrypt(private_key.encode())
# Clear the plaintext key from memory
private_key = "0" * len(private_key)
del private_key
return encrypted_key
finally:
rpc.lock_wallet()
Additional Resources
Official Documentation
- Reddcoin Official Website
- Reddcoin GitHub Repository
- Bitcoin RPC API Reference (Similar commands)
Security Resources
Development Resources
Disclaimer: This documentation is for educational purposes. Always verify commands in a test environment before using with real funds. The authors are not responsible for any loss of funds due to improper use of these commands.