2

I am getting type as Codec while using api.query.<module><method>. The types should be specific or am i missing something. Is there any way to convert this into the right type.

2 Answers 2

6

Remember that the full types are only available at runtime, i.e. all the endpoints and methods and their types are available in the on-chain runtime via metadata

When operating in a TypeScript environment, this means you would need to apply static types "augmented" for your specific chain - no two Substrate-based chains are the same

The pjs api docs has a section detailing how to apply augmentation.

It has also been covered before in another answer which has code samples which I am shortening below with attribution to the answer linked -

// apply augmentation first, before any usage
import "@polkadot/api-augment"

// normal imports
import { ApiPromise, WsProvider } from "@polkadot/api"

// ... all code with augmented types follow
-3

Take a look at this https://github.com/Supercolony-net/typechain-polkadot, we are working on it, and in the future, there will be a lot of new features!

1
  • 1
    "to improve developers’ experience working with ink! smartcontracts" - this is not an ink! question. Aug 25, 2022 at 14:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.