I want to write custom query based on this answer:

impl<T: Config> Pallet<T> {
    pub fn hello_world() -> u128 {

But the problem is, it is not exposed in query of pallet inspector in substrate-node-template.

Neither I could query with polkadot js api.

  const queryResHandler = result =>
    result.isNone ? setStatus('None') : setStatus(result.toString()) 
const opts = []
let data = api.query.templateModule.hello_world(...opts, queryResHandler)
let data = api.query.templateModule.helloWorld(...opts, queryResHandler)

Gives error

TypeError: Function.prototype.apply was called on undefined, which is a undefined and not a function

What more I need to do?

  • You may want to create your custom RPCs. docs.substrate.io/v3/runtime/custom-rpcs
    – Burak
    Apr 7, 2022 at 16:53
  • Documentation is scarce for implementation. Any code examples. Apr 7, 2022 at 17:42
  • 1
    You can check out this pallet from substrate recipes. And here how to call a runtime api using RPC. You can also take a look at Subsocial's profile pallet
    – Burak
    Apr 7, 2022 at 18:07
  • substrate.recipes/runtime-api.html Trying to implement runtime api, but there is version conflict error for sp-api. error: failed to select a version for parity-util-mem. ... required by package sc-service v0.10.0-dev (https://github.com/paritytech/substrate.git?tag=monthly-2021-10#bf9683ee) Apr 7, 2022 at 18:07
  • Make sure that you're using the same substrate tag for the whole project. If different, it may cause conflicts.
    – Burak
    Apr 7, 2022 at 18:55

1 Answer 1


As some in the comments mentioned you can create a custom RPC that queries a value from storage.

Check this answer on StackExchange about how to do it or this tutorial, that creates a custom RPC query from the pallet template in the Substrate node template.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.