如何将 u128 转换为余额?

How to convert u128 to Balance?

如何将 u128 转换为余额?

use frame_support::{
        traits::{Currency, ExistenceRequirement, Get, ReservableCurrency, WithdrawReasons},
    };

type BalanceOf<T> = <<T as Config>::Currency as Currency<AccountIdOf<T>>>::Balance;

#[pallet::type_value]
pub fn DefaultRegistrationFees<T: Config>() -> BalanceOf<T> { 100 }

错误:
lib.rs(79, 67): 预期关联类型,找到整数

试过这个方法:

100.into() 不起作用。

我是否必须使用 configurable pallet constant 在运行时声明?

有了这个 https://crates.parity.io/sp_arithmetic/traits/trait.SaturatedConversion.html#method.saturated_into 你可以轻松地将 num 转换为 Balance

例子https://sourcegraph.com/github.com/paritytech/substrate/-/blob/frame/transaction-payment/src/lib.rs?L584.

另外,推荐阅读这篇