I keep seeing #[pallet::compact] on some extrinsic arguments like here on the pallet-assets/mint definition:

pub fn mint(
            origin: OriginFor<T>,
            #[pallet::compact] id: T::AssetId,
            beneficiary: <T::Lookup as StaticLookup>::Source,
            #[pallet::compact] amount: T::Balance,
        ) -> DispatchResult

What does #[pallet::compact] do on an argument?
When do I have to use it for implementing a pallet?

1 Answer 1


You should use #[pallet::compact] wherever the type allows it, and you want to take advantage of compact encoding to reduce the amount of bytes that is needed to call an extrinsic.

https://docs.substrate.io/reference/scale-codec/ (Compact/general integers)

As a small reminder, compact encoding allows types like 0u64 to be represented as only 1 byte 0x00 rather than 8 bytes. This kind of "compactification" will be true for all small values, while it may introduce up to one additional byte overall for only the largest numbers.

So, by telling your pallet to expect a compact integer, you can on average reduce the number of bytes which are used to successfully call an extrinsic. This can reduce the overall size of your blockchain, and also reduce the fees for the end user.

This is never required, but is nice to include when the situation makes sense.

Note that changing between compact and non-compact encoding is a transaction version breaking change, since things like hardware wallets will expect to encode transaction in one of these specific ways.

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.