Cant call mint function for token

I have token that has mint functionality, and when I call mint function I keep getting this error

 mint = async (assetId?: string) => {
    if (assetId == null || this.alreadyMintedTokens.includes(assetId)) return;
    this._setLoading(true);
    const { accountStore, notificationStore } = this.rootStore;
    const { address } = accountStore;
    if (address == null || window?.fuel == null) return;

    const wallet = Wallet.fromAddress(address, window.fuel?.getProvider());
    console.log(assetId);
    const tokenContract = TokenAbi__factory.connect(assetId, wallet);

    try {
      const v = await tokenContract.functions
        .mint()
        .txParams({ gasPrice: 1 })
        .call();
      console.log(v);
      this.setAlreadyMintedTokens([...this.alreadyMintedTokens, assetId]);
      await this.rootStore.accountStore.updateAccountBalances();
    } catch (e) {
      console.log(e);
      notificationStore.notify(
        `You have already minted ${TOKENS_BY_ASSET_ID[assetId].symbol}`,
        { type: "error" }
      );
    } finally {
      this._setLoading(false);
    }
  };

this is the error

TypeError: this.provider.getResourcesToSpend is not a function
    at P.getResourcesToSpend (base-locked-wallet.ts:81:1)
    at S.fundWithRequiredCoins (base-invocation-scope.ts:165:1)
    at S.prepareTransaction (base-invocation-scope.ts:114:1)
    at S.getTransactionRequest (base-invocation-scope.ts:199:1)
    at S.call (base-invocation-scope.ts:213:1)
    at FaucetVM.mint (FaucetVm.tsx:128:1)
    at executeAction (action.ts:68:1)
    at FaucetVM@11.mint (action.ts:49:1)
    at onClick (TokensFaucetTable.tsx:92:1)
    at HTMLUnknownElement.callCallback (react-dom.development.js:4164:1

It used to work fine before, I have updated fuels and fuels-wallet packages to 0.29.1 version and

Can you share the repo and branch to reproduce this?

sure,
here is link to func declaration

is there any updates?)

Do the other functions work and this is the only one where you get this error?

every call or simulate function fails with this error

Can you try deleting node_modules and try re-installing? It seems to be working on our end.

I did this yesterday before crated topic and now also did it now to be sure all is same. It still keeps giving error

TypeError: this.provider.getResourcesToSpend is not a function
    at P.getResourcesToSpend (base-locked-wallet.ts:81:1)
    at S.fundWithRequiredCoins (base-invocation-scope.ts:165:1)
    at S.prepareTransaction (base-invocation-scope.ts:114:1)
    at S.getTransactionRequest (base-invocation-scope.ts:199:1)
    at S.call (base-invocation-scope.ts:213:1)
    at FaucetVM.mint (FaucetVm.tsx:124:1)
    at executeAction (action.ts:68:1)
    at FaucetVM@13.mint (action.ts:49:1)
    at onClick (TokensFaucetTable.tsx:92:1)
    at HTMLUnknownElement.callCallback (react-dom.development.js:4164:1)

I have found another of creating token contract instance and changed it to this one, but error is still same


import token_abi from "./token_abi.json"

mint = async (assetId?: string) => {
    if (assetId == null || this.alreadyMintedTokens.includes(assetId)) return;
    this._setLoading(true);
    const { accountStore, notificationStore } = this.rootStore;
    const { address } = accountStore;
    if (address == null || window?.fuel == null) return;
 

    const wallet = Wallet.fromAddress(address, window.fuel?.getProvider());  
    const tokenContract = new Contract(assetId, token_abi, wallet);

    try {
   //i have changed here !
      const { transactionId, value } = await tokenContract.functions
        .mint()
        .txParams({ gasPrice: 1 })
        .call();
      console.log(value, transactionId);
      this.setAlreadyMintedTokens([...this.alreadyMintedTokens, assetId]);
    } catch (e) {
      console.log(e);
    } finally {
      this._setLoading(false);
    }
  };

Here is list of token addresses that I want to mint

{
    "name": "Bitcoin",
    "symbol": "BTC",
    "decimals": 8,
    "assetId": "0xdd17dda6eeee55f6d327020e6d61b9fa7b3c2ab205c46cdca690a46966f4e1c7"
  },
  {
    "name": "USDC",
    "symbol": "USDC",
    "decimals": 6,
    "assetId": "0xd7d5e5c1220872e6f42b38f85ae80c6072b1b4723e7a7218bbf6717aca962536"
  },
  {
    "name": "Uniswap",
    "symbol": "UNI",
    "decimals": 9,
    "assetId": "0x76c4fda9074c4509eaf2652f82bace86e2c7a21bf9faff7bf6228034ebc0f8a2"
  },
  {
    "name": "Chainlink",
    "symbol": "LINK",
    "decimals": 9,
    "assetId": "0x71be783354a9bccfa9de0e7edf291797775e4a730d0922a9675258dbb47f557b"
  },
  {
    "name": "Sway",
    "symbol": "SWAY",
    "decimals": 9,
    "assetId": "0x99075448d291a8f8f69e5f3d25a309c38ad38def9f709a69ae4a2aeaed1701fe"
  }

rpc link I use this - https://node-beta-2.fuel.network/graphql

also funny note!

every time when I mint tokes for just created address my Fuel wallet extension is breaking down and showing only black screen


@stacio please have a look, might be something wrong with token standard
link to token standard - GitHub - sway-gang/fuel-token-standard: Fuel network Fungible token standard

We have updated our API to get the provider, and it now returns a promise. it would require you to change the code;

from;

const wallet = Wallet.fromAddress(address, window.fuel?.getProvider());

to;

const provider = await window.fuel?.getProvider();
const wallet = Wallet.fromAddress(address, provider);
// or better now
const wallet = await window.fuel?.getWallet(address);

thanks fo help! it worked, but I have faced another problem with this error

Error: Window closed by inactivity after 5 minutes!

But my window was opened only for 10 seconds

Do you have an example for testing this? I think the issue is related to the custom token as mint will return a token we don’t have on the assets list.

I don’t have deployed version of code that I am trying to create yet, but I have tested with account that doesn’t have any other tokens except testEth, and yes, problem is exactly in this
:frowning:

Looking forward for this feature implementation

Is there any estimation when it will be done?)

:sweat_smile::zap::innocent:

@sway This is one of our priorities. We should have it in a couple of days.

Hello @stacio
I have noticed that team has updated @fuel-wallet/sdk package to 0.5.1 version and tried to run same code above with changed api way, so it look like this now

const wallet = window.fuel?.getWallet(this.address);
const marketContract = MarketAbi__factory.connect(
          CONTRACT_ADDRESSES.market,
          wallet
        );
const tx = await market.functions
      .supply_base()
      .callParams({
        forward: {
          amount: this.tokenAmount.toString(),
          assetId: this.baseToken.assetId,
        },
      })
      .txParams({ gasPrice: 1 })
      .call();

but it still fails with same “5 minutes not interaction” error