4

The rpc methods (showing in rpc_methods), are still not showing in their own area, after (attempting to) decorate the rpc.

I have custom rpc on a substrate template.

Here are the rpc_methods:

methods

I have manually described the methods in apps-config/src/api/spec/supersig.ts

import type { OverrideBundleDefinition } from '@polkadot/types/types';

export default {
  rpc: {
    superSig: {
      getProposalState: {
        description: 'Get the proposal state',
        params: [
          {
            name: 'supersig_id',
            type: 'AccountId'
          },
          {
            name: 'call_id',
            type: 'CallId',
            
          }
        ],
        type: 'Result<(ProposalState<AccountId>, u32), DispatchError>'
      },
      get_user_supersigs: {
        description: 'Get supersigs associated to the user.',
        params: [
            {
            name: 'user_account',
            type: 'AccountId'
            },
        ],
        type: 'Vec<SupersigId>'
      },
      list_members: {
        description: 'List members of the supersig',
        params: [
            {
            name: 'supersig_id',
            type: 'AccountId'
            }
        ],
        type: 'Vec<(AccountId, Role)'
      },
      list_proposals: {
        description: 'List proposals associated to a supersig',
        params: [
            {
            name: 'supersig_id',
            type: 'AccountId'
            }
        ],
        type: 'Result<(Vec<ProposalState<AccountId>>, u32), DispatchError>'
      },
    },
  },
} as OverrideBundleDefinition;

I then renamed my local custom node-template, and then launched it using this command:

./target/release/node-template --chain="./supersig-raw.json" --alice --rpc-cors all --rpc-methods=unsafe

I named the chain to "supersig" and id: supersig in theh chain-spec,

and added the chain to a local hosted polkadot-js/apps (this branch):

However, the rpc methods are still not showing in their own area, which I attempted to decorate.

  1. Could you provide some guidance for what i am missing?
  2. type: 'Result<(Vec<ProposalState<AccountId>>, u32), DispatchError>' is that a correct way to create the return type in the rpc module?
3
  • 1
    Did you try this polkadot.js.org/docs/api/start/rpc.custom? Dec 7, 2022 at 17:30
  • Yes indeed that’s how I got to this point. Dec 8, 2022 at 10:50
  • to resolve this i had to put my decorated methods in typeBundles.js file manually. I am sure there is a command to run but this at least gave me the sanity of the ability to test it works correctly. Jan 5 at 8:43

2 Answers 2

2
+50
  1. Names, which are shown in the rpc.methods, are not related to chain name. So, you change your chain name won't affect those names. These names will only be affected by the annotations on the rpc method. e.g. The following rpc method name is did_getMetadata.
#[method(name = "did_getMetadata")]
    fn get_metadata(&self, did: DecentralizedId, key: String) -> RpcResult<String>;
  1. RpcResult<(Vec<ProposalState>, u32)> is great. And, if you want to return a struct in RpcResult, you should check if it requires more annotations on that struct. Instead of struct, I suggest to use pure primitive tupple.

Finally, try use state-call instead of custom rpc, because every time you need to create/modify a rpc api, you'll need to re-deploy the node binary. If you use state-call, its pure wasm runtime, so if some changes are needed, then you just need to upgrade the runtime.

6
  • thanks for your answer! Re: 1) how does the ui know where to get the custom rpc from, is not on a per chain basis, or can it apply to rpc method on any chain? Dec 8, 2022 at 21:37
  • So in this instead pure primitive tuple would be to just do (Vec<ProposalState>, u32) and leave out the RpcResult struct? Dec 8, 2022 at 21:38
  • 1
    @Decentration So in this instead pure primitive tuple would be to just do (Vec<ProposalState>, u32) and leave out the RpcResult struct? --- Yeah Dec 16, 2022 at 3:55
  • 1
    @Decentration "what do you mean by this can you give an example? Do you mean to add it into the runtime/lib.rs amongst the rpc functions, not outside the runtime?" -- Yes, define it in runtime instead of rpc, and then call it with state_call in the frontend. You can take github.com/coderfengyun/local-node-scripts/blob/… as the frontend example. And take github.com/parami-foundation/parami-blockchain/pull/41 as the substrate example. Dec 16, 2022 at 4:01
  • 1
    @Decentration 1) how does the ui know where to get the custom rpc from, is not on a per chain basis, or can it apply to rpc method on any chain? -- First, you can find your new rpc methods in polkadot.js "rpc calls -> rpc -> methods". Second, you should define the rpc method in frontend's code, refer to polkadot.js.org/docs/api/start/rpc.custom Dec 16, 2022 at 4:02
2

Not sure but maybe this will help you ? In mangata this is how we generate types and also RPC methods. Mangata types

4
  • substrate.stackexchange.com/help/how-to-answer -> Always quote the most relevant part of an important link, in case the external resource is unreachable or goes permanently offline. Links to other websites should always be helpful, but avoid making it necessary to click on them as much as possible.
    – Nuke
    Dec 9, 2022 at 18:05
  • 1
    I think this is a helpful answer, but could be improve greatly with a bit more confidence and concrete text in it with an example? 😀
    – Nuke
    Dec 9, 2022 at 18:06
  • 1
    What exactly do you need? Would you like to know how the whole process of generating types we did in our case? Dec 12, 2022 at 13:43
  • few steps would be great Dec 14, 2022 at 15:20

Your Answer

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

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