3

We are currently experiencing an issue related to RPC methods. Let me provide a description of the problem:

To generate metadata from our node, we use the following command:

echo '{"id":1,"jsonrpc":"2.0","method":"state_getMetadata","params":[]}' | websocat -n1 -B 99999999 wss://kusama-rpc.mangata.online > metadata.json

By using this metadata, we are able to generate types, as demonstrated in this repository repo (branch rc/1.0.0)

We have successfully generated all the required types, and everything is working smoothly. Additionally, we have added RPC methods when initializing the ApiPromise in JavaScript:

ApiPromise.create(
  {
    provider,
    rpc: {
      xyk: {
        calculate_buy_price: {
  description: "Calculates and returns sold_token_amount while providing bought_token_amount and respective reserves",
  params: [
    {
      name: "input_reserve",
      type: "Balance"
    },
    {
      name: "output_reserve",
      type: "Balance"
    },
    {
      name: "sell_amount",
      type: "Balance"
    }
  ],
  type: "XYKRpcResult<Balance>"
}

      }
    }
  }
)

Ideally, we would like to call this RPC method as follows:

api.rpc.xyk.calculate_buy_price() 

Unfortunately, this is currently not possible, and we have to use the following workaround:

(api.rpc as any).xyk.calculate_buy_price() 

This workaround is not optimal. According to the docs

you can define a firstModule_testMethod on the Rust node and if correctly defined it will be callable via api.rpc.firstModule.testMethod(...)

In our node, we have defined this method as xyk_calculate_buy_price, following this structure. We have noticed that when we generate the metadata, the module xyk is not present in the augment-api-rpc.ts file. We suspect that this is causing the issue. How can we include these RPC methods in the metadata? Alternatively, what steps should be taken to resolve this?

Any assistance would be greatly appreciated.

Thank you.

1 Answer 1

1

It seems that you require this update from https://github.com/paritytech/substrate/pull/14481. Without it, the custom RPC metadata will not be included in the runtime metadata.

1
  • Thanks @AurevoirXavier I will check it :) Jul 4, 2023 at 18:29

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.