Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation for package importing AST gotcha #234

Open
robGetsTheJobDoneAE opened this issue Jul 15, 2022 · 0 comments
Open

Add documentation for package importing AST gotcha #234

robGetsTheJobDoneAE opened this issue Jul 15, 2022 · 0 comments
Labels
tutorial Tutorial request for the Nullstack blog

Comments

@robGetsTheJobDoneAE
Copy link

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;

@Mortaro Mortaro added the tutorial Tutorial request for the Nullstack blog label Aug 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tutorial Tutorial request for the Nullstack blog
Projects
None yet
Development

No branches or pull requests

2 participants