question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No type generation for library

See original GitHub issue

I have the following library/contract file:

// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0 <0.9.0;

import "./Kiosk.sol";
import "./SnackbarToken.sol";
import "@openzeppelin/contracts/utils/Counters.sol"; // used in Registry
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol"; // used in Registry
import "@openzeppelin/contracts/utils/structs/EnumerableMap.sol"; // used in Registry

library KioskDeployer {
    function deployKiosk(address payable treasurer, string memory name, SnackbarToken sck) public returns (address){
        Kiosk kiosk = new Kiosk(treasurer, name, sck);
        return address(kiosk);
    }
}

contract Registry {<contract that uses KioskDeployer>}

My package.json is as follows:

{
  "name": "backend",
  "version": "1.0.0",
  "license": "MIT",
  "scripts": {
    "compile": "truffle compile",
    "generate-types": "yarn compile && typechain --target=truffle-v5 './build/contracts/*.json' --show-stack-traces",
    "generate-types-client": "yarn compile && typechain --target=web3-v1 './build/contracts/*.json'",
    "postinstall": "yarn generate-types && yarn generate-types-client",
    "migrate:clean": "rm -rf ./build/migrations/*",
    "migrate:compile": "yarn migrate:clean && npx tsc -p ./tsconfig.migrate.json --outDir ./build/migrations",
    "migrate": "yarn migrate:compile && truffle migrate",
    "test:clean": "rm -rf ./build/test/*",
    "test:compile": "yarn test:clean && npx tsc -p ./tsconfig.test.json --outDir ./build/test",
    "test:registry": "yarn test:compile && truffle test \"./build/test/registry.js\"",
    "test:kiosk": "yarn test:compile && truffle test \"./build/test/kiosk.js\"",
    "test": "yarn test:compile && truffle test",
    "sizes": "truffle run contract-size",
    "ganache-cli": "ganache-cli -p 7545 --gasLimit=0x1fffffffffffff --allowUnlimitedContractSize -e 1000000000 > /dev/null &",
    "coverage": "yarn test:compile && truffle run coverage",
    "typecheck": "tsc --noEmit"
  },
  "devDependencies": {
    "@openzeppelin/contracts": "^4.6.0",
    "@openzeppelin/test-helpers": "^0.5.15",
    "@typechain/truffle-v5": "^8.0.0",
    "@typechain/web3-v1": "^6.0.0",
    "@types/bn.js": "^5.1.0",
    "@types/chai": "^4.3.0",
    "@types/chai-as-promised": "^7.1.5",
    "@types/deep-equal-in-any-order": "^1.0.1",
    "@types/mocha": "^9.0.0",
    "@types/sinon-chai": "^3.2.8",
    "@types/web3": "^1.2.2",
    "chai-as-promised": "^7.1.1",
    "chai-bn": "^0.3.1",
    "deep-equal-in-any-order": "^1.1.19",
    "ethereum-waffle": "^3.4.4",
    "ganache": "^7.2.0",
    "solidity-coverage": "0.8.0-beta.1",
    "truffle": "^5.5.16",
    "truffle-contract-size": "^2.0.1",
    "truffle-typings": "^1.0.8",
    "typechain": "^8.0.0",
    "typescript": "^4.5.4"
  },
  "dependencies": {
    "truffle-contract-size": "^2.0.1"
  }
}

The whole project (and therefore the package.json) is a modified version of this repo. My issue is that after calling yarn generate-types everything gets types - except for the library KioskDeployer. Putting the library into a separate file does not change anything. Here you can see all generated types:

grafik

As you can see KioskDeployer was successfully compiled.

grafik

I can resupply you with relevant information if you want.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
krzkaczorcommented, Jun 22, 2022

I don’t think so as libraries can’t be instantiated 🤔

Anyway, this is not a TypeChain issue but rather something that you want to discuss on solidity-related chats.

1reaction
ollijonssoncommented, Sep 2, 2022

It would be preferrable if there was a flag --skipEmptyAbis=false

Read more comments on GitHub >

github_iconTop Results From Across the Web

Type definitions are not generated for library mode build #2049
If the issue is related to 1.x -> 2.0 upgrade, read the Migration Guide first. Describe the bug. Type definitions are not generated...
Read more >
How to import a regular javascript library with no type ...
Firstly you need to import it as follows: import * as ldapjs from 'ldapjs';. Next you can instantiate it as follows:
Read more >
TypeScript library tips: Rollup your types! | by Martin Hochel
If you're writing a JavaScript library or application, you'll definitely need some kind of bundler. There are various options on the market, ...
Read more >
FIX - Microsoft Support
Describes several problems that may occur when you try to generate type library information by using the Microsoft.VisualStudio.Shell.
Read more >
typing — Support for type hints — Python 3.11.1 documentation
The Python runtime does not enforce function and variable type annotations ... GenericAlias and the ability to use standard library classes as generic...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found