TypeError: provider.getGasConfig is not a function

Hi guys!

After updating fuels to 0.62.0 all my code for Swaylend and Spark project stopped working.
Main error that I get when try to call any smart contract is “TypeError: provider.getGasConfig is not a function”

Here is AccountStore where I keep my connection with Fuel Wallet]

import RootStore from "@stores/RootStore";
import { makeAutoObservable, reaction, when } from "mobx";
import { Address, Provider, Wallet, WalletLocked, WalletUnlocked } from "fuels";
import { IToken, NODE_URL, TOKENS_LIST } from "@src/constants";
import Balance from "@src/entities/Balance";
import BN from "@src/utils/BN";
import { FuelWalletProvider } from "@fuel-wallet/sdk";

export enum LOGIN_TYPE {
  FUEL_WALLET = "FUEL_WALLET",
  FUELET = "FUELET",
}

export interface ISerializedAccountStore {
  address: string | null;
  loginType: LOGIN_TYPE | null;
}

class AccountStore {
  public readonly rootStore: RootStore;
  public provider: Provider | null = null;
  private setProvider = (provider: Provider | null | any) =>
    (this.provider = provider);

  constructor(rootStore: RootStore, initState?: ISerializedAccountStore) {
    makeAutoObservable(this);

    this.rootStore = rootStore;
    if (initState) {
      this.setLoginType(initState.loginType);
      this.setAddress(initState.address);
      if (initState.loginType != null) {
        document.addEventListener("FuelLoaded", this.onFuelLoaded);
      }
    }
    this.initProvider();
    when(() => this.provider != null, this.updateAccountBalances);
    setInterval(this.updateAccountBalances, 10 * 1000);
    reaction(
      () => this.address,
      () => Promise.all([this.updateAccountBalances()])
    );
  }

  initProvider = async () => {
    Provider.create(NODE_URL)
      .then((provider) => this.setProvider(provider))
      .catch(console.error);
  };

  onFuelLoaded = () => {
    if (this.walletInstance == null) return;
    this.walletInstance.on(
      window?.fuel.events.currentAccount,
      this.handleAccEvent
    );
    this.walletInstance.on(
      window?.fuel.events?.network,
      this.handleNetworkEvent
    );
  };
  handleAccEvent = (account: string) => this.setAddress(account);

  handleNetworkEvent = (network: FuelWalletProvider) => {
    if (network.url !== NODE_URL) {
      this.rootStore.notificationStore.toast(
        `Please change network url to Testnet Beta 4`,
        {
          copyTitle: "Copy beta-4 RPC",
          copyText: NODE_URL,
          type: "error",
          title: "Attention",
        }
      );
    }
  };

  public address: string | null = null;
  setAddress = (address: string | null) => (this.address = address);

  public privateKey: string | null = null;
  setPrivateKey = (key: string | null) => (this.privateKey = key);

  public loginType: LOGIN_TYPE | null = null;
  setLoginType = (loginType: LOGIN_TYPE | null) => (this.loginType = loginType);

  public assetBalances: Balance[] | null = null;
  setAssetBalances = (v: Balance[] | null) => (this.assetBalances = v);

  updateAccountBalances = async () => {
    if (this.address == null) {
      this.setAssetBalances([]);
      return;
    }
    const address = Address.fromString(this.address);
    const balances = (await this.provider?.getBalances(address)) ?? [];
    const assetBalances = TOKENS_LIST.map((asset) => {
      const t = balances.find(({ assetId }) => asset.assetId === assetId);
      const balance = t != null ? new BN(t.amount.toString()) : BN.ZERO;
      if (t == null)
        return new Balance({ balance, usdEquivalent: BN.ZERO, ...asset });

      return new Balance({ balance, ...asset });
    });
    this.setAssetBalances(assetBalances);
  };
  findBalanceByAssetId = (assetId: string) =>
    this.assetBalances &&
    this.assetBalances.find((balance) => balance.assetId === assetId);

