I'm using the C# SDK.

For Example, a new Asset is created.

_stellarAsset = Asset.CreateNonNativeAsset("credit_alphanum4", _assetIssuer, _assetCode);

This is in a method which returns the asset that was just created.

Now I need to access _stellarAsset.Asset or _stellarAsset.Code however, those properties only exist in the AssetResponse class. This might have an obvious answer but how can I get access to AssetResponse properties from the newly created Asset?

1 Answer 1


Asset.CreateNonNativeAsset is a simple factory method to create an Asset instance of the right subtype.


The values for code and issuer will be the same as the values you provided as parameters.

I suspect the reason you cannot access these values on the returned type is because the parent type Asset is returned. It is realised in subtypes by AssetTypeNative, AssetTypeCreditAlphaNum4 and AssetTypeCreditAlphaNum12. The first of these three do not have code and issuer values, so the parent type doesn't have it either. I'm not familiar with C#, but I suspect you would need to detect the subtype and cast it before you can access the fields.

From memory, this is the approach taken in Java SDK too.

As an aside, I chose to use a different hierarchy when building the Scala SDK in order to avoid type problems like you describe:

 + NativeAsset
 + NonNativeAsset(code, issuer)
   + IssuedAsset4
   + IssuedAsset12

Asset(code, issuer) only returns instances of NonNativeAsset. In this way you can always pattern match or directly access the fields:

@ Asset("FRUIT", KeyPair.random) match {
    case IssuedAsset4(code, issuer) => s"$code from ${issuer.accountId}"
    case IssuedAsset12(code, issuer) => s"$code from ${issuer.accountId}"
  • Ok, thanks for this. I'll just adjust logic to query Horizon for the provided asset and pick from the results instead with the AssetResponse type. I was basing my logic off of the JavaScript SDK when those areas where the c# and java docs weren't as detailed. In that SDK, account code and issuer are properties of any asset instance.
    – mrtpain
    Commented Sep 30, 2018 at 0:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.