Hello everyone. We were able to get address status using csharp2nem project. We are having a hard time sending mosaic from one address to another. Please help. Thanks
What issue are you having? (sorry, i only just saw this)
We are having problem sending mosaic…we find a sample c# code in cshart2nem but when we tried, it did not update the balance of the mosaic. (https://github.com/NemProject/csharp2nem/blob/master/NemApi/Wrapper/RequestClients/TransactionClient.cs) can you lead me to sample code in c# that can transfer mosaic. thanks.
This is the sample code we did.
// To get mosaic information of the account from the address.
var mosaicClient = new NamespaceMosaicClient(connection);
var mosaicResult = mosaicClient.BeginGetMosaicsOwned(Address);
var mosaicResponse = mosaicClient.EndGetMosaicsOwned(mosaicResult);
foreach(var data in mosaicResponse.Data)
{
// XEM is mosaic, but it does not shown because it has already been shown on the above.
if (data.MosaicId.Name != "xem")
{
Mosaics.Add(new Mosaic
{
Name = data.MosaicId.Name,
Amount = data.Quantity.ToString("N6")
});
MosaicList.Add(new CSharp2nem.Model.Transfer.Mosaics.Mosaic(data.MosaicId.NamespaceId,data.MosaicId.Name,240000));
Debug.WriteLine(data.MosaicId.NamespaceId);
}
}
//transfer transaction
var accountFactory = new PrivateKeyAccountClientFactory(connection);
var accClient = accountFactory.FromPrivateKey("7921112a8aea456fad3b260b97fa61aa77a9df362dfacec2e748ae8977ea5d7d");
var transData = new TransferTransactionData()
{
Message = " ",
RecipientAddress = "TDRQ6B5K6434DU3QURHZP4PSIIN4LOP7G5O4T73G",
ListOfMosaics = MosaicList
};
var transResult = accClient.BeginSendTransaction(transData);
var response = accClient.EndTransaction(transResult);
}
catch(Exception ex)
{
}
i dont see anything wrong at first look. Perhaps try using Fiddler (https://www.telerik.com/download/fiddler) to see if the Http request is actually going through, and if so, if any errors are picked up.
if it helps, you can try adapting your code to the following:
class TestClass
{
static void Main()
{
Connection connection = new Connection();
connection.SetTestnet();
var accountFactory = new PrivateKeyAccountClientFactory(connection);
PrivateKeyAccountClient accClient = accountFactory.FromPrivateKey("<key>");
var mosaicsList = new List<Mosaic>()
{
new Mosaic("<namespaceName>", "<mosaicName>", 100000)
};
var transData = new TransferTransactionData()
{
Amount = 1000000, // amount should always be 1000000 micro xem when attaching mosaics as it acts as a multiplier.
Message = "message here if needed",
RecipientAddress = "<address>",
ListOfMosaics = mosaicsList
};
try
{
accClient.BeginSendTransaction(body =>
{
try
{
if (body.Ex != null) throw body.Ex;
Console.WriteLine("message: " + body.Content.Message);
}
catch (Exception e)
{
Console.WriteLine("error: " + e.Message);
}
}, transData);
}
catch (Exception ex)
{
Console.WriteLine("error: " + ex.Message);
}
}
}
this just worked for me bar the mosaic not being known.
thanks…will try…