  get balances() {
    const { accountStore } = this.rootStore;
    return TOKENS_LIST.map((t) => {
      const balance = accountStore.findBalanceByAssetId(t.assetId);
      return balance ?? new Balance(t);
    })
      .filter((v) => v.usdEquivalent != null && v.usdEquivalent.gt(0))
      .sort((a, b) => {
        if (a.usdEquivalent == null && b.usdEquivalent == null) return 0;
        if (a.usdEquivalent == null && b.usdEquivalent != null) return 1;
        if (a.usdEquivalent == null && b.usdEquivalent == null) return -1;
        return a.usdEquivalent!.lt(b.usdEquivalent!) ? 1 : -1;
      });
  }

  serialize = (): ISerializedAccountStore => ({
    address: this.address,
    loginType: this.loginType,
  });

  login = async (loginType: LOGIN_TYPE) => {
    this.setLoginType(loginType);
    await this.loginWithWallet();
    await this.onFuelLoaded();
  };

  get walletInstance() {
    switch (this.loginType) {
      case LOGIN_TYPE.FUEL_WALLET:
        return window.fuel;
      case LOGIN_TYPE.FUELET:
        return window.fuelet;
      default:
        return null;
    }
  }

  disconnect = async () => {
    try {
      this.walletInstance.disconnect();
    } catch (e) {
      this.setAddress(null);
      this.setLoginType(null);
    }
    this.setAddress(null);
    this.setLoginType(null);
  };

  loginWithWallet = async () => {
    if (this.walletInstance == null)
      throw new Error("There is no wallet instance");
    // const res = await this.walletInstance.connect({ url: NODE_URL });
    const res = await this.walletInstance.connect();
    if (!res) {
      this.rootStore.notificationStore.toast("User denied", {
        type: "error",
      });
      return;
    }
    const account = await this.walletInstance.currentAccount();
    const provider = await this.walletInstance.getProvider();
    if (provider.url !== NODE_URL) {
      this.rootStore.notificationStore.toast(
        `Please change network url to beta 4`,
        {
          copyTitle: "Copy beta-4 RPC",
          copyText: NODE_URL,
          type: "error",
          title: "Attention",
        }
      );
    }
    this.setAddress(account);
  };

  getFormattedBalance = (token: IToken): string | null => {
    const balance = this.findBalanceByAssetId(token.assetId);
    if (balance == null) return null;
    return BN.formatUnits(balance.balance ?? BN.ZERO, token.decimals).toFormat(
      2
    );
  };
  getBalance = (token: IToken): BN | null => {
    const balance = this.findBalanceByAssetId(token.assetId);
    if (balance == null) return null;
    return BN.formatUnits(balance.balance ?? BN.ZERO, token.decimals);
  };

  get isLoggedIn() {
    return this.address != null;
  }

  getWallet = async (): Promise<WalletLocked | WalletUnlocked | null> => {
    if (this.address == null || window.fuel == null) return null;
    return window.fuel.getWallet(this.address);
  };

  get walletToRead(): WalletLocked | null {
    return this.provider == null
      ? null
      : Wallet.fromAddress(
          "fuel1m56y48mej3366h6460y4rvqqt62y9vn8ad3meyfa5wkk5dc6mxmss7rwnr",
          this.provider ?? ""
        );
  }

  get addressInput(): null | { value: string } {
    if (this.address == null) return null;
    return { value: Address.fromString(this.address).toB256() };
  }

  get addressB256(): null | string {
    if (this.address == null) return null;
    return Address.fromString(this.address).toB256();
  }
}

export default AccountStore;

And here is the code of the mint function from the multi-token smart and console logs for some of variable to make sure that they are not empty

mint = async (assetId?: string) => {
    console.log("mint assetId", assetId);
    if (assetId == null) return;
    if (this.rootStore.accountStore.loginType === LOGIN_TYPE.FUEL_WALLET) {
      const addedAssets: Array<any> = await window?.fuel.assets();
      if (
        addedAssets != null &&
        !addedAssets.some((v) => v.assetId === assetId)
      ) {
        await this.addAsset(assetId);
      }
    }
    this._setLoading(true);
    this.setActionTokenAssetId(assetId);
    const { accountStore, notificationStore } = this.rootStore;
    const { tokenFactory } = this.rootStore.settingsStore.currentVersionConfig;
    const wallet = await accountStore.getWallet();
    console.log("wallet in mint fn", wallet);
    console.log("provider ", accountStore.provider);
    if (wallet == null) return;
    const tokenFactoryContract = TokenFactoryAbi__factory.connect(
      tokenFactory,
      wallet
    );

    console.log("tokenFactoryContract", tokenFactoryContract);

    try {
      const token = TOKENS_BY_ASSET_ID[assetId];
      const amount = BN.parseUnits(faucetAmounts[token.symbol], token.decimals);
      const hash = hashMessage(token.symbol);
      const userAddress = wallet.address.toB256();

      const { transactionResult } = await tokenFactoryContract.functions
        .mint({ value: userAddress }, hash, amount.toString())
        .txParams({ gasPrice: 2 })
        .call();
      if (transactionResult != null) {
        const token = TOKENS_BY_ASSET_ID[assetId];
        if (token !== TOKENS_BY_SYMBOL.ETH) {
          this.rootStore.settingsStore.addMintedToken(assetId);
        }
        const txId = transactionResult.id ?? "";
        this.rootStore.notificationStore.toast(
          `You have successfully minted ${token.symbol}`,
          {
            link: `${EXPLORER_URL}/transaction/${txId}`,
            linkTitle: "View on Explorer",
            type: "success",
            copyTitle: `Copy tx id: ${centerEllipsis(txId, 8)}`,
            copyText: transactionResult.id,
            title: "Transaction is completed!",
          }
        );
      }
      await this.rootStore.accountStore.updateAccountBalances();
    } catch (e) {
      const errorText = e?.toString();
      console.log(errorText);
      notificationStore.toast(errorText ?? "", { type: "error" });
    } finally {
      this.setActionTokenAssetId(null);
      this._setLoading(false);
    }
  };

AccountStore code - https://github.com/compolabs/sway-lend/blob/fuels-62-fails/frontend/src/stores/AccountStore.ts

Faucet Vm with mint fn - https://github.com/compolabs/sway-lend/blob/fuels-62-fails/frontend/src/screens/Faucet/FaucetVm.tsx

Also, I tried to call a transaction with a wallet instance generated from privateKey and everything worked but not really well, one mint call worked well and the other started to fail with next Error

Error: Transaction is not inserted. Hash is already known: {"response":{"data":null,"errors":[{"message":"Transaction is not inserted. Hash is already known","locations":[{"line":2,"column":3}],"path":["submit"]}],"status":200,"headers":{"map":{"content-type":"application/json"}}},"request":{"query":"mutation submit($encodedTransaction: HexString!) {\n  submit(tx: $encodedTransaction) {\n    id\n  }\n}","variables":{"encodedTransaction":"0x0000000000000000000000000000000200000000009896800000000000000000000000000000001800000000000000a00000000000000002000000000000000c00000000000000010000000000000000000000000000000000000000000000000000000000000000724028a8724428805d451000724828882d41148a2404000000000000000000000000000000000000000000000000000000000000000000000000000000000000d8c627b9cd9ee42e2c2bd9793b13bc9f8e9aad32e25a99ea574f23c1dd17685a00000000812e79b000000000000028d87aa35fdbcd9e3ef68475417f35b7bd6778e7fafa5f0b4b190a353db900183212e26ef19029cc92e234d9457823ca0811b92db9ce9dbf8db99c0fdd75d11338f00000000ba43b74000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000d8c627b9cd9ee42e2c2bd9793b13bc9f8e9aad32e25a99ea574f23c1dd17685a000000000000000043ded2bb3e9b919f819f36be1b727ffc58d0ca43a864cb223957619cc36c461400000000000000017aa35fdbcd9e3ef68475417f35b7bd6778e7fafa5f0b4b190a353db900183212000000001dcd645d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000027aa35fdbcd9e3ef68475417f35b7bd6778e7fafa5f0b4b190a353db90018321200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000408337ea135a8633646cc309445991514dff7aa193b2134882de3a155f2b1abab6d312a7b7f187aafc74c73b3a0f89a47678d97186fb65ba16110e4b0964ba1041"}}}

This error i described here - Error: Transaction is not inserted. Hash is already known:

Wallet version is 0.13.0 -

What version of the @fuel-wallet/sdk are you using also?

I had 0.11.0 before, after updating to the new 0.13.0 this error disappeared, thanks!

Transactions are not going through, but this error is related to the node I guess.

Thanks!

1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.