polkadot-js / api

Promise and RxJS APIs around Polkadot and Substrate based chains via RPC calls. It is dynamically generated based on what the Substrate runtime provides in terms of metadata.
Apache License 2.0
1.07k stars 354 forks source link

Your runtime does not expose the api.call.contractsApi.call runtime interfaces #5400

Closed deuszx closed 1 year ago

deuszx commented 1 year ago

After upgrading network to WeightsV2, my frontend code started to fail with the following errors

Uncaught (in promise) Error: Your runtime does not expose the api.call.contractsApi.call runtime interfaces
    at new Base (Base.js:13:1)
    at new Contract (Contract.js:33:1)
    at new ContractPromise (index.js:18:1)
    at getPostsAuthors (getPostsAuthors.ts:18:1)
    at async getAllPostsAuthors (BulletinBoard.tsx:51:1)

link to the repository.

  1. Network running ink3, contracts deployed, custom frontend (built with polkadot.js) working.
  2. Network migrated to ink4, contracts deployed, custom frontend (built with polkadot.js) not working.
  3. ContractsUI connected to that same network capable of interacting with the contracts and the chain.

    • Version:

    • Environment:

    • [ ] Node.js

    • [ ] Browser

    • [ ] Other (limited support for other environments)

    • Language:

    • [ ] JavaScript

    • [x] TypeScript ("typescript": "^4.8.4")

    • [ ] Other

jacogr commented 1 year ago

It literally means what it says - the chain you are connecting to does not expose the runtime interfaces required. See the explict check -

https://github.com/polkadot-js/api/blob/114050f893344dc538f057642de84466bd76b129/packages/api-contract/src/base/Base.ts#L27-L29

It either means -

(a) it is a non-contract chain (e.g. Polkadot/Kusama/etc - a chain explicitly needs to have the contracts pallet included in the on-chain runtime) (b) it is an old version of the chain without the newer runtime interfaces (unlikely) (c) runtime misconfiguration if the pallet is indeed meant to be exposed

deuszx commented 1 year ago

Yes, I saw the Base.ts but I don't think that's the problem I'm having.

My setup:

  1. The contracts and fronted (built with polkadotjs) were working correctly with ink3.
  2. Network has been migrated to ink4.
  3. Deployment and interactions with the contracts work through the ContractsUI.

Given that:

deuszx commented 1 year ago

I think I've found the reason why it keeps working with ContractsUI https://github.com/paritytech/substrate/pull/12358

deuszx commented 1 year ago

My chain is exposing that interface though @jacogr , see https://github.com/Cardinal-Cryptography/aleph-node/blob/main/bin/runtime/src/lib.rs#L924

jacogr commented 1 year ago

Yes, the RPCs are completely unused since they are deprecated/removed in Substrate. So the API only uses the state call interfaces directly.

deuszx commented 1 year ago

Tell me, please, if I get the exact same error when running substrate-contracts-node from https://github.com/paritytech/substrate-contracts-node/releases/tag/v0.22.1 and

"@polkadot/api": "^9.11.1",
"@polkadot/api-contract": "^9.11.1",

Wouldn't that mean it's not the problem with my chain but the library?

Error:

Uncaught (in promise) Error: Your runtime does not expose the api.call.contractsApi.call runtime interfaces
    at new Base (Base.js:13:1)
    at new Contract (Contract.js:33:1)
    at new ContractPromise (index.js:18:1)
    at getHighlightedPostsAuthors (getHighlightedPostsAuthors.ts:20:1)
deuszx commented 1 year ago

@jacogr , turns out that the error was caused by invalid version of npm -- failed on npm @ 9.1.1 but is "working" on 8.19.3.

polkadot-js-bot commented 1 year ago

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.