fuels-ts icon indicating copy to clipboard operation
fuels-ts copied to clipboard

Map `not enough coins to fit the target` error

Open arboleya opened this issue 1 year ago • 4 comments

Errors like not enough coins to fit the target don't seem obvious to users:

  • https://forum.fuel.network/t/fuelerror-not-enough-coins-to-fit-the-target/5818/2
  • https://forum.fuel.network/t/creating-a-fuel-dapp-using-provided-example-in-docs/5796/1

We should consider mapping this one even before we get to https://github.com/FuelLabs/fuels-ts/issues/2467.

[!NOTE] Should be done after:

  • https://github.com/FuelLabs/fuels-ts/issues/2521

arboleya avatar Jun 15 '24 10:06 arboleya

The reason for causing this issue is because of the deployer or the provider has 0 tokens at first. Hence I think to fix it is to use generateTestWallet. However currently, the importation doesn't work forum.

P.S. The current fuel dApp in Typescript SDK uses local node.

import { NODE_URL } from "../../lib";
import { Provider, Wallet, WalletUnlocked, Signer } from "fuels";
import { useState } from "react";
import useAsync from "react-use/lib/useAsync";
// import { generateTestWallet } from '@fuel-ts/account/test-utils';

export const useFaucet = () => {
  const [faucetWallet, setFaucetWallet] = useState<WalletUnlocked>();

  useAsync(async () => {
    if (!faucetWallet) {
      const provider = await Provider.create(NODE_URL);
      const wallet = Wallet.fromPrivateKey("0x01", provider);
      const signer = new Signer("0x01");
      const balances: CoinQuantity[] = await wallet.getBalances();
      console.log('Local Provider address', signer)
      setFaucetWallet(wallet);
    }
  }, [faucetWallet]);

  return {
    faucetWallet,
  };
};

goheesheng avatar Jun 18 '24 03:06 goheesheng

I'd like to close this in favour of #2467, I also don't think this is required for mainnet as we don't map any of the other VM errors. @FuelLabs/sdk-ts

danielbate avatar Jul 16 '24 15:07 danielbate

I was hoping we could squeeze this in because it's been more prevalent, but you also have a point.

Maybe we can give it another week or so and then deprioritize it in case we can't get it across the line.

arboleya avatar Jul 16 '24 17:07 arboleya

@danielbate whilst I agree that this would be an exceptional use case in terms of mapping a VM error, the fact that other consumers have been perplexed by it suggests to me that we should consider the DX when this error is thrown. My personal opinion is that they should be directed to the faucet when this error is thrown, but that would require it to be mapped first.

maschad avatar Jul 16 '24 18:07 maschad