public void CreateTest() { //1B7229DC6A062904C0D2B9D9A5795D4E555F5D1FEBC4A37B63EEB0FF4BC82D60 Passw0rdTRON TYYgwqYU9U8PT19bVDYjJckGrEnJoQKGUX // hash tran 6e712f3c4a50945973b655fbcaa503369ec4977a294d697823070026ba539110 // test wallet 2E77481EA8344FF43D5301D55F500CA45A4FEE62AFCDEFF3E8D4F2A4465C8CB2 TMmjx5RbjDwS4JoqKgujbsoa617b7DwfJq //D8414F1EFEC490358FEF9C8F6AE3980BD7F4323E0D2F2DE0DB9D590935D12F72 // String privateStr = "D95611A9AF2A2A45359106222ED1AFED48853D9A44DEFF8DC7913F5CBA727366"; String privateKeyHex = "750EB0343C49C9958387737108FB41EB53B6FD1FC074700F30082A7F9D4CC823"; //тестовая сеть TLWY31TNNkqENXNcSctb2mqH1qvRdwbjFL // String privateKeyHex = "74767E0ACC92FF6ED8E6A8C6CDDD61E27AEF20ACA3EC3E6492098C8B96CA23DB"; String toAddressWalletHes = "TPwJS5eC5BPGyMGtYTHNhPTB89sUWjDSSu"; // String toAddressWalletHes = "TSSrETcLX7ZaWuXRF652R4AJhXDWRX6JuV"; KeyTriple keyTriple = new KeyTriple(privateKeyHex); byte[] fromAddressWallet = keyTriple.GetAddressWallet(TypeNet.Main); String base58AddressWallet = Base58.Encode(fromAddressWallet); long amount = 231L; //100 TRX, api only receive trx in drop, and 1 trx = 1000000 drop Wallet.WalletClient wallet = GetMainNetWalletClient; // byte[] hashTransaction = StringHelper.HexStringToByteArray("f5eea816a16b1907f8b5c6394e133f285001585ce07f657240701511436ba836"); // BytesMessage bytesMessage = new BytesMessage(); // bytesMessage.Value=ByteString.CopyFrom(hashTransaction); // Transaction transactionLoad = wallet.GetTransactionByIdAsync(bytesMessage).GetAwaiter().GetResult(); /* * TransferContract transferContract = TransferContract.Parser.ParseFrom(transactionLoad.RawData.Contract[0].Parameter.Value.ToByteArray()); * String ownerAddress = Base58Check.Base58CheckEncoding.Encode(transferContract.OwnerAddress.ToByteArray()); * String toAddress = Base58Check.Base58CheckEncoding.Encode(transferContract.ToAddress.ToByteArray()); * String ownerAddress64 = transferContract.OwnerAddress.ToBase64(); */ // string sign11 = Base64.ToBase64String(Sha256.Hash(transactionLoad.RawData.ToByteArray())); // NodeList nodeList = wallet.ListNodesAsync().GetAwaiter().GetResult(); Transaction transaction = createTransaction(wallet, fromAddressWallet, Base58.Decode(toAddressWalletHes), amount); byte[] transactionBytes = transaction.ToByteArray(); Transaction transaction1 = sign(transaction, keyTriple); //get byte transaction byte[] transaction2 = transaction1.ToByteArray(); Console.WriteLine("transaction2 ::::: " + Base58.Encode(transaction2)); //sign a transaction in byte format and return a Transaction object // Transaction transaction3 = Transaction.Parser.ParseFrom(signTransaction2Byte(transactionBytes, keyTriple.PrivateKey)); // Console.WriteLine("transaction3 ::::: " + Base58Check.Base58CheckEncoding.Encode(transaction3.ToByteArray())); // wallet.CreateTransactionAsync() Return result1 = wallet.BroadcastTransactionAsync(transaction1).GetAwaiter().GetResult(); // Return result3 = wallet.BroadcastTransactionAsync(transaction3).GetAwaiter().GetResult(); }
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); }
private void broadcast(Wallet.WalletClient wallet, Transaction transactionBytes) { Return result = wallet.BroadcastTransactionAsync(transactionBytes).GetAwaiter().GetResult(); }