Open Snikko opened 1 year ago
Did you follow some tutorial or how did you add it to the template?
Where did you get the code from?
Did you follow some tutorial or how did you add it to the template? Where did you get the code from?
yeah,I followed some tutorials to add it to my template,sunch as https://substrate.stackexchange.com/questions/5554/how-to-add-custom-rpcs and https://github.com/AlexD10S/susbtrate-node-template/blob/rpc-custom-methods/pallets/template/rpc/src/lib.rs#L9 and others. I compared the codes among them and found that they did the same thing.But ,when I added the codes in my project, errors occured like that when it is built.So,maybe,I think wether the newest codes causing the problem,I am not sure.
@AlexD10S do you know if the tutorial maybe needs an update?
@AlexD10S do you know if the tutorial maybe needs an update? yeah,I know.I download the newest version of substrate-node-template and add the rpc configuration to it following the tutorial,changing the version to the newest in the file Cargo.toml of rpc.The version is v1.0.0.(branch = "polkadot-v1.0.0")
error[E0308]: mismatched types --> pallets/template/src/rpc/src/lib.rs:45:23 | 45 | api.get_value(&at,v).map_err(runtime_error_into_rpc_err) | --------- ^^^ expected associated type, found &BlockId<_> |
---|---|---|---|
arguments to this method are incorrect | |||
= note: expected associated type `<Block as BlockT>::Hash`
found reference `&BlockId<_>`
help: a method is available that returns <Block as BlockT>::Hash
--> /root/.cargo/git/checkouts/substrate-7e08433d4c370a21/948fbd2/primitives/runtime/src/traits.rs:1274:2 |
1274 | fn hash(&self) -> Self::Hash { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ consider calling sp_api::BlockT::hash
note: method defined here
--> /home/nikko/substrate-node-template/pallets/template/src/rpc/runtime-api/src/lib.rs:7:12 |
---|---|---|---|
7 | fn get_value(v: u32) -> bool; | ||
^^^^^^^^^ |
For more information about this error, try rustc --explain E0308
.
@AlexD10S do you know if the tutorial maybe needs an update?
I have found the answer.Thanks.
I am going to take a look, probably it needs an update. The tutorial was done with polkadot-v0.9.28
.
@Snikko If you have found an answer, can you share your solution here or in the StackExchange question with a new answer or editing mine. The community will benefit if you share your solution there.
I am going to take a look, probably it needs an update. The tutorial was done with
polkadot-v0.9.28
.@Snikko If you have found an answer, can you share your solution here or in the StackExchange question with a new answer or editing mine. The community will benefit if you share your solution there.
impl<C, Block> TemplateApiServer<
{
let api = self.client.runtime_api();
let at = at.unwrap_or_else(||self.client.info().best_hash);
api.get_value(at).map_err(runtime_error_into_rpc_err)
}
Is there an existing issue?
Experiencing problems? Have you tried our Stack Exchange first?
Description of bug
I want to add rpc function in my substrate blockchain to supply restful apis for others.But some mistake occur when the project is built.The errors show like this:
&BlockId<_>
Steps to reproduce
1、add rpc configuration to the prject correctly 2、build the project 3、errors like this:
&BlockId<_>