7 votes
Accepted

What are the differences between using declarative and attribute macros in FRAME?

The decl_* macros were deprecated in favour of the newer procedural macros, such as [pallet::storage]. The problem with old macros is that they invented new syntax, instead of allowing users to write ...
Vincent's user avatar
  • 158
7 votes

What is the role of `#[scale_info(skip_type_params(T))]`?

The answer to this question is similar to the answer here: How to fix `parity_scale_codec::MaxEncodedLen` is not implemented for `T`? Basically, Rust macros are not that intelligent. In the case of ...
Shawn Tabrizi's user avatar
  • 16k
4 votes
Accepted

Why do runtime APIs have a block_height parameter on the client side but not on the runtime side?

The block hash is for client-side rather than the runtime itself - it tells the client to invoke the runtime API using the post-state of the given block hash. The way this manifests is in how the ...
rob's user avatar
  • 2,126
4 votes

Adding PaysFee to #[pallet::weight("")] produces unexpected token error

I think this is a mistake in the docs, rather than: #[pallet::weight(10_000, Pays::No)] it should be as a tuple: #[pallet::weight((10_000, Pays::No))] I agree it would be nicer if this wasn't the case....
Squirrel's user avatar
  • 3,839
4 votes

What are the differences between using declarative and attribute macros in FRAME?

Declarative macros (specifically, macro_rules!) are used in FRAME V1. Most of FRAME pallets written prior to January 2021 use these. FRAME V2 on the other hand, officially introduced in January 2021 ...
Sacha Lansky's user avatar
  • 2,620
4 votes
Accepted

What does #[pallet::compact] do?

https://paritytech.github.io/substrate/master/frame_support/pallet_macros/attr.compact.html Compact encoding for arguments can be achieved via #[pallet::compact]. The function must return a ...
AurevoirXavier's user avatar
2 votes
Accepted

The ensure! macro with a false condition doesn't make an extrinsic fail, why?

While Alex Bean's answer would be perfectly right if things were running normally, in this particular case, the question was asked because something went wrong, while using the latest node-template v9....
Tbaut's user avatar
  • 253
2 votes

The ensure! macro with a false condition doesn't make an extrinsic fail, why?

If send the extrinsic setName with a name shorter than the number you set when configured the pallet you can will see that the extrinsic is included in the block, but it fails to perform the operation....
Alex Bean's user avatar
  • 5,692
2 votes
Accepted

Invalid generic declaration when using FRAME macro pallet::error

It looks like your pallet is instantiatable. This requires you to additionally pass in the instance type like such. In the easiest case it looks like this: #[pallet::error] pub enum Error<T, I = ()&...
Oliver Tale-Yazdi's user avatar
2 votes

Mixing FRAME macros in a single runtime or pallet

It should be okay to mix pallets from the old and new macros. We had this for a while when we were migrating pallets to the new macros. End of the day, the underlying generated Rust code is the same, ...
Shawn Tabrizi's user avatar
  • 16k
2 votes
Accepted

Why getter function don't return Result type?

There is a trait bound. You are using ValueQuery. The value in the storage map must be implemented Default. If the key is missing in the storage map, then the default value will be returned. If you ...
AurevoirXavier's user avatar
2 votes

Organize Runtime into modules

For example would it be possible to create a storage.rs module and add the storages there like so I think the answer is no. You can't split #[pallet::storage] from pallet module. When you go into the ...
ironman_ch_parami's user avatar
1 vote

Expose StorageItems to other pallets whose types are bound on an instance of my pallet

As far as I understand your trait approach is correct. The only way of how Pallets are supposed to interact with each other, be it storage or calls, is through traits. So you cannot use a storage Item ...
Oliver Tale-Yazdi's user avatar
1 vote

Is it possible for users to call non #[pallet::call_index(0)] functions

Without the #[pallet::call] macro, these functions will not have any dispatch logic which would allow an external caller to trigger the function to execute. You will note that dispatchable calls all ...
Shawn Tabrizi's user avatar
  • 16k
1 vote

Is it possible for users to call non #[pallet::call_index(0)] functions

I would also add that it is possible to call this function within runtime or from another pallet (with tight coupling) since it is a public function. For example, in pallet_a: // Tight coupling with `...
dastansam's user avatar
  • 501
1 vote
Accepted

Is it possible for users to call non #[pallet::call_index(0)] functions

No. These functions are purely internal. It is safe to write internal logic in them - no user can call into it. However, if you need something purely for testing you can still add a #[cfg(test)] or #[...
Oliver Tale-Yazdi's user avatar
1 vote
Accepted

`The trait Deserialize is not implemented for a` GenesisConfig

Change #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] to #[derive(serde::Serialize, serde::Deserialize)] It requires to be always Serialize now.
AurevoirXavier's user avatar
1 vote

Error in Substrate "use macros in a custom pallet" tutorial

Unfortunately there is a bug in the tutorial at the moment. While we work to fix it in the tutorial, here is a fix to the code: #![cfg_attr(not(feature = "std"), no_std)] // Re-export ...
Shawn Tabrizi's user avatar
  • 16k

Only top scored, non community-wiki answers of a minimum length are eligible