0

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

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());
    }
}

请帮忙!

4

1 回答 1

0

我也没有使用统一,C#,但它似乎GetPublicAddress()不是静态函数而是类方法

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

// Creating an EthECKey instance
var key = new Nethereum.Signer.EthECKey(privateKey.HexToByteArray(), true);

// Getting the public Address
string publicKey = key.GetPublicAddress();

我只是从这里检查了示例。

于 2021-12-30T14:00:33.910 回答