Skip to main content
15 votes
Accepted

How to verify a signature in a Pallet?

Substrate provides a Verify and an IdentifyAccount trait. They work with any signature scheme since they are just traits and can be implemented for different crypto schemata. This is very helpful when ...
Oliver Tale-Yazdi's user avatar
7 votes
Accepted

How to mint offchain NFT in pallet_nfts

In order to sign the mintData object, you would need to get its encoded version first. The easiest way to do this is to open the mintPreSigned extrinsic's form and fill it with the data: For the ...
Jegor Sidorenko's user avatar
6 votes
Accepted

How to parse/match a specific frame_system event?

The code removed in this PR is exactly what you need to do. Trying to translate it into your case would yield: #[pallet::hooks] impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet&...
kianenigma's user avatar
  • 2,844
6 votes

Is there any way to get all the key/value pairs together from sc_client_db::offchain::LocalStorage?

From the best of my knowledge there is no utility to do it, you are limited to OffchainStorage trait. Technically, the offchain storage directly writes to the underlying db column (just prefixing the ...
cheme's user avatar
  • 456
6 votes
Accepted

How to avoid multiple OCWs duplicating work?

It sounds to me that you are using offchain workers incorrectly. They should not be thought of as trusted applications which can modify your runtime's state or behave in expected ways. In fact, you ...
Shawn Tabrizi's user avatar
  • 16.2k
5 votes

How can I create OCW that won't activates every block, but will activates only when I call function that it represents?

There are 3 levels of answer to this question. As OCW being a commonly misunderstood topic, it is a very good question. Simple Answer First, a crude and objectively inefficient answer. You can use the ...
kianenigma's user avatar
  • 2,844
5 votes

How to verify a signature in a Pallet?

You can also see fully integrated examples of signature verification in a Pallet with: The claims pallet, which verifies Ethereum Signatures impl<T: Config> Pallet<T> { // Constructs ...
Shawn Tabrizi's user avatar
  • 16.2k
4 votes

How to parse/match a specific frame_system event?

@kianenigma, thanks for you extended and detailed answer. There was just one small missing piece. I had to setup the TryInto<Event<Self>> to the #[pallet::config] macro or otherwise your ...
Pablo Buitrago's user avatar
4 votes

How to extract data from Offchain storage in client-side?

On the client-side we can get the off-chain storage instance from shared backend instance (which is of type Arc < FullBanckend >). This instance can be find inside new_full(). After getting the ...
Pawan Bisht's user avatar
4 votes

How to mint offchain NFT in pallet_nfts

Offchain minting is a feature built into the NFTs pallet. It is the ability to mint NFTs by having the issuer of a collection sign encoded mint data offchain, this encoded mint data will either ...
Bruno's user avatar
  • 8,335
3 votes

What is KeyTypeId, and how to use it?

The idea by KeyTypeId is to have some unique identifier for a key. This is used for the "application crypto" as we call it in Substrate. Basically that just means that you should use ...
bkchr's user avatar
  • 11.6k
2 votes

How to avoid multiple OCWs duplicating work?

So the idea of OCW's is that it will do some off-chain "work" and ultimately submit a transaction that will call a public function in the runtime to get the result of that work on-chain. OCW'...
Bruno's user avatar
  • 8,335
2 votes

Read a value from offchain storage of a node

You can access the data stored in the OffchainStorage using offchain worker threads that have read and write access or through the on-chain logic using offchain indexing. Read more about Offchain ...
Alex Bean's user avatar
  • 5,757
2 votes
Accepted

How to enable off-chain workers for parachain via command line?

Are you using the parachain node template from Cumulus? According to the help text, it's only enabled for nodes that are authoring new blocks: ./target/release/parachain-template-node --help --...
Bruno's user avatar
  • 8,335
2 votes
Accepted

What is the best way to add additional libp2p protocols to Substrate client?

sc-network allows for custom notification protocols and request/response protocols to be registered with the NetworkConfiguration when starting the service. The extra_sets define peer-sets for ...
rob's user avatar
  • 2,126
2 votes

AccountId in offchain worker

Bear in mind that a particular node isn't inherently associated with a particular on chain validator. Node X is only validator X because to happens to have the current session keys for that validator. ...
JelliedOwl - Paul's user avatar
1 vote
Accepted

Is there a way to use a crate that depends on the `std` in substrate OCW?

I'm not sure why it was designed this way, but I understand how it works. Perhaps they intended for the OCW to run anywhere since it's part of the WASM blob. Therefore, everything is compiled into ...
AurevoirXavier's user avatar
  • 10.8k
1 vote
Accepted

can't use BTreeMap with custom key struct for offchain Local Storage

https://docs.rs/parity-scale-codec/3.4.0/src/parity_scale_codec/codec.rs.html#1084-1093 impl_codec_through_iterator! { BTreeMap { K: Ord, V } { LikeK, LikeV} { K: EncodeLike<LikeK>, ...
AurevoirXavier's user avatar
  • 10.8k
1 vote

Read a value from offchain storage of a node

I think that's impossible. offchain-indexing is an option. The node can access the offchain storage only when it enabled this feature. Not every node enables that. Also, you might notice that there is ...
AurevoirXavier's user avatar
  • 10.8k
1 vote
Accepted

Offchain indexing storage overwrites during forks

Is it a safe to assume that in case of forks for offchain indexing writes, a storage will always get overwritten by the canonical block eventually? Correct, off-chain indexing is called from on-chain ...
Daan van der Plas's user avatar
1 vote

How to use FixedU128?

Note that FixedU128 is not a floating point type. It represents floating point numbers using u128 type with 18 digits of precision. This means that the last 18 digits of any number are taken to be the ...
Sachin's user avatar
  • 61
1 vote

Facing issue in adding offchain worker

Offchain workers must also be enabled on the client side. Make sure you have configured the cli parameters to run the offchain workers. You must also spawn an offchain worker task in your client side ...
JoshOrndorff's user avatar
  • 1,201
1 vote

What is KeyTypeId, and how to use it?

KeyTypeId is used in creating an identifier that maps to public keys in your application. The public keys then map to private keys. Essentially, the identifier is a public value that represents the ...
Abdulbee's user avatar
  • 388
1 vote

What is KeyTypeId, and how to use it?

Here defines some well-known key type ids. Just like its name. It's the key type's id. Which is used here. From the algorithm level, key type id is just a 4-bytes-length slice append to the key head. ...
AurevoirXavier's user avatar
  • 10.8k
1 vote

How to generate key pair in pallet or on offchain work

For "How to generate random offchain", you can refer https://wiki.polkadot.network/docs/learn-randomness
ironman_ch_parami's user avatar
1 vote

Offchain workers in parachain

Yes, it has to work too. As suggested in the previous answer check that you are doing the initialisation. Do the Substrate tutorial: Add offchain workers to see how to implement the pallet in the ...
Alex Bean's user avatar
  • 5,757
1 vote

Offchain workers in parachain

Did you initialise the offchain worker in service.rs file? These lines have to be added to initialise offchain worker https://github.com/substrate-developer-hub/substrate-node-template/blob/...
sierratango's user avatar
1 vote
Accepted

Off-chain DB indexing example

I found out it's just a hook, so no worries, all good. #[pallet::hooks] impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> { /// Initialization fn on_initialize(now:...
Pablo Buitrago's user avatar

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