Skip to main content
26 votes
Accepted

When should I build a Substrate FRAME Pallet versus a Smart Contract?

Substrate Pallets and Substrate Smart Contracts are two different approaches to building "decentralized applications" using the Substrate framework. Smart Contracts A traditional smart ...
Shawn Tabrizi's user avatar
  • 16k
13 votes
Accepted

What are some good use cases for anonymous proxies?

One good use case is to be able to transfer ownership of a multisig member. Since multisig AccountIds are derived based on their members, changing one member changes the address of the multisig. If ...
joepetrowski's user avatar
  • 2,955
11 votes

How to fix `parity_scale_codec::MaxEncodedLen` is not implemented for `T`?

The underlying issue here is that Rust macros are not super intelligent. While you are correct that all the interior fields of Kitty is bounded in length, you are also using the generic type T: Config ...
Shawn Tabrizi's user avatar
  • 16k
11 votes
Accepted

Why is there no `Default` implementation for `T::AccountId`?

Short answer: AccountId is not designed to be bound to Default. A "default" AccountId doesn't make any sense to have and it helped mask a previous issue and so it was removed in a recent ...
Gav's user avatar
  • 2,681
10 votes
Accepted

When to use `BoundedVec` vs. `WeakBoundedVec` vs. `Vec`?

Please don't use WeakBoundedVec ever, unless you are migrating code which you plan to fix in the future. Instead use directly BoundedVec which ensures that any item placed in storage as a maximum ...
Shawn Tabrizi's user avatar
  • 16k
9 votes

Is it possible to use format! in Substrate runtime?

Using String in the runtime is discouraged by Substrate, because it most often means that you are doing something "wrong". Aka user data should not be stored on chain, you should instead ...
bkchr's user avatar
  • 11.3k
9 votes

Is it possible to use format! in Substrate runtime?

The item referred by the path sp_std::fmt::format is actually a function, rather than a macro. See documentation. The fundamental problem though is that under a no_std environment, the format! macro ...
Keith Yeung's user avatar
  • 2,121
9 votes
Accepted

<T::Lookup as StaticLookup>::Source vs T::AccountId?

Shawn has explained a lot. Let me give you a real example. I've implemented a custom AccoundIdLookup for Darwinia, which allows transfer from Substrate address to EVM address directly. https://github....
AurevoirXavier's user avatar
  • 10.4k
7 votes
Accepted

How do I use storage and functions from one custom pallet in another?

If you are building a pallet (pallet2) which has a direct dependency on another pallet (pallet1), you can you "tight coupling" inherit pallet1's Config in pallet2's Config definition: pub ...
Shawn Tabrizi's user avatar
  • 16k
7 votes
Accepted

How are Events aggregated

Yes, you are right that every runtime has Event declaration that combines all the events of each pallet. It looks roughly like this: enum Event { System(frame_system::Event), Balances(...
bkchr's user avatar
  • 11.3k
7 votes
Accepted

Which data to put in a Pallet Event?

For Substrate events are also "expensive". Events are in the state of each block. This means that archive nodes for example need to store all events of all blocks that ever happened. So, if ...
bkchr's user avatar
  • 11.3k
7 votes
Accepted

How do treasury accounts compare to end user accounts in FRAME?

I would like to understand how treasury accounts are created and used under the hood You can see here for a similar explanation on sub-accounts. To walk through the specific steps here: Here is the ...
Shawn Tabrizi's user avatar
  • 16k
7 votes
Accepted

How to limit the number of values by prefix in StorageDoubleMap?

You could also use a vector as a value to AccountId. #[pallet::storage] #[pallet::getter(fn addresses_owned)] /// Keeps track of address owners. pub(super) type AddressOwners<T: Config> = ...
Amir Boziev's user avatar
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

<T::Lookup as StaticLookup>::Source vs T::AccountId?

You can start by looking at the trait: /// Means of changing one type into another in a manner dependent on the source type. /// This variant is different to `Lookup` in that it doesn't (can cannot) ...
Shawn Tabrizi's user avatar
  • 16k
6 votes

Query on polkadot-apps chain-state cuts of string. Text-overflow?

It is not actually a display issue as suggested, it is by design where values > 512 bits are truncated. If you wish to have the actual full value, you can always query via the developer tools. ...
Jaco's user avatar
  • 5,865
6 votes

BTreeMap storage type

There is no sorted storage type. That would be way too expensive to realize, just imagine adding an item how many storage reads that would need. However, for small things you can just use a storage ...
bkchr's user avatar
  • 11.3k
6 votes

Scalability beyond Asynchronous Backing

We have a number of protocol updates that will help improve scalability at the protocol level. Torrent-style fetching of PoVs: https://github.com/paritytech/polkadot/issues/3307 . This includes a &...
rob's user avatar
  • 2,126
6 votes
Accepted

How to convert `BlockNumber` to `u64`?

use sp_runtime::traits::SaturatedConversion; fn f(block_number: BlockNumber) { block_number.saturated_into::<u64>(); }
AurevoirXavier's user avatar
  • 10.4k
5 votes

What means `PhantomData<T>` in a pallet?

A phantom type parameter is simply a type parameter which is never used. In Rust, this often causes the compiler to complain, and the solution is to add a “dummy” use by way of PhantomData. Adding a ...
Alejandro Martínez's user avatar
5 votes
Accepted

Difference between ReservableCurrency and NamedReservableCurrency?

The context for NamedReserveableCurrency can be found here: https://github.com/paritytech/substrate/issues/7223 https://github.com/paritytech/substrate/pull/7778 Basically, this was a feature added ...
Shawn Tabrizi's user avatar
  • 16k
5 votes

How do treasury accounts compare to end user accounts in FRAME?

There is no difference. From the point of view of the runtime, the treasury account is like a normal account. These special system accounts are just public keys, without the private key being known. ...
bkchr's user avatar
  • 11.3k
5 votes
Accepted

What is a runtime as a data structure?

Yes, the Runtime is a struct which implements a bunch of traits, for example all the Config traits required by the pallets you include in your runtime. You can look at the Runtime generated by the ...
Shawn Tabrizi's user avatar
  • 16k
5 votes
Accepted

How can I check whether a specific storage item was already accessed in the current block?

You can not check whether a specific storage item was already read or written. You need to assume the worst case, aka always having a "fresh" read.
bkchr's user avatar
  • 11.3k
5 votes

How does the AccountData type work in FRAME runtimes?

I believe I'd asked a similar question on stackoverflow a while ago and it may answer your question: https://stackoverflow.com/questions/70845959/balances-accountstore-definition-in-substrate-runtime ...
Purple_Turtle's user avatar
5 votes

Substrate compatible crate for handling RSA encryption

I would also probably advise to avoid rsa. About your issue, it may be possible to import code in runtime by disabling 'std'. In your cargo.toml, import your ring dependency with flag 'no-default-...
cheme's user avatar
  • 456
5 votes
Accepted

When to use `compact` on extrinsic arguments?

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....
Shawn Tabrizi's user avatar
  • 16k
5 votes

How to limit the number of values by prefix in StorageDoubleMap?

Any solution to this problem, whether provided by FRAME or implemented manually, would require storing the number of items currently in the map in some other storage location, since you would never ...
Shawn Tabrizi's user avatar
  • 16k
5 votes

How can I configure genesis state for my pallet's tests without hardcoding it?

You can configure the new_test_ext function however you like. In this case, you can make it take the parameters you'll want to use to modify your genesis state and then just pass values into your ...
Sacha Lansky's user avatar
  • 2,640
5 votes

Why do frame calls take a `Vec` parameter instead of `BoundedVec`?

BoundedVec is still a relatively new type that was introduced in the last months. It is not yet used everywhere. BoundedVec is mainly useful for when you want to make your storage bound to some ...
bkchr's user avatar
  • 11.3k

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