[英]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.