Skip to content

Add documentation for package importing AST gotcha  #234

Open
@robGetsTheJobDoneAE

Description

@robGetsTheJobDoneAE

When using mono repo style dependencies and possibly other dependencies, it is possible that the built AST does not properly include an imported package.

The following example failed to include "@starving/contracts/dist/typechain-types"

import Nullstack from "nullstack";
import base from "@starving/contracts/dist/typechain-types";
import ethers from "ethers";
class Account extends Nullstack {
  hydrate() {
    this.connectWallet();
  }
  async connectWallet() {
    console.log(base.ERC165__factory);
    const factory = await new base.Tap__factory();

    factory.attach("").requestTokens();
    const fact = await factory.deploy();

    const provider = new ethers.providers.JsonRpcProvider();
    const tokenContract = new tap(nftAddress, NFT.abi, provider);
    const marketContract = new ethers.Contract(
      nftMarketAddress,
      Market.abi,
      provider
    );
    const data = await marketContract.fetchMarketItems();
  }
  getTap() {
    return 1.354;
  }

  getAddress() {
    return "0x5a773...6f57c0";
  }

  render() {
    return (
      <div style="" class="flex justify-end">
        <div class="flex items-center">
          <div class="max-w-[14px] max-h-[17px]">
            <img src="tap.png" class="object-cover"></img>
          </div>
          <div class="pl-2 text-sm flex flex-col items-center">
            <span class="font-bold">
              {this.getTap()}{" "}
              <span class="text-shadow-white font-medium">TAP</span>
            </span>
            <div>
              <span class="text-shadow-white">{this.getAddress()}</span>
            </div>
          </div>
        </div>
        <div class="flex items-center pl-10">
          <div class="max-w-[14px] max-h-[17px]">
            <img src="account_circle.png" class="object-cover"></img>
          </div>
          <span class="pl-2 font-bold"> My account</span>
        </div>
      </div>
    );
  }
}

export default Account;

This was fixed by importing @starving/contracts/dist/typechain-types in the server.js file

import Nullstack from "nullstack";
import Application from "./src/Application";
import { StavingChildrenNft__factory } from "@starving/contracts/dist/typechain-types/factories/contracts/Nft.sol/StavingChildrenNft__factory";

const context = Nullstack.start(Application);

context.start = async function start() {
  console.log(StavingChildrenNft__factory);
  // https://nullstack.app/application-startup
};

export default context;

Metadata

Metadata

Assignees

No one assigned

    Labels

    tutorialTutorial request for the Nullstack blog

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions