private static void ReturnAsset(string address, long amount, string hash) { try { // create mosaic to be sent var mosaicsToSend = new List <Mosaic>() { new Mosaic(MosaicToReturn.Id.NamespaceId, MosaicToReturn.Id.Name, RoundUp(amount, 6 - int.Parse(MosaicToReturn.Properties[0].Value))) }; Console.WriteLine("address to send to: \n" + address); // initialize transaction data var transferData = new TransferTransactionData() { Amount = 0, // no xem to be sent but is still required. Message = hash, // include the hash of the deposit transaction for tracability ListOfMosaics = mosaicsToSend, // include list of mosaics to send, in this case just one but needs to be a list. Recipient = new AccountFactory(Con).FromEncodedAddress(address) // recipient of the transaction }; // send the transaction var result = SecretAccount.SendTransactionAsync(transferData).Result; // print out result Console.WriteLine(result.Message); Console.WriteLine(); } catch (Exception e) { Console.WriteLine(e); } }
public String Transaction(Models.TransferData data) { String message = ""; List <CSharp2nem.Model.Transfer.Mosaics.Mosaic> MosaicList = new List <CSharp2nem.Model.Transfer.Mosaics.Mosaic>(); var connection = new Connection(); connection.SetTestnet(); var mosaicClient = new NamespaceMosaicClient(connection); var mosaicResult = mosaicClient.BeginGetMosaicsOwned(data.Sender); var mosaicResponse = mosaicClient.EndGetMosaicsOwned(mosaicResult); foreach (var mosaic in mosaicResponse.Data) { if (mosaic.MosaicId.Name == "tfc") { MosaicList.Add(new CSharp2nem.Model.Transfer.Mosaics.Mosaic(mosaic.MosaicId.NamespaceId, mosaic.MosaicId.Name, (data.Amount * 10000))); } } var accountFactory = new PrivateKeyAccountClientFactory(connection); var accClient = accountFactory.FromPrivateKey(data.SenderPrivateKey); var transData = new TransferTransactionData() { Amount = 1000000, // amount should always be 1000000 micro xem when attaching mosaics as it acts as a multiplier. RecipientAddress = data.Receiver, ListOfMosaics = MosaicList }; try { accClient.BeginSendTransaction(body => { try { if (body.Ex != null) { throw body.Ex; } message = body.Content.Message; Debug.WriteLine(message); } catch (Exception e) { message = e.Message; } }, transData); } catch (Exception e) { message = e.Message; } Thread.Sleep(5000); //to make sure the message variable gets the content message before terminating return(message); }
internal TransferTransaction(Connectivity.Connection connection, PublicKey senderPublicKey, PrivateKey senderPrivateKey, TransferTransactionData transactionData) : base(connection, transactionData.MultisigAccountKey ?? senderPublicKey, transactionData.Deadline) { SenderPublicKey = senderPublicKey; SenderPrivateKey = senderPrivateKey; Data = transactionData; Con = connection; Recipient = Data.RecipientAddress; SerializeTransferPart(); finalize(); AppendMultisig(); }
public bool Send(string address, string message, Mosaic mosaic, long amount) { try { var accountFactory = new PrivateKeyAccountClientFactory(connection); var accountClient = accountFactory.FromPrivateKey(PrivateKey); TransferTransactionData transData; if (mosaic.MosaicName == "xem") { transData = new TransferTransactionData() { Amount = amount, Message = message, RecipientAddress = address, }; } else { mosaic.Quantity = amount; transData = new TransferTransactionData() { Amount = 1000000, Message = message, RecipientAddress = address, ListOfMosaics = new List <Mosaic>() { mosaic }, }; } var accountResult = accountClient.BeginSendTransaction(transData); while (!accountResult.IsCompleted) { ; } return(accountClient.EndTransaction(accountResult).Message == "SUCCESS"); } catch (Exception ex) { return(false); } }