[C#] 手把手來玩狗狗幣 (Dogecoin) - 製作 還原 狗狗幣錢包
2021-05-24
最近幣價再度跳水大跌 (2021- 519 事件),正好就把之前研究的一些東西開始整理一下順便寫寫 Blog 筆記一下研究的東西..
今天我們要來講講如何建立一個 DogeCoin 錢包,並且還原..
Step 1. 首先,安裝一個 nuget 套件 https://www.nuget.org/packages/NBitcoin/
Step2 . 再來就是建立錢包的程式碼了,這邊我使用的是 Testnet ,當你的使用場景不是測試鏈 ,記得要切換成 NBitcoin.Altcoins.Dogecoin.Instance.Mainnet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Key1 = new NBitcoin.Key(); | |
//正式鏈的錢包 | |
//var dogePrivateKey = Key1.GetWif(NBitcoin.Altcoins.Dogecoin.Instance.Mainnet); | |
var dogePrivateKey = Key1.GetWif(NBitcoin.Altcoins.Dogecoin.Instance.Testnet); | |
NBitcoin.BitcoinEncryptedSecret encryptedDogePrivateKey = dogePrivateKey.Encrypt("your_pass_word"); | |
DisplayData.Add("Your Address : " + dogePrivateKey.GetAddress(NBitcoin.ScriptPubKeyType.Legacy)); | |
DisplayData.Add("Encrypted PrivateKey : " + encryptedDogePrivateKey.ToWif()); | |
//result: | |
//Your Address : njrpt4uw8ApfaHVwwxWWPigqTx5XxN7axV | |
//Encrypted PrivateKey : 6PYWL2rmPS35z5LsYijsoD4gcHr6XVtQvkAkeV3oYbPCRG86snGN1ffLs3 | |
產出結果:
Your Address :
njrpt4uw8ApfaHVwwxWWPigqTx5XxN7axV
Encrypted PrivateKey :
6PYWL2rmPS35z5LsYijsoD4gcHr6XVtQvkAkeV3oYbPCRG86snGN1ffLs3
你可以透過這網站查看你產出的 Testnet 的錢包交易
https://chain.so/address/DOGETEST/njrpt4uw8ApfaHVwwxWWPigqTx5XxN7axV
Step3. 還原錢包,第二步 我們拿到了 PrivateKey 是 6PYWL2rmPS35z5LsYijsoD4gcHr6XVtQvkAkeV3oYbPCRG86snGN1ffLs3 ,這時候我們要來還原錢包
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var restoreWallet = NBitcoin.Key. | |
Parse("6PYWL2rmPS35z5LsYijsoD4gcHr6XVtQvkAkeV3oYbPCRG86snGN1ffLs3", "your_pass_word", NBitcoin.Altcoins.Dogecoin.Instance.Testnet).GetWif(NBitcoin.Altcoins.Dogecoin.Instance.Testnet); | |
DisplayData.Add("Your Restore Address : " + restoreWallet.GetAddress(NBitcoin.ScriptPubKeyType.Legacy)); | |
大概就是這樣,有沒有很簡單,網路上對於 DogeCoin 的 C# 開發文件相對少,我有測出來就記錄一下..
對了測試鏈的水龍頭 我記錄一下,如果有需要可以領一點,之後測試交易可以用到
https://doge-faucet-testnet.ggcorp.fr/