Ejemplo n.º 1
0
        public async Task TestTransferAsync()
        {
            var transactionClient = _record.ServiceProvider.GetService <ITransactionClient>();
            var walletClient      = _record.TronClient.GetWalletClient();
            var privateKey        = "8e812436a0e3323166e1f0e8ba79e19e217b2c4a53c970d4cca0cfb1078979df";
            var tronKey           = new TronECKey(privateKey, _record.Options.Value.Network);
            var from   = tronKey.GetPublicAddress();
            var to     = "TGehVcNhud84JDCGrNHKVz9jEAVKUpbuiv";
            var amount = 1_000_000L; // 1 TRX, api only receive trx in Sun, and 1 trx = 1000000 Sun

            var fromAddress = Base58Encoder.DecodeFromBase58Check(from);
            var toAddress   = Base58Encoder.DecodeFromBase58Check(to);

            var block = await walletClient.GetNowBlock2Async(new EmptyMessage());

            var transaction = await transactionClient.CreateTransactionAsync(from, to, amount);

            Assert.True(transaction.Result.Result);

            var transactionSigned = transactionClient.GetTransactionSign(transaction.Transaction, privateKey);

            var result = await transactionClient.BroadcastTransactionAsync(transactionSigned);

            Assert.True(result.Result);
        }
Ejemplo n.º 2
0
 public void Initialise(TronECKey key)
 {
     _key       = key;
     PrivateKey = key.GetPrivateKey();
     Address    = key.GetPublicAddress();
     PublicKey  = key.GetPubKey().ToHex();
 }
Ejemplo n.º 3
0
        public void TestPublicAddress()
        {
            var privateKey = "F43EBCC94E6C257EDBE559183D1A8778B2D5A08040902C0F0A77A3343A1D0EA5";

            var mainKey = new TronECKey(privateKey, TronNetwork.MainNet);

            Assert.Equal("TWVRXXN5tsggjUCDmqbJ4KxPdJKQiynaG6", mainKey.GetPublicAddress());
        }
Ejemplo n.º 4
0
        public async Task TestTransactionSignAsync()
        {
            var privateStr = "8e812436a0e3323166e1f0e8ba79e19e217b2c4a53c970d4cca0cfb1078979df";
            var tronKey    = new TronECKey(privateStr, _record.Options.Value.Network);
            var from       = tronKey.GetPublicAddress();
            var to         = "TGehVcNhud84JDCGrNHKVz9jEAVKUpbuiv";
            var amount     = 100_000_000L; // 100 TRX, api only receive trx in Sun, and 1 trx = 1000000 Sun

            var transactionExtension = await CreateTransactionAsync(from, to, amount);

            Assert.True(transactionExtension.Result.Result);

            var transaction = transactionExtension.Transaction;

            var transactionSignExtention = await _wallet.GetTransactionSign2Async(new TransactionSign
            {
                PrivateKey  = ByteString.CopyFrom(privateStr.HexToByteArray()),
                Transaction = transaction
            });

            Assert.NotNull(transactionSignExtention);

            Assert.True(transactionSignExtention.Result.Result);

            var transactionSigned = transactionSignExtention.Transaction;

            var transactionBytes = transaction.ToByteArray();

            var transaction4 = SignTransaction2Byte(transactionBytes, privateStr.HexToByteArray(), transactionSigned);


            var transaction5 = transactionSigned.ToByteArray();

            Assert.Equal(transaction4.ToHex(), transaction5.ToHex());

            var result = await _wallet.BroadcastTransactionAsync(transactionSigned);

            Assert.True(result.Result);
        }
Ejemplo n.º 5
0
        public async Task TestSignAsync()
        {
            var transactionClient = _record.ServiceProvider.GetService <ITransactionClient>();
            var privateKey        = "D95611A9AF2A2A45359106222ED1AFED48853D9A44DEFF8DC7913F5CBA727366";
            var ecKey             = new TronECKey(privateKey, _record.Options.Value.Network);
            var from   = ecKey.GetPublicAddress();
            var to     = "TGehVcNhud84JDCGrNHKVz9jEAVKUpbuiv";
            var amount = 100_000_000L;
            var result = await transactionClient.CreateTransactionAsync(from, to, amount);

            Assert.True(result.Result.Result);

            var transactionSigned = transactionClient.GetTransactionSign(result.Transaction, privateKey);

            var remoteTransactionSigned = await _record.TronClient.GetWalletClient().GetTransactionSign2Async(new Protocol.TransactionSign
            {
                Transaction = result.Transaction,
                PrivateKey  = ByteString.CopyFrom(privateKey.HexToByteArray()),
            });

            Assert.True(remoteTransactionSigned.Result.Result);

            Assert.Equal(remoteTransactionSigned.Transaction.Signature[0], transactionSigned.Signature[0]);
        }