NodeModules:Unable to import 'generateTestWallet'

Hi, wanted to test out generateTestWallet, but it seems that it doesn’t work even if added into index.d.ts.

import { generateTestWallet } from '@fuel-ts/account/test-utils';
or 
import { generateTestWallet } from 'fuels';

Tried to fix it, but still doesn’t work:

node_modules/@fuel-ts/account/dist/index.d.ts
import './test-utils.js';
import './configs.js';
export * from './account';
export * from './wallet';
export * from './hdwallet';
export * from './mnemonic';
export * from './wordlists';
export * from './signer';
export * from './wallet-manager';
export * from './predicate';
export * from './providers';
export * from './connectors';
export * from './test-utils'; // added but doesn't work
//# sourceMappingURL=index.d.ts.map

Error Message:

Module '"fuels"' has no exported member 'generateTestWallet'.ts(2305)
2 Likes

Hi @eesheng :wave:

Could you share your package.json file please?

3 Likes
{
  "name": "fuelswapv1",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "@fuels/connectors": "^0.5.0",
    "@fuels/react": "^0.20.0",
    "@radix-ui/react-accordion": "^1.1.2",
    "@radix-ui/react-label": "^2.0.2",
    "@radix-ui/react-navigation-menu": "^1.1.4",
    "@tanstack/react-query": "^5.45.0",
    "class-variance-authority": "^0.7.0",
    "clsx": "^2.1.1",
    "flowbite": "^2.3.0",
    "flowbite-react": "^0.9.0",
    "fuels": "^0.89.2",
    "lucide-react": "^0.395.0",
    "next": "14.2.4",
    "next-themes": "^0.3.0",
    "radix-ui": "^1.0.1",
    "react": "^18",
    "react-dom": "^18",
    "react-hot-toast": "^2.4.1",
    "react-use": "^17.5.0"
  },
  "devDependencies": {
    "@types/node": "^20",
    "@types/react": "^18",
    "@types/react-dom": "^18",
    "autoprefixer": "^10.4.19",
    "eslint": "^8",
    "eslint-config-next": "14.2.4",
    "postcss": "^8.4.38",
    "tailwindcss": "^3.4.4",
    "typescript": "^5"
  }
}

1 Like

Thanks @eesheng.

You can access the generateTestWallet via the fuels/test-utils namespace.

import { generateTestWallet } from 'fuels/test-utils';
1 Like

HI it doesn’t work

Cannot find module 'fuels/test-utils' or its corresponding type declarations.ts(2307

Apologies, potentially that change is awaiting release.

Could you try using the following import:

import { generateTestWallet } from '@fuel-ts/account/test-utils';

You will need to install the @fuel-ts/account package.

Still doesn’t work, Could not find a declaration file for module '@fuel-ts/account/test-utils'.

This is my package.json when I ran the command pnpm install @fuel-ts/account

{
  "name": "fuelswapv1",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "@fuel-ts/account": "^0.89.2",
    "@fuels/connectors": "^0.5.0",
    "@fuels/react": "^0.20.0",
    "@radix-ui/react-accordion": "^1.1.2",
    "@radix-ui/react-label": "^2.0.2",
    "@radix-ui/react-navigation-menu": "^1.1.4",
    "@tanstack/react-query": "^5.45.0",
    "class-variance-authority": "^0.7.0",
    "clsx": "^2.1.1",
    "flowbite": "^2.3.0",
    "flowbite-react": "^0.9.0",
    "fuels": "^0.89.2",
    "lucide-react": "^0.395.0",
    "next": "14.2.4",
    "next-themes": "^0.3.0",
    "radix-ui": "^1.0.1",
    "react": "^18",
    "react-dom": "^18",
    "react-hot-toast": "^2.4.1",
    "react-use": "^17.5.0"
  },
  "devDependencies": {
    "@types/node": "^20",
    "@types/react": "^18",
    "@types/react-dom": "^18",
    "autoprefixer": "^10.4.19",
    "eslint": "^8",
    "eslint-config-next": "14.2.4",
    "postcss": "^8.4.38",
    "tailwindcss": "^3.4.4",
    "typescript": "^5"
  }
}

When will the release be out?

This is my mistake - I created the following issue, which has been resolve in #2548. This has been released with v0.90.0.

Hi, is there an update going on? Not sure why it doesn’t work and the documentation page is down https://docs.fuel.network/docs/fuels-ts/wallets/test-wallets/#setting-up-test-wallets

This is the code and I am running the local fuel node.

import { NODE_URL } from "../../lib";
import { Provider, Wallet, WalletUnlocked, Signer, CoinQuantity,  } from "fuels";
import { generateTestWallet } from '@fuel-ts/account/test-utils';
import { useState } from "react";
import useAsync from "react-use/lib/useAsync";
export const useFaucet = () => {
  const [faucetWallet, setFaucetWallet] = useState<WalletUnlocked>();

  useAsync(async () => {
    if (!faucetWallet) {
      const provider = await Provider.create(NODE_URL);
      const baseAssetId = provider.getBaseAssetId();
      const myWallet: WalletUnlocked = await generateTestWallet(provider, [[10, baseAssetId]]);
      const signer = new Signer("0x01");
      const balances: CoinQuantity[] = await myWallet.getBalances();
      console.log('Local Provider address', signer)
      console.log('Local Provider Balances', balances)

      setFaucetWallet(myWallet);
    }
  }, [faucetWallet]);

  return {
    faucetWallet,
  };
};

Error:

 Property '#private' in type 'Provider' refers to a different member that cannot be accessed from within type 'Provider'.ts(2345)
1 Like

Hey @eesheng,

Apologies for the late reply, did you manage to resolve this issue?

If you have not, could you add an issue for this and we can triage it accordingly.

1 Like

Hey @eesheng! Where did you find that link to the docs?

Hi the docs page has been updated and removed.

Hi @eesheng I’ve responded to the related issue you raised here

For the use case you have presented generateTestWallet would not be appropriate. We are moving away from generateTestWallet in favour of more explicit resource management through launchTestNode , you can read more here

Given you want to instantiate a wallet in the browser though I recommend you follow this guide

Please let us know if this resolves your issue.

  1. Let say I generate a new wallet const unlockedWallet: WalletUnlocked = Wallet.generate();, do I still need to connect to a provider?

  2. How do you add faucets to our locally instantiated wallets? Not the connected provider

@eesheng I’d just like to re-iterate that it seems for your use case generateTestWallet is not appropriate, as it primarily for unit tests. Also, we are going to be deprecating that utility in short order in favour of launchTestNode

You should either install a browser wallet or instantiate a browser wallet as shown here with useBrowserWallet

  1. Let say I generate a new wallet const unlockedWallet: WalletUnlocked = Wallet.generate();, do I still need to connect to a provider?

More than likely any wallet you generate you will want to interact with the chain, and thus that would require connecting to a provider, which can be passed in as a parameter to the generate function.

  1. How do you add faucets to our locally instantiated wallets? Not the connected provider

I’m not sure I understand the question, if you would like to send testnet assets to a generated wallet then you can send it to that wallet’s address.

1 Like