api icon indicating copy to clipboard operation
api copied to clipboard

Add decoration of runtimeApis

Open TarikGul opened this issue 1 year ago • 2 comments

rel: https://github.com/polkadot-js/api/issues/5725

The next step in getting runtimeApis from the metadata is to have them decorated at runtime via the metadata. This can be seen as similar to decorateExtrinsics. This should only be available for V15.

Once this issue is complete we can then add it to the static typegen.

TarikGul avatar Apr 10 '24 18:04 TarikGul

This would actually replace decorateCalls inside of the api base decoration.

TarikGul avatar Apr 10 '24 19:04 TarikGul

@TarikGul Is there a way to manually add runtime API calls for now?

Unable to find hints in the docs, so I tried using the runtime option during ApiPromise creation like below. However, it's not even added to ApiPromise.call (undefined is not an object), so probably not the way how to do it in the first place. 🤔

import { DefinitionsCall } from "@polkadot/types/types";
import { ApiPromise, WsProvider } from "@polkadot/api";

const wsProvider = new WsProvider(`wss://...`);

export const api = await ApiPromise.create({
  provider: wsProvider,
  runtime: {
    camelCasedPalletNameApi: [
      {
        version: 1,
        methods: {
          camelCasedRuntimeFn {
            description: "This is my function",
            params: [],
            type: "Balance",
          },
        },
      },
    ],
  } as DefinitionsCall,
});

const result = await pjsApi.call.camelCasedPalletNameApi.camelCasedRuntimeFn();
console.log({result})

--- update

Never mind got it to work. Seems like it's important to use camel case for the api name key and an underscored runtime call function name.

Found out how to do it here: https://github.com/polkadot-js/api/blob/3b7b44f048ff515579dd233ea6964acec39c0589/packages/types/src/interfaces/system/runtime.ts#L6-L24

All in all looking forward for metadata v15 support. 👍 🚀

peetzweg avatar Aug 09 '24 11:08 peetzweg

this should go in V16

decentration avatar Sep 01 '24 12:09 decentration