substrate-docs
substrate-docs copied to clipboard
Update Offchain worker docs: could not find `SyncCryptoStore` in `sp_keystore`
This should be Code Bug Report, not requesting for new content. I make a mistake in issue label.
Is there an existing issue?
- [X] I have searched the existing issues
Experiencing problems? Have you tried our Stack Exchange first?
- [X] This is not a support question.
Content request
Problem
When I follows the offchain worder guide here https://docs.substrate.io/tutorials/build-application-logic/add-offchain-workers/#unsigned-transactions
Using a development account If you are running a node in development mode—with --dev command-line option—you can manually generate and insert the account key for a development account by modifying the node/src/service.rs file as follows:
pub fn new_partial(config: &Configuration) -> Result <SomeStruct, SomeError> {
//...
if config.offchain_worker.enabled {
// Initialize seed for signing transaction using offchain workers. This is a convenience
// so learners can see the transactions submitted simply running the node.
// Typically these keys should be inserted with RPC calls to `author_insertKey`.
sp_keystore::SyncCryptoStore::sr25519_generate_new(
&*keystore,
node_template_runtime::pallet_your_ocw_pallet::KEY_TYPE,
Some("//Alice"),
).expect("Creating key with account Alice should succeed.");
}
}
This example manually adds the key for the Alice account to the keystore identified by the KEY_TYPE defined in your pallet. For a working example, see this sample service.rs file.
I meet the following error
error[E0433]: failed to resolve: could not find `SyncCryptoStore` in `sp_keystore`
--> node/src/service.rs:141:16
|
141 | sp_keystore::SyncCryptoStore::sr25519_generate_new(
| ^^^^^^^^^^^^^^^ could not find `SyncCryptoStore` in `sp_keystore`
Solution
With Polkadot-v1.0.0 and sp-keystore version = "0.27.0": there is no SyncCryptoStore in sp_keystore. Use sp_keystore::Keystore::sr25519_generate_new
pub fn new_partial(config: &Configuration) -> Result <SomeStruct, SomeError> {
//...
if config.offchain_worker.enabled {
// Initialize seed for signing transaction using offchain workers. This is a convenience
// so learners can see the transactions submitted simply running the node.
// Typically these keys should be inserted with RPC calls to `author_insertKey`.
sp_keystore::Keystore::sr25519_generate_new(
&*keystore,
node_template_runtime::pallet_your_ocw_pallet::KEY_TYPE,
Some("//Alice"),
).expect("Creating key with account Alice should succeed.");
}
}
Are you willing to help with this request?
Yes!