【问题标题】:Nethereum EthECKey not working. Scripts are not compiledNethereum EthECKey 不工作。脚本未编译
【发布时间】:2021-12-27 11:34:01
【问题描述】:

如果我将此行添加到我的代码中,那么它会拒绝编译!(这发生在所有统一的脚本,甚至是空的脚本)

string publicKey = Nethereum.Signer.EthECKey.GetPublicAddress(privatekey);

代码:

using System.Collections;
using System;
using System.Collections.Generic;
using Nethereum.Util;
using UnityEngine;
using System.Threading.Tasks;
using Nethereum.Hex.HexConvertors.Extensions;
using Org.BouncyCastle.Crypto.Digests;
using System.Linq;
using System.Text;
using Nethereum.Util.Keccak;
using System.Numerics;
using System.Runtime.CompilerServices;
using Nethereum.RLP;
using Nethereum.Signer.Crypto;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Agreement;
using Org.BouncyCastle.Crypto.Generators;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Security;
using Org.BouncyCastle.Utilities;
public class MianScript : MonoBehaviour
{
    string chain = "ethereum";
    string network = "rinkeby";
    [SerializeField]
    public string password;
    public void OnClickBTN()
    {

        string privatekey = CreateAccount();
        string publicKey = Nethereum.Signer.EthECKey.GetPublicAddress(privatekey);
        Debug.Log("\nPrivate: " + privatekey + "\nPublicKey: " + publicKey);
    }


    public byte[] CalculateHash(byte[] value)
    {
        var digest = new KeccakDigest(256);
        var output = new byte[digest.GetDigestSize()];
        digest.BlockUpdate(value, 0, value.Length);
        digest.DoFinal(output, 0);
        return output;
    }
    public async Task<String> GetBalance(string chain1, string network1, string address1)
    {
        string balance = await EVM.BalanceOf(chain1, network1, address1);
        return balance;
    }
    public static string CreateAccount()
    {
        System.Random random = new System.Random();
        var bytes = new Byte[32];
        random.NextBytes(bytes);

        var hexArray = Array.ConvertAll(bytes, x => x.ToString("X2"));
        var hexStr = String.Concat(hexArray);
        return Convert.ToString(hexStr.ToLower());
    }
}

请帮忙!

【问题讨论】:

    标签: c# unity3d ethereum nethereum


    【解决方案1】:

    我也没有使用 unity,C# 但似乎 GetPublicAddress() 不是 静态函数,而是 类方法强>.

    所以我认为你需要这样做:

    // Creating an EthECKey instance
    var key = new Nethereum.Signer.EthECKey(privateKey.HexToByteArray(), true);
    
    // Getting the public Address
    string publicKey = key.GetPublicAddress();
    

    我只是检查了来自here 的示例。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-13
      • 1970-01-01
      • 2013-11-19
      • 1970-01-01
      • 2012-01-31
      相关资源
      最近更新 更多