[英]How do you Create an Ethereum wallet in C# directly
我已經用盡了很多資源來嘗試找到這個答案,但只是如何在 C# 中創建錢包或集成Ethereum Blockchain
? 有許多技術,例如Web3.js
、 MyEtherWallet
(也是 js)和Nethereum
,它是 C# 但使用 Infura 作為 API 調用。 還有一個名為blockcypher.com
的服務
您如何創建一個公開的以太坊錢包,以便將資金從一個錢包轉移到另一個錢包? 終點是什么?
我想要做的是以編程方式使用我的網絡應用程序為我的每個用戶創建一個錢包,當他們獲得積分時,我再次想以編程方式將資金從我的錢包轉移到我的用戶的錢包。
任何意見,將不勝感激
提前致謝
下面是一個使用 Nethereum 的例子:
string password = "MYSTRONGPASS";
EthECKey key = EthECKey.GenerateKey();
byte[] privateKey = key.GetPrivateKeyAsBytes();
string address = key.GetPublicAddress();
var keyStore = new KeyStoreScryptService();
string json = keyStore.EncryptAndGenerateKeyStoreAsJson(
password: password,
privateKey: privateKey,
addresss: address);
json
可以存儲在一個文件中。 Mist 使用了這種文件格式。
試試 Nethereum,你可以使用任何 rpc 端點,而不僅僅是 Infura。 這與 Web3js、MyEtherWallet、Web3j 等相同。
顯然,您需要有一個像 Geth、Parity 或 Besu 這樣運行的節點。
這是在 Nethereum 的公共測試鏈中傳輸 Ether 的示例。
您也可以將它與@LOST 響應結合起來,以使用 KeyStore 標准加密和解密您的私鑰。
您可以在 Nethereum Playground http://playground.nethereum.com/csharp/id/1003中運行此示例。
using System;
using System.Text;
using Nethereum.Hex.HexConvertors.Extensions;
using System.Threading.Tasks;
using Nethereum.Web3;
using Nethereum.Web3.Accounts;
public class Program
{
private static async Task Main(string[] args)
{
//First let's create an account with our private key for the account address
var privateKey = "0x7580e7fb49df1c861f0050fae31c2224c6aba908e116b8da44ee8cd927b990b0";
var account = new Account(privateKey);
Console.WriteLine("Our account: " + account.Address);
//Now let's create an instance of Web3 using our account pointing to our nethereum testchain
var web3 = new Web3(account, "http://testchain.nethereum.com:8545");
// Check the balance of the account we are going to send the Ether
var balance = await web3.Eth.GetBalance.SendRequestAsync("0x13f022d72158410433cbd66f5dd8bf6d2d129924");
Console.WriteLine("Receiver account balance before sending Ether: " + balance.Value + " Wei");
Console.WriteLine("Receiver account balance before sending Ether: " + Web3.Convert.FromWei(balance.Value) +
" Ether");
// Lets transfer 1.11 Ether
var transaction = await web3.Eth.GetEtherTransferService()
.TransferEtherAndWaitForReceiptAsync("0x13f022d72158410433cbd66f5dd8bf6d2d129924", 1.11m);
balance = await web3.Eth.GetBalance.SendRequestAsync("0x13f022d72158410433cbd66f5dd8bf6d2d129924");
Console.WriteLine("Receiver account balance after sending Ether: " + balance.Value);
Console.WriteLine("Receiver account balance after sending Ether: " + Web3.Convert.FromWei(balance.Value) +
" Ether");
}
}
你有很多使用 Nethereum 的以太坊錢包樣本,它們可以在這里找到http://docs.nethereum.com/en/latest/nethereum-ui-wallets/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.