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); }
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 _wallet.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]); }