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 custom rpc not work #1668

Closed
Kayryu opened this issue Dec 13, 2019 · 2 comments
Closed

Add custom rpc not work #1668

Kayryu opened this issue Dec 13, 2019 · 2 comments

Comments

@Kayryu
Copy link

Kayryu commented Dec 13, 2019

I want to add a custom rpc interface, but it doesn't work.
here is example:

const { ApiPromise } = require('@polkadot/api');
const { WsProvider } = require('@polkadot/rpc-provider');
const provider = new WsProvider('ws://127.0.0.1:9944/');
const options = {
  provider: provider,
  rpc: {
    custom: [
      {
        name: 'foo',
        params: [
          {
            name: 'data',
            type: 'U32'
          }
        ],
        section: 'custom',
        type: 'U32'
      }
    ]
  }
}
// Create the API and wait until ready
ApiPromise.create(options).then(api => {
  return api.rpc.custom.foo(1)
}).then(console.log)

Error message:

UnhandledPromiseRejectionWarning: TypeError: api.rpc.custom.foo is not a function

dependencies:

"@polkadot/api": "^0.99.0-beta.16",
@Kayryu
Copy link
Author

Kayryu commented Dec 13, 2019

This problem is caused by substrate side.

Here is error code I previously defined:

#[rpc]
pub trait CustomApi<BlockHash> {
	/// test foo
	#[rpc(name = "foo")]
	fn foo(&self, data: u32) -> Result<u32>;
}

It should use #[rpc(name = "custom_foo")] to replace #[rpc(name = "foo")]

@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 Jun 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants