I've been trying to add some rpc calls available for my node, but an error related to the 'getrandom' module appears (even tho I'm not even using it).

I have a very simple pallet that creates and transfers items, and it is working just fine. The problem comes when I try to add the custom rpc calls to the node.

error: the wasm32-unknown-unknown target is not supported by default, you may need to 
enable the "js" feature. For more information see: 

I tried adding the dependency as stated in the documentation regarding this issue, but nothing seems to fix the issue, it just generates more errors.

This is the documentation I've been using to implement the custom rpc calls for my pallet. I'll leave here my SO question, which is a little bit longer but its the same issue: https://stackoverflow.com/questions/71734501/error-adding-custom-rpcs-for-custom-pallet-substrate



Is there any recent documentation about adding custom RPCs for a pallet? Everything I've found is pretty outdated I think.

UPDATE: I've uploaded the current status of the code, I think it will be easier to try.


  • Those tetcoin.org stuff I would steer clear of. Someone randomly forked all of substrate a while back. I think anything on those sites is at least very dated, and possibly suspect.
    – Squirrel
    Commented Apr 4, 2022 at 12:52
  • @Squirrel I agree, It was the only thing I found that tried to explain the process of adding custom RPCs tbh.
    – andresvsm
    Commented Apr 4, 2022 at 13:02

3 Answers 3


I also noticed that the docs were lacking in explanation on how to add custom rpcs, but then I stumbled on the rust RPC repo by parity. It's referenced at the bottom of the docs on substrate.io that talks about adding custom rpcs: https://github.com/paritytech/jsonrpc

From the examples in the README file, it seems the RPC is a struct that implements the RPC trait. This RPC trait has some macros derived that help specify the functions to be exposed. This is then made concrete on the RPC struct with an impl block that defines the functions fully. To do the same on a node, the main focus would be to find something similar to the two impl blocks (one for the trait, the other for the struct). I'd look for something similar on substrate nodes and use that instead.

To give an example with the node-template I used,


I just looked through it and there's a comment at the bottom that explains how to extend the functionality on a node. Specifically:

    // Extend this RPC with a custom API by using the following syntax.
    // `YourRpcStruct` should have a reference to a client, which is needed
    // to call into the runtime.
    // `io.extend_with(YourRpcTrait::to_delegate(YourRpcStruct::new(ReferenceToClient, ...)));`

To bring things together, I'd call this method (io.extend_with()), or its equivalent on your setup, with a custom struct that has the rpcs you'd like to expose and the accompanying trait following the guide from paritytech/jsonrpc. Specifically, the one on clients: https://github.com/paritytech/jsonrpc#client-support

This doesn't quite answer your question with the error, but I hope it helps you implement a custom RPC.


Please review the following Recipe link. All you are looking for is carefully explained there.



  • 1
    Thanks for the reply, but I'm having the same issue. I managed to get the silly_rpc working tho, but I can't add the custom RPC for my pallet.
    – andresvsm
    Commented Apr 6, 2022 at 7:25

After reading this post Implementation of runtime api RPC, I found out I was also missing the same requirement. Adding it and re-exporting my custom runtime for the custom pallet, the node compiled and it's working.

I didn't need to include the getRandom crate to make it work, it was just that missing line -.-

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.