FuelLabs / fuels-ts

Fuel Network Typescript SDK
https://docs.fuel.network/docs/fuels-ts/
Apache License 2.0
44.4k stars 1.32k forks source link

NodeModules:Unable to import ‘generateTestWallet’ #2617

Open goheesheng opened 1 week ago

goheesheng commented 1 week ago

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)
maschad commented 6 days ago

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 fuels@0.89.2 and @fuel-ts/account@0.90.0 ( since there was previously this issue in @fuel-ts/account@0.89.2) .

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.