I'm using pallet-assets
to implement my own pallet. In one of the extrinsic calls I would like to check if an asset with the given ID exists. How to achieve this, given that Assets
type is private and there's no getter provided?
2 Answers
I think you can use maybe_total_supply. This will return Some(supply) if the asset exists, and None otherwise https://github.com/paritytech/substrate/blob/0ba251c9388452c879bfcca425ada66f1f9bc802/frame/assets/src/functions.rs#L62
-
That's a good one. For some reason
maybe_total_supply
is not mentioned in the docs. Commented Jun 27, 2022 at 14:48
After you create the asset with for example pallet_assets::Pallet::<T>::force_create
query pallet_assets::<T>::Balance
with the asset id
let assetid: AssetId<T> = 1337u32.into();
let asset_balance: u128 = pallet_assets::Pallet::<T>::balance(assetid.into(), myaccount)
.try_into()
.unwrap_or(0u128);
-
This assumes I have an account
myaccount
with non-zero balance of the asset, which is not quite my case. Commented Jun 27, 2022 at 14:50
assets.asset(u32): Option<PalletAssetsAssetDetails>
?get
on github.com/paritytech/substrate/blob/master/frame/assets/src/… ?