Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add decoration of runtimeApis #5845

Open
TarikGul opened this issue Apr 10, 2024 · 3 comments · May be fixed by #5986
Open

Add decoration of runtimeApis #5845

TarikGul opened this issue Apr 10, 2024 · 3 comments · May be fixed by #5986

Comments

@TarikGul
Copy link
Member

rel: #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
Copy link
Member Author

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

@peetzweg
Copy link
Contributor

peetzweg commented Aug 9, 2024

@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:

export const runtime: DefinitionsCall = {
AccountNonceApi: [
{
methods: {
account_nonce: {
description: 'The API to query account nonce (aka transaction index)',
params: [
{
name: 'accountId',
type: 'AccountId'
}
],
type: 'Index'
}
},
version: 1
}
]
};

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

@decentration
Copy link

this should go in V16

@TarikGul TarikGul linked a pull request Sep 19, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants