dedotdev / dedot

Delightful JavaScript client for Polkadot & Substrate
https://dedot.dev
Apache License 2.0
30 stars 4 forks source link

feat(api): add `getRuntimeVersion` to clients #199

Closed sinzii closed 1 month ago

sinzii commented 1 month ago

Closes #196

This new async version of getRuntimeVersion will ensure that the runtime upgrade process is done (download metadata, setup registry, caching ...) before returning the value. Helpful when we want to prepare for runtime upgrades.

So the process of preparing for new runtime upgrades would look like this:

const client = await DedotClient<OldApi>.new(...)
const runtimeVersion = await client.getRuntimeVersion();

if (runtimeVersion.specVersion === NEW_SPEC_VERSION) {
   // casting the client to using the NewApi interface, generated from the new metadata
   const newClient: DedotClient<NewApi> = api as any; 
   newClient.tx.pallet.new_tx_call(...)
} else {
   client.tx.pallet.old_tx_call(...)
}

Pending some specs to verify the logics