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

NodeModules:Unable to import ‘generateTestWallet’ #2617

Open
goheesheng opened this issue Jun 25, 2024 · 1 comment
Open

NodeModules:Unable to import ‘generateTestWallet’ #2617

goheesheng opened this issue Jun 25, 2024 · 1 comment
Assignees
Labels
awaiting We need further input from the author bug Issue is a bug triage Issue needs to be triaged

Comments

@goheesheng
Copy link

goheesheng commented Jun 25, 2024

What version of fuels-ts are you using?

^0.89.2

Steps to Reproduce

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,
  };
};

This is the forum post: https://forum.fuel.network/t/nodemodules-unable-to-import-generatetestwallet/5859

Expected Behavior

Able to use generateTestWallet and create a test wallet variable

Actual Behavior

Error:

 Property '#private' in type 'Provider' refers to a different member that cannot be accessed from within type 'Provider'.ts(2345)
@goheesheng goheesheng added the bug Issue is a bug label Jun 25, 2024
@maschad maschad added the triage Issue needs to be triaged label Jun 25, 2024
@maschad maschad self-assigned this Jun 25, 2024
@maschad
Copy link
Member

maschad commented Jun 26, 2024

Hey @goheesheng thanks for raising this issue.

I'm sorry for the inconvenience caused here, we removed that documentation in release 0.90.0 but I think was an error on our part. So we should re-introduce it.

That being said, we use the generateTestWallet utility for test suites in node. If you would like to generate a test wallet in the browser I would recommend that you use the Wallet.generate method. e.g.

 	const provider = await Provider.create(NODE_URL);
    wallet = Wallet.generate({ provider });

    localStorage.setItem('my-wallet-pk', wallet.privateKey);

For more information, you can read here

I was able to reproduce the issue you are facing locally, the error you're encountering is due to a version mismatch between the Provider types from different versions of the @fuel-ts/account package i.e. you're using [email protected] and @fuel-ts/[email protected] ( since there was previously this issue in @fuel-ts/[email protected]) .

Regardless your setup is correct if you are testing in node, you can find a code snippet here

Please let me know if this resolves your issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting We need further input from the author bug Issue is a bug triage Issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

2 participants