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

How to include custom RPC in polkadotjs (+types) #4954

Closed
crystalin opened this issue Jun 18, 2022 · 13 comments
Closed

How to include custom RPC in polkadotjs (+types) #4954

crystalin opened this issue Jun 18, 2022 · 13 comments
Labels
Support Tracks issues or requests related to troubleshooting, answering questions, and user assistance.

Comments

@crystalin
Copy link
Contributor

crystalin commented Jun 18, 2022

When generating the api-augment with typegen, the additional RPC methods are not included.
Additionally those rpc_method are not recognized when polkadotjs connect to the network and load the types.

API/INIT: RPC methods not decorated: eth_feeHistory, eth_maxPriorityFeePerGas, moon_isBlockFinalized, moon_isTxFinalized

Ex: using npm install @moonbeam-network/[email protected]

import "@moonbeam-network/api-augment";
import { ApiPromise, WsProvider } from "@polkadot/api";

const main = async () => {
  const api = await ApiPromise.create({
    provider: new WsProvider("wss://wss.api.moonbase.moonbeam.network"),
  });
  await api.isReady;

  const blockHash = `0x0bbeb2c7b5e7c3e960efd54029404fa2ec4288ff1e1ae6d2b149793a7b0a0226`;
  console.log(`${blockHash} finalized?: ${api.rpc.moon.isBlockFinalized(blockHash)}`);
};

main();

This will fail to compile (because of missing moon) and fail to execute because moon is not decorated in the api object.

@jacogr jacogr added the Support Tracks issues or requests related to troubleshooting, answering questions, and user assistance. label Jun 18, 2022
@jacogr
Copy link
Member

jacogr commented Jun 18, 2022

@crystalin
Copy link
Contributor Author

crystalin commented Jun 18, 2022

Thank you @jacogr, I didn't see this one. It is working for the js decoration.
Do you know for the api-augment part ?

@jacogr
Copy link
Member

jacogr commented Jun 18, 2022

Assuming you have the RPCs in your definitions when building the types, it should create augmented types for those as well. Basically it should create a augment-api-rpc.ts file. (This is based on the rpc key in the supplied edfinitions)

@crystalin
Copy link
Contributor Author

I thought those were taken automatically from the rpc nodes

@jacogr
Copy link
Member

jacogr commented Jun 18, 2022

There is no way it can be - the nodes only expose the names of the methods, no parameters whatsoever. See the api.rpc.rpc.methods call. So it can determine if there is something it doesn't know about, but nothing more, no types, no return values.

Unlike the runtime none of this is fully-specified and it seems unlikely that this will become a reality (Substrate tracking issue)

The consensus from the Substrate side seems to be that there should be no manual RPCs, you can also check in on the other links as part of this API issue, which just moves the issue around to state_call definitions, aka teams would still need manual definitions for these things.

@crystalin
Copy link
Contributor Author

Interesting, that would definitely be valuable to include the types in there.

@crystalin
Copy link
Contributor Author

I tried adding rpc to the interfaces/moon/definitions.ts (and including it in the index.ts) but it doesn't include it in the augment-api-rpc.ts ( see https://github.com/PureStake/moonbeam/pull/1613/files#diff-17f80788bf6f510b72f3d2b75c0d9fefe6ba3044235385f6732ce69be7f58316R1)
Do you see what I did wrong ?

@jacogr
Copy link
Member

jacogr commented Jun 19, 2022

Ummm... will checkout that branch and run it, it certainly looks correct.

@crystalin
Copy link
Contributor Author

@jacogr Were you able to find some information? Otherwise I'll try to dig into the typegen.

@jacogr
Copy link
Member

jacogr commented Jun 20, 2022

Have it on the list of TODOs, have not gotten there to look.

@jacogr
Copy link
Member

jacogr commented Jun 27, 2022

Add the --package @moonbeam/api-augment/moonbeam/interfaces parameter to polkadot-types-from-chain.

"generate:meta:moonbase": "ts-node --skip-project node_modules/.bin/polkadot-types-from-chain --endpoint ./metadata-moonbase.json --package @moonbeam/api-augment/moonbeam/interfaces --output ./src/moonbase/interfaces",
"generate:meta:moonriver": "ts-node --skip-project node_modules/.bin/polkadot-types-from-chain --endpoint ./metadata-moonriver.json --package @moonbeam/api-augment/moonbeam/interfaces --output ./src/moonriver/interfaces",
"generate:meta:moonbeam": "ts-node --skip-project node_modules/.bin/polkadot-types-from-chain --endpoint ./metadata-moonbeam.json --package @moonbeam/api-augment/moonbeam/interfaces --output ./src/moonbeam/interfaces",

This added the moon endpoints for me on your branch.

@crystalin
Copy link
Contributor Author

Thank you @jacogr it worked as expected :)

@polkadot-js-bot
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue if you think you have a related problem or query.

@polkadot-js polkadot-js locked as resolved and limited conversation to collaborators Jul 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Support Tracks issues or requests related to troubleshooting, answering questions, and user assistance.
Projects
None yet
Development

No branches or pull requests

3 participants