2

I'm trying to generate type interfaces using definitions directly from Substrate and ORML libraries. I'm using the polkadotjs package versions 8.1.1.

My type generate file looks like:

import * as ormlDefinitions from '@open-web3/orml-types/interfaces/definitions';

// import fs from 'fs';
import { generateDefaultConsts, generateDefaultQuery, generateDefaultRpc, generateDefaultTx } from '@polkadot/typegen/generate';
import { generateInterfaceTypes } from '@polkadot/typegen/generate/interfaceRegistry';
import { generateTsDef } from '@polkadot/typegen/generate/tsDef';
import * as defaultDefinitions from '@polkadot/types/interfaces/definitions';

// import * as webbDefinitions from '../src/interfaces/definitions.js';
import metadata from '../src/metadata/static-latest.js';

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { runtime: _runtime, ...ormlModulesDefinitions } = ormlDefinitions;

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { runtime, ...substrateDefinitions } = defaultDefinitions;

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const definitions = {
  '@open-web3/orml-types/interfaces': ormlModulesDefinitions,
  '@polkadot/types/interfaces': substrateDefinitions
  // '@webb-tools/types/interfaces': webbDefinitions
} as any;

generateTsDef(definitions, 'packages/types/src/interfaces', '@webb-tools/types/interfaces');
generateInterfaceTypes(definitions, 'packages/types/src/interfaces/augment-types.ts');
generateDefaultConsts('packages/types/src/interfaces/augment-api-consts.ts', metadata, definitions, false);

generateDefaultTx('packages/types/src/interfaces/augment-api-tx.ts', metadata, definitions, false);
generateDefaultQuery('packages/types/src/interfaces/augment-api-query.ts', metadata, definitions, false);
generateDefaultRpc('packages/types/src/interfaces/augment-api-rpc.ts', definitions);

Even without our custom types, I'm stuck getting this to execute and generate the type files. The errors are due to some undefined parameters.

packages/types/src/interfaces/types.ts
    Generating
TypeError: Cannot convert undefined or null to object
    at Function.entries (<anonymous>)
    at file:///Users/drew/webb/webb.js/node_modules/@polkadot/typegen/generate/tsDef.js:295:12
    at writeFile (file:///Users/drew/webb/webb.js/node_modules/@polkadot/typegen/util/file.js:9:19)
    at generateTsDef (file:///Users/drew/webb/webb.js/node_modules/@polkadot/typegen/generate/tsDef.js:293:3)
    at file:///Users/drew/webb/webb.js/packages/types/scripts/generate.ts:42:1
    at ModuleJob.run (node:internal/modules/esm/module_job:195:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:337:24)
    at async loadESM (node:internal/process/esm_loader:88:5)
    at async handleMainPromise (node:internal/modules/run_main:61:12)

Any ideas how to add custom type libraries and generate from metadata? Is there some tutorial available against up-to-date dependencies?

2
  • More confusing is that the generated type files contain: '@open-web3/orml-types/interfaces/__esModule' as imported packages, and yet this package is pulling types from our runtime and not ORML.
    – Drew Stone
    Apr 17, 2022 at 13:58
  • For this comment above, this is what is generated: import type { Perbill, Permill, WebbProposalsHeaderTypedChainId } from '@open-web3/orml-types/interfaces/__esModule'; My Query/TX auto-generated files look OK but my types are not in the type file. I have updated our metadata but not sure if I should start defining our types directly in the type-definitions?
    – Drew Stone
    Apr 17, 2022 at 14:15

1 Answer 1

2

There is a tutorial on generating type definitions here:

And some sample code here:

1

Your Answer

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

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