简体   繁体   English

如何直接在 C# 中创建以太坊钱包

[英]How do you Create an Ethereum wallet in C# directly

I have exhausted a number of sources to try and find this answer but simply how do you create a wallet or integrate the Ethereum Blockchain in C#?我已经用尽了很多资源来尝试找到这个答案,但只是如何在 C# 中创建钱包或集成Ethereum Blockchain There are a number of technologies such as Web3.js , MyEtherWallet (also js) and Nethereum which is C# but uses Infura as the API call.有许多技术,例如Web3.jsMyEtherWallet (也是 js)和Nethereum ,它是 C# 但使用 Infura 作为 API 调用。 There is also a service called blockcypher.com还有一个名为blockcypher.com的服务

How do you Create an Ethereum wallet that is public to the transfer funds to from one wallet to another?您如何创建一个公开的以太坊钱包,以便将资金从一个钱包转移到另一个钱包? What is the endpoint?终点是什么?

What I am looking to do is programmatically create a wallet for each of my users using my web app and as they earn points I again want to programmatically move funds from my wallet to my user's wallet.我想要做的是以编程方式使用我的网络应用程序为我的每个用户创建一个钱包,当他们获得积分时,我再次想以编程方式将资金从我的钱包转移到我的用户的钱包。

Any advice would be appreciated任何意见,将不胜感激

Thanks in advance提前致谢

Here's an example using Nethereum:下面是一个使用 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 can be stored in a file. json可以存储在一个文件中。 Mist used this file format. Mist 使用了这种文件格式。

Try Nethereum you can use any rpc end point, not just Infura.试试 Nethereum,你可以使用任何 rpc 端点,而不仅仅是 Infura。 This is the same as Web3js, MyEtherWallet, Web3j, etc.这与 Web3js、MyEtherWallet、Web3j 等相同。

Obviously you will need to have a Node running like Geth, Parity or Besu.显然,您需要有一个像 Geth、Parity 或 Besu 这样运行的节点。

This is an example of transferring Ether in Nethereum's public test chain.这是在 Nethereum 的公共测试链中传输 Ether 的示例。

Also you can combine it with @LOST response to encrypt and decrypt your private key using the KeyStore standard.您也可以将它与@LOST 响应结合起来,以使用 KeyStore 标准加密和解密您的私钥。

You can run this sample in the Nethereum Playground http://playground.nethereum.com/csharp/id/1003 .您可以在 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");
    }
}

You have many samples of Ethereum wallets using Nethereum, they can be found here http://docs.nethereum.com/en/latest/nethereum-ui-wallets/你有很多使用 Nethereum 的以太坊钱包样本,它们可以在这里找到http://docs.nethereum.com/en/latest/nethereum-ui-wallets/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM