From 1095ef54ab4e8d2b5e4cbb1314d5388111100f80 Mon Sep 17 00:00:00 2001 From: Anderson Arboleya Date: Fri, 27 Dec 2024 19:14:53 -0300 Subject: [PATCH 01/29] Relief at last --- apps/create-fuels-counter-guide/src/main.tsx | 2 +- apps/demo-typegen/src/demo.test.ts | 4 +- .../snippets/call-parameters/forward.ts | 4 +- .../snippets/call-parameters/gas-fee.ts | 4 +- .../setting-both-parameters.ts | 4 +- .../snippets/configurable-constants.ts | 2 +- .../contracts/snippets/contract-balance.ts | 4 +- .../contracts/snippets/cost-estimation.ts | 8 +- .../deploying-contracts/deployment.ts | 2 +- .../deploying-contracts/get-max-size.ts | 4 +- .../snippets/inter-contract-calls.ts | 2 +- .../guide/contracts/snippets/introduction.ts | 2 +- .../docs/src/guide/contracts/snippets/logs.ts | 2 +- .../snippets/managing-deployed-contracts.ts | 2 +- .../guide/contracts/snippets/methods/call.ts | 2 +- .../contracts/snippets/methods/dry-run.ts | 2 +- .../guide/contracts/snippets/methods/get.ts | 2 +- .../snippets/methods/is-read-only.ts | 2 +- .../contracts/snippets/methods/simulate.ts | 2 +- .../different-contracts-chain-methods.ts | 4 +- .../different-contracts-readonly.ts | 2 +- .../multi-call/different-contracts.ts | 2 +- .../snippets/multi-call/same-contract.ts | 2 +- .../contracts/snippets/proxy-contracts.ts | 2 +- .../override-storage-slots-inline.ts | 2 +- .../storage-slots/override-storage-slots.ts | 2 +- .../add-transfer-multiple-recipients.ts | 6 +- .../add-transfer-single-recipient.ts | 8 +- .../utilities/minted-token-asset-id.ts | 2 +- .../utilities/using-different-wallet.ts | 2 +- .../snippets/utilities/variable-outputs.ts | 2 +- .../cookbook/snippets/combining-utxos.ts | 16 ++- .../snippets/custom-contract-calls.ts | 8 +- .../snippets/deposit-and-withdraw/deposit.ts | 6 +- .../snippets/deposit-and-withdraw/withdraw.ts | 8 +- .../guide/cookbook/snippets/fake-resources.ts | 4 +- .../guide/cookbook/snippets/max-outputs.ts | 6 +- .../right-resubmission.ts | 4 +- .../submitting.ts | 4 +- .../wrong-resubmission.ts | 4 +- .../signing-transactions/predicate.ts | 8 +- .../snippets/signing-transactions/script.ts | 4 +- .../cookbook/snippets/splitting-utxos.ts | 10 +- .../snippets/decrement-counter.ts | 2 +- .../encoding/snippets/encode-and-decode.ts | 2 +- .../snippets/connecting-to-localnode.ts | 2 +- .../snippets/connecting-to-testnet.ts | 4 +- .../configurables/configurable-default.ts | 8 +- .../configurables/configurable-set-data.ts | 8 +- .../cookbook/failure-not-enough-funds.ts | 4 +- .../cookbook/failure-returns-false.ts | 10 +- .../predicates/snippets/cookbook/pre-stage.ts | 8 +- .../snippets/cookbook/transferring-assets.ts | 6 +- .../snippets/custom-transactions.ts | 4 +- .../snippets/deploying-predicates.ts | 4 +- .../snippets/instantiation/multi-args.ts | 2 +- .../snippets/instantiation/simple.ts | 2 +- .../snippets/instantiation/struct-arg.ts | 2 +- .../snippets/methods/create-transfer.ts | 6 +- .../methods/get-resources-to-spend.ts | 8 +- .../snippets/methods/send-transaction.ts | 9 +- .../snippets/methods/simulate-transaction.ts | 12 +- .../predicates/snippets/methods/transfer.ts | 6 +- .../snippets/functionality/get-balances.ts | 2 +- .../functionality/get-base-asset-id.ts | 4 +- .../snippets/functionality/get-blocks.ts | 2 +- .../functionality/get-coins-from-account.ts | 4 +- .../functionality/get-coins-from-provider.ts | 4 +- .../snippets/functionality/get-messages.ts | 2 +- .../get-resources-to-spend-from-account.ts | 4 +- .../get-resources-to-spend-from-provider.ts | 4 +- .../functionality/get-transactions.ts | 2 +- .../src/guide/provider/snippets/pagination.ts | 17 +-- .../snippets/provider-instantiation.ts | 4 +- .../provider/snippets/provider-operations.ts | 2 +- .../provider/snippets/provider-options.ts | 12 +- .../scripts/snippets/deploying-scripts.ts | 2 +- .../scripts/snippets/initialising-scripts.ts | 2 +- .../snippets/script-with-configurable.ts | 2 +- .../scripts/snippets/script-with-main-args.ts | 2 +- .../snippets/transaction-parameters.ts | 2 +- .../policies-from-response.ts | 4 +- .../transaction-request/add-output-coin.ts | 4 +- .../transaction-request/add-predicate.ts | 4 +- .../transaction-request/add-witness.ts | 4 +- .../transaction-request/estimate-and-fund.ts | 2 +- .../transaction-request/fetch-coins.ts | 4 +- .../transaction-request/fetch-resources.ts | 4 +- .../transaction-request/input-contract.ts | 2 +- .../transaction-response/contract-call.ts | 2 +- .../from-submitted-request.ts | 2 +- .../transactions/snippets/transaction.ts | 6 +- .../snippets/address/from-a-public-key.ts | 2 +- apps/docs/src/guide/types/snippets/arrays.ts | 2 +- .../snippets/asset-id/using-an-asset-id-1.ts | 2 +- .../snippets/asset-id/using-an-asset-id-2.ts | 2 +- .../types/snippets/bits512/b512-in-the-sdk.ts | 2 +- .../types/snippets/bits512/echoing-a-b512.ts | 2 +- apps/docs/src/guide/types/snippets/bytes.ts | 2 +- .../snippets/enums/using-enums-of-enums-1.ts | 2 +- .../snippets/enums/using-enums-of-enums-2.ts | 2 +- .../types/snippets/enums/using-sway-enums.ts | 2 +- .../evm-address/using-an-evm-address-1.ts | 2 +- .../evm-address/using-an-evm-address-2.ts | 2 +- .../snippets/native-parameters/address.ts | 2 +- .../snippets/native-parameters/asset-id.ts | 2 +- .../snippets/native-parameters/contract-id.ts | 2 +- .../native-parameters/identity-address.ts | 2 +- .../native-parameters/identity-contract.ts | 2 +- .../snippets/numbers/for-u64-and-u256-3.ts | 2 +- .../snippets/numbers/for-u8-u16-and-u32-1.ts | 2 +- .../snippets/options/example-option-u8.ts | 2 +- .../snippets/options/overview-of-option.ts | 2 +- .../src/guide/types/snippets/raw-slice.ts | 2 +- .../src/guide/types/snippets/std-string.ts | 2 +- apps/docs/src/guide/types/snippets/string.ts | 2 +- apps/docs/src/guide/types/snippets/tuples.ts | 2 +- apps/docs/src/guide/types/snippets/vectors.ts | 2 +- .../snippets/address-conversion/contract.ts | 2 +- .../snippets/address-conversion/wallet.ts | 2 +- .../utilities/snippets/unit-conversion.ts | 2 +- .../guide/utilities/snippets/using-assets.ts | 2 +- .../docs/src/guide/wallets/snippets/access.ts | 2 +- .../wallets/snippets/checking-balances-two.ts | 2 +- .../wallets/snippets/checking-balances.ts | 4 +- ...rypting-and-decrypting-json-wallets-two.ts | 2 +- .../encrypting-and-decrypting-wallets.ts | 2 +- .../getting-started-with-wallet-manager.ts | 2 +- .../instantiating/connect-existing-wallet.ts | 2 +- .../instantiating/connect-new-wallet.ts | 2 +- .../snippets/instantiating/from-wallet.ts | 2 +- .../wallets/snippets/locked-to-unlocked.ts | 2 +- .../snippets/signing/fund-transaction.ts | 4 +- .../wallets/snippets/signing/sign-message.ts | 2 +- .../snippets/signing/sign-transaction.ts | 6 +- .../snippets/transfers/batch-transfer.ts | 6 +- .../wallets/snippets/unlocked-to-locked.ts | 2 +- .../wallet-transferring/between-accounts.ts | 5 +- .../wallet-transferring/create-transfer-2.ts | 6 +- .../wallet-transferring/create-transfer.ts | 6 +- .../transferring-to-contracts.ts | 4 +- .../transferring-to-multiple-contracts.ts | 4 +- packages/account/src/account.test.ts | 73 ++++++---- packages/account/src/account.ts | 37 ++--- packages/account/src/connectors/fuel.ts | 4 +- .../account/src/providers/provider.test.ts | 130 +++++++++--------- packages/account/src/providers/provider.ts | 107 +++++++------- .../transaction-request.test.ts | 11 +- .../transaction-response.ts | 13 +- .../assemble-transaction-summary.test.ts | 8 +- .../get-transaction-summary.ts | 16 +-- .../providers/transaction-summary/input.ts | 4 +- .../account/src/test-utils/launchNode.test.ts | 3 +- .../setup-test-provider-and-wallets.test.ts | 2 +- .../setup-test-provider-and-wallets.ts | 3 +- .../src/utils/deployScriptOrPredicate.ts | 2 +- .../src/wallet/base-wallet-unlocked.ts | 2 +- .../src/wallet/wallet-unlocked.test.ts | 2 +- packages/account/src/wallet/wallet.test.ts | 2 +- .../test/fuel-wallet-connector.test.ts | 21 +-- packages/contract/src/contract-factory.ts | 18 +-- .../src/test-utils/launch-test-node.test.ts | 4 +- .../fuel-gauge/src/await-execution.test.ts | 2 +- packages/fuel-gauge/src/blob-deploy.test.ts | 4 +- packages/fuel-gauge/src/bytes.test.ts | 4 +- .../fuel-gauge/src/call-test-contract.test.ts | 2 +- .../fuel-gauge/src/check-user-account.test.ts | 2 +- .../fuel-gauge/src/contract-factory.test.ts | 4 +- packages/fuel-gauge/src/contract.test.ts | 77 ++++++----- .../fuel-gauge/src/coverage-contract.test.ts | 2 +- packages/fuel-gauge/src/doc-examples.test.ts | 21 ++- .../src/dry-run-multiple-txs.test.ts | 8 +- packages/fuel-gauge/src/e2e-script.test.ts | 7 +- packages/fuel-gauge/src/edge-cases.test.ts | 5 +- packages/fuel-gauge/src/fee.test.ts | 22 ++- .../src/funding-transaction.test.ts | 54 ++++---- .../src/mapped-error-messages.test.ts | 2 +- packages/fuel-gauge/src/min-gas.test.ts | 10 +- .../fuel-gauge/src/payable-annotation.test.ts | 4 +- packages/fuel-gauge/src/policies.test.ts | 12 +- .../src/predicate-conditional-inputs.test.ts | 16 ++- .../src/predicate/predicate-arguments.test.ts | 28 ++-- .../predicate/predicate-configurables.test.ts | 34 ++--- .../predicate/predicate-estimations.test.ts | 16 ++- .../predicate/predicate-evaluations.test.ts | 4 +- .../src/predicate/predicate-general.test.ts | 4 +- .../predicate/predicate-input-data.test.ts | 2 +- .../predicate/predicate-invalidations.test.ts | 4 +- .../predicate-populate-witness.test.ts | 24 ++-- .../predicate/predicate-with-contract.test.ts | 4 +- .../predicate/predicate-with-script.test.ts | 2 +- .../utils/predicate/fundPredicate.ts | 2 +- packages/fuel-gauge/src/raw-slice.test.ts | 4 +- .../fuel-gauge/src/std-lib-string.test.ts | 4 +- packages/fuel-gauge/src/str-slice.test.ts | 2 +- .../src/token-test-contract.test.ts | 2 +- .../src/transaction-response.test.ts | 10 +- .../src/transaction-summary.test.ts | 48 ++++--- .../src/transaction-upgrade.test.ts | 4 +- packages/fuel-gauge/src/transaction.test.ts | 2 +- packages/fuel-gauge/src/vector-types.test.ts | 4 +- .../src/cli/commands/deploy/createWallet.ts | 3 +- .../src/setup-launch-node-server.test.ts | 2 +- .../src/functions/base-invocation-scope.ts | 15 +- packages/recipes/src/types/Src14OwnedProxy.ts | 2 +- .../src/types/Src14OwnedProxyFactory.ts | 2 +- packages/recipes/src/types/common.d.ts | 2 +- packages/recipes/src/types/index.ts | 2 +- .../script/src/script-invocation-scope.ts | 10 +- templates/nextjs/src/app/layout.tsx | 2 +- templates/vite/src/main.tsx | 2 +- 211 files changed, 795 insertions(+), 692 deletions(-) diff --git a/apps/create-fuels-counter-guide/src/main.tsx b/apps/create-fuels-counter-guide/src/main.tsx index 4f0e9214b4a..5eedd96e47d 100644 --- a/apps/create-fuels-counter-guide/src/main.tsx +++ b/apps/create-fuels-counter-guide/src/main.tsx @@ -16,7 +16,7 @@ const queryClient = new QueryClient(); const connectors = defaultConnectors({ devMode: true, - burnerWalletConfig: { fuelProvider: Provider.create(providerUrl) }, + burnerWalletConfig: { fuelProvider: new Provider(providerUrl) }, }); createRoot(document.getElementById("root")!).render( diff --git a/apps/demo-typegen/src/demo.test.ts b/apps/demo-typegen/src/demo.test.ts index f9b0c654d44..d52c7bf2383 100644 --- a/apps/demo-typegen/src/demo.test.ts +++ b/apps/demo-typegen/src/demo.test.ts @@ -169,11 +169,11 @@ test('Example predicate', async () => { data: predicateData, }); - const tx = await wallet.transfer(predicate.address, 200_000, provider.getBaseAssetId()); + const tx = await wallet.transfer(predicate.address, 200_000, await provider.getBaseAssetId()); const { isStatusSuccess } = await tx.wait(); // Then we are transferring some coins from the predicate to a random address (receiver) - const tx2 = await predicate.transfer(receiver.address, 50_000, provider.getBaseAssetId()); + const tx2 = await predicate.transfer(receiver.address, 50_000, await provider.getBaseAssetId()); await tx2.wait(); expect((await receiver.getBalance()).toNumber()).toEqual(50_000); diff --git a/apps/docs/src/guide/contracts/snippets/call-parameters/forward.ts b/apps/docs/src/guide/contracts/snippets/call-parameters/forward.ts index 9a13c184f46..bbd40950fd5 100644 --- a/apps/docs/src/guide/contracts/snippets/call-parameters/forward.ts +++ b/apps/docs/src/guide/contracts/snippets/call-parameters/forward.ts @@ -3,7 +3,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { ReturnContextFactory } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const deploy = await ReturnContextFactory.deploy(wallet); @@ -15,7 +15,7 @@ const amountToForward = 10; const { waitForResult } = await contract.functions .return_context_amount() .callParams({ - forward: [amountToForward, provider.getBaseAssetId()], + forward: [amountToForward, await provider.getBaseAssetId()], }) .call(); diff --git a/apps/docs/src/guide/contracts/snippets/call-parameters/gas-fee.ts b/apps/docs/src/guide/contracts/snippets/call-parameters/gas-fee.ts index 4f75c567290..14de8f6bcb8 100644 --- a/apps/docs/src/guide/contracts/snippets/call-parameters/gas-fee.ts +++ b/apps/docs/src/guide/contracts/snippets/call-parameters/gas-fee.ts @@ -3,7 +3,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { ReturnContextFactory } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const deploy = await ReturnContextFactory.deploy(wallet); @@ -14,7 +14,7 @@ try { await contract.functions .return_context_amount() .callParams({ - forward: [10, provider.getBaseAssetId()], + forward: [10, await provider.getBaseAssetId()], gasLimit: 1, }) .call(); diff --git a/apps/docs/src/guide/contracts/snippets/call-parameters/setting-both-parameters.ts b/apps/docs/src/guide/contracts/snippets/call-parameters/setting-both-parameters.ts index 400e872c9d5..cfd1e3b4199 100644 --- a/apps/docs/src/guide/contracts/snippets/call-parameters/setting-both-parameters.ts +++ b/apps/docs/src/guide/contracts/snippets/call-parameters/setting-both-parameters.ts @@ -3,7 +3,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { ReturnContextFactory } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const deploy = await ReturnContextFactory.deploy(wallet); @@ -16,7 +16,7 @@ const transactionGasLimit = 100_000; const call = await contract.functions .return_context_amount() .callParams({ - forward: [10, provider.getBaseAssetId()], + forward: [10, await provider.getBaseAssetId()], gasLimit: contractCallGasLimit, }) .txParams({ diff --git a/apps/docs/src/guide/contracts/snippets/configurable-constants.ts b/apps/docs/src/guide/contracts/snippets/configurable-constants.ts index d75f61ba3b6..395f0d222c6 100644 --- a/apps/docs/src/guide/contracts/snippets/configurable-constants.ts +++ b/apps/docs/src/guide/contracts/snippets/configurable-constants.ts @@ -3,7 +3,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../env'; import { EchoConfigurablesFactory } from '../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); // #region setting-configurable-constant diff --git a/apps/docs/src/guide/contracts/snippets/contract-balance.ts b/apps/docs/src/guide/contracts/snippets/contract-balance.ts index 89b468d238f..79b7546ed03 100644 --- a/apps/docs/src/guide/contracts/snippets/contract-balance.ts +++ b/apps/docs/src/guide/contracts/snippets/contract-balance.ts @@ -5,7 +5,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../env'; import { TransferToAddressFactory } from '../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const { waitForResult: waitForDeploy } = await TransferToAddressFactory.deploy(wallet); @@ -13,7 +13,7 @@ const { contract } = await waitForDeploy(); const amountToForward = 40; const amountToTransfer = 10; -const baseAssetId = provider.getBaseAssetId(); +const baseAssetId = await provider.getBaseAssetId(); const recipient = Wallet.generate({ provider, diff --git a/apps/docs/src/guide/contracts/snippets/cost-estimation.ts b/apps/docs/src/guide/contracts/snippets/cost-estimation.ts index 191f73135f4..a30ce4c29d7 100644 --- a/apps/docs/src/guide/contracts/snippets/cost-estimation.ts +++ b/apps/docs/src/guide/contracts/snippets/cost-estimation.ts @@ -3,7 +3,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../env'; import { ReturnContextFactory } from '../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const deploy = await ReturnContextFactory.deploy(wallet); @@ -13,7 +13,7 @@ const { contract } = await deploy.waitForResult(); const cost = await contract.functions .return_context_amount() .callParams({ - forward: [100, provider.getBaseAssetId()], + forward: [100, await provider.getBaseAssetId()], }) .getTransactionCost(); @@ -23,10 +23,10 @@ console.log('costs', cost); // #region cost-estimation-2 const scope = contract.multiCall([ contract.functions.return_context_amount().callParams({ - forward: [100, provider.getBaseAssetId()], + forward: [100, await provider.getBaseAssetId()], }), contract.functions.return_context_amount().callParams({ - forward: [300, provider.getBaseAssetId()], + forward: [300, await provider.getBaseAssetId()], }), ]); diff --git a/apps/docs/src/guide/contracts/snippets/deploying-contracts/deployment.ts b/apps/docs/src/guide/contracts/snippets/deploying-contracts/deployment.ts index 2487606adf3..84c8f44fdb4 100644 --- a/apps/docs/src/guide/contracts/snippets/deploying-contracts/deployment.ts +++ b/apps/docs/src/guide/contracts/snippets/deploying-contracts/deployment.ts @@ -4,7 +4,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { MyContractFactory } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const factory = new MyContractFactory(wallet); // #endregion setup diff --git a/apps/docs/src/guide/contracts/snippets/deploying-contracts/get-max-size.ts b/apps/docs/src/guide/contracts/snippets/deploying-contracts/get-max-size.ts index 424627478ea..ffec62ce70b 100644 --- a/apps/docs/src/guide/contracts/snippets/deploying-contracts/get-max-size.ts +++ b/apps/docs/src/guide/contracts/snippets/deploying-contracts/get-max-size.ts @@ -3,13 +3,13 @@ import { Provider } from 'fuels'; import { LOCAL_NETWORK_URL } from '../../../../env'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const { consensusParameters: { contractParameters: { contractMaxSize }, }, -} = provider.getChain(); +} = await provider.getChain(); // #endregion full console.log('contractMaxSize', contractMaxSize); diff --git a/apps/docs/src/guide/contracts/snippets/inter-contract-calls.ts b/apps/docs/src/guide/contracts/snippets/inter-contract-calls.ts index a20197730df..eb547f521dd 100644 --- a/apps/docs/src/guide/contracts/snippets/inter-contract-calls.ts +++ b/apps/docs/src/guide/contracts/snippets/inter-contract-calls.ts @@ -4,7 +4,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../env'; import { SimpleTokenFactory, TokenDepositorFactory } from '../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const { waitForResult: waitForSimpleToken } = diff --git a/apps/docs/src/guide/contracts/snippets/introduction.ts b/apps/docs/src/guide/contracts/snippets/introduction.ts index 124e9e9ae2c..f140b8bce36 100644 --- a/apps/docs/src/guide/contracts/snippets/introduction.ts +++ b/apps/docs/src/guide/contracts/snippets/introduction.ts @@ -3,7 +3,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../env'; import { EchoValuesFactory } from '../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const deploy = await EchoValuesFactory.deploy(wallet); diff --git a/apps/docs/src/guide/contracts/snippets/logs.ts b/apps/docs/src/guide/contracts/snippets/logs.ts index a5010be425f..b38e16c06e8 100644 --- a/apps/docs/src/guide/contracts/snippets/logs.ts +++ b/apps/docs/src/guide/contracts/snippets/logs.ts @@ -5,7 +5,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../env'; import { LogValuesFactory } from '../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const deploy = await LogValuesFactory.deploy(wallet); diff --git a/apps/docs/src/guide/contracts/snippets/managing-deployed-contracts.ts b/apps/docs/src/guide/contracts/snippets/managing-deployed-contracts.ts index 70f504d8c67..56e25ed820e 100644 --- a/apps/docs/src/guide/contracts/snippets/managing-deployed-contracts.ts +++ b/apps/docs/src/guide/contracts/snippets/managing-deployed-contracts.ts @@ -3,7 +3,7 @@ import { Contract, Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../env'; import { EchoValues, EchoValuesFactory } from '../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const abi = EchoValues.abi; const { waitForResult, contractId } = await EchoValuesFactory.deploy(wallet); diff --git a/apps/docs/src/guide/contracts/snippets/methods/call.ts b/apps/docs/src/guide/contracts/snippets/methods/call.ts index c6603f518f2..b982d068eaa 100644 --- a/apps/docs/src/guide/contracts/snippets/methods/call.ts +++ b/apps/docs/src/guide/contracts/snippets/methods/call.ts @@ -4,7 +4,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { CounterFactory } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const deployer = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const deployContract = await CounterFactory.deploy(deployer); diff --git a/apps/docs/src/guide/contracts/snippets/methods/dry-run.ts b/apps/docs/src/guide/contracts/snippets/methods/dry-run.ts index 1eca2cc7dcc..a2e23bf2939 100644 --- a/apps/docs/src/guide/contracts/snippets/methods/dry-run.ts +++ b/apps/docs/src/guide/contracts/snippets/methods/dry-run.ts @@ -4,7 +4,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { CounterFactory } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const deployer = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const deployContract = await CounterFactory.deploy(deployer); diff --git a/apps/docs/src/guide/contracts/snippets/methods/get.ts b/apps/docs/src/guide/contracts/snippets/methods/get.ts index fcd88ad83f4..c8b4a119a62 100644 --- a/apps/docs/src/guide/contracts/snippets/methods/get.ts +++ b/apps/docs/src/guide/contracts/snippets/methods/get.ts @@ -4,7 +4,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { CounterFactory } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const deployer = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const deployContract = await CounterFactory.deploy(deployer); diff --git a/apps/docs/src/guide/contracts/snippets/methods/is-read-only.ts b/apps/docs/src/guide/contracts/snippets/methods/is-read-only.ts index 5f211840161..755690bfbe0 100644 --- a/apps/docs/src/guide/contracts/snippets/methods/is-read-only.ts +++ b/apps/docs/src/guide/contracts/snippets/methods/is-read-only.ts @@ -4,7 +4,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { CounterFactory } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const deployer = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const deployContract = await CounterFactory.deploy(deployer); diff --git a/apps/docs/src/guide/contracts/snippets/methods/simulate.ts b/apps/docs/src/guide/contracts/snippets/methods/simulate.ts index 4b08dd4c4b1..810723dbb7c 100644 --- a/apps/docs/src/guide/contracts/snippets/methods/simulate.ts +++ b/apps/docs/src/guide/contracts/snippets/methods/simulate.ts @@ -4,7 +4,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { CounterFactory } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const deployer = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const deployContract = await CounterFactory.deploy(deployer); diff --git a/apps/docs/src/guide/contracts/snippets/multi-call/different-contracts-chain-methods.ts b/apps/docs/src/guide/contracts/snippets/multi-call/different-contracts-chain-methods.ts index 717b523bfa7..4cb30aa9b31 100644 --- a/apps/docs/src/guide/contracts/snippets/multi-call/different-contracts-chain-methods.ts +++ b/apps/docs/src/guide/contracts/snippets/multi-call/different-contracts-chain-methods.ts @@ -4,7 +4,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { EchoValuesFactory, ReturnContextFactory } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const deployer = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const echoContractTx = await EchoValuesFactory.deploy(deployer); @@ -17,7 +17,7 @@ const { waitForResult } = await echoContract .multiCall([ echoContract.functions.echo_u8(10), returnContextContract.functions.return_context_amount().callParams({ - forward: [100, provider.getBaseAssetId()], + forward: [100, await provider.getBaseAssetId()], }), ]) .call(); diff --git a/apps/docs/src/guide/contracts/snippets/multi-call/different-contracts-readonly.ts b/apps/docs/src/guide/contracts/snippets/multi-call/different-contracts-readonly.ts index fd664661699..8319976575a 100644 --- a/apps/docs/src/guide/contracts/snippets/multi-call/different-contracts-readonly.ts +++ b/apps/docs/src/guide/contracts/snippets/multi-call/different-contracts-readonly.ts @@ -4,7 +4,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { CounterFactory, EchoValuesFactory } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const deployer = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const counterContractTx = await CounterFactory.deploy(deployer); diff --git a/apps/docs/src/guide/contracts/snippets/multi-call/different-contracts.ts b/apps/docs/src/guide/contracts/snippets/multi-call/different-contracts.ts index 38bce26f687..9c149d004f5 100644 --- a/apps/docs/src/guide/contracts/snippets/multi-call/different-contracts.ts +++ b/apps/docs/src/guide/contracts/snippets/multi-call/different-contracts.ts @@ -4,7 +4,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { CounterFactory, EchoValuesFactory } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const deployer = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const counterContractTx = await CounterFactory.deploy(deployer); diff --git a/apps/docs/src/guide/contracts/snippets/multi-call/same-contract.ts b/apps/docs/src/guide/contracts/snippets/multi-call/same-contract.ts index 89fa41d95c3..1db6ebf9379 100644 --- a/apps/docs/src/guide/contracts/snippets/multi-call/same-contract.ts +++ b/apps/docs/src/guide/contracts/snippets/multi-call/same-contract.ts @@ -4,7 +4,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { CounterFactory } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const deployer = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const counterContractTx = await CounterFactory.deploy(deployer); diff --git a/apps/docs/src/guide/contracts/snippets/proxy-contracts.ts b/apps/docs/src/guide/contracts/snippets/proxy-contracts.ts index ef1b0385778..50db63824a0 100644 --- a/apps/docs/src/guide/contracts/snippets/proxy-contracts.ts +++ b/apps/docs/src/guide/contracts/snippets/proxy-contracts.ts @@ -14,7 +14,7 @@ import { CounterV2Factory, } from '../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const counterContractFactory = new CounterFactory(wallet); diff --git a/apps/docs/src/guide/contracts/snippets/storage-slots/override-storage-slots-inline.ts b/apps/docs/src/guide/contracts/snippets/storage-slots/override-storage-slots-inline.ts index 717d71e873e..07415c76b9c 100644 --- a/apps/docs/src/guide/contracts/snippets/storage-slots/override-storage-slots-inline.ts +++ b/apps/docs/src/guide/contracts/snippets/storage-slots/override-storage-slots-inline.ts @@ -4,7 +4,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { StorageTestContractFactory } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const deployer = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const deploymentTx = await StorageTestContractFactory.deploy(deployer, { diff --git a/apps/docs/src/guide/contracts/snippets/storage-slots/override-storage-slots.ts b/apps/docs/src/guide/contracts/snippets/storage-slots/override-storage-slots.ts index 0bb07720123..a4b4c289f1f 100644 --- a/apps/docs/src/guide/contracts/snippets/storage-slots/override-storage-slots.ts +++ b/apps/docs/src/guide/contracts/snippets/storage-slots/override-storage-slots.ts @@ -7,7 +7,7 @@ import { StorageTestContractFactory, } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const deployer = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const deploymentTx = await StorageTestContractFactory.deploy(deployer, { diff --git a/apps/docs/src/guide/contracts/snippets/utilities/add-transfer-multiple-recipients.ts b/apps/docs/src/guide/contracts/snippets/utilities/add-transfer-multiple-recipients.ts index 9b18d9a5665..5f4e1874d2a 100644 --- a/apps/docs/src/guide/contracts/snippets/utilities/add-transfer-multiple-recipients.ts +++ b/apps/docs/src/guide/contracts/snippets/utilities/add-transfer-multiple-recipients.ts @@ -6,7 +6,7 @@ import { ASSET_A, ASSET_B } from 'fuels/test-utils'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { EchoValuesFactory } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const deployer = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const deployContract = await EchoValuesFactory.deploy(deployer); @@ -19,7 +19,7 @@ const transferParams: TransferParams[] = [ { destination: recipient1.address, amount: 100, - assetId: provider.getBaseAssetId(), + assetId: await provider.getBaseAssetId(), }, { destination: recipient1.address, amount: 400, assetId: ASSET_A }, { destination: recipient2.address, amount: 300, assetId: ASSET_B }, @@ -34,7 +34,7 @@ await waitForResult(); // #endregion add-transfer-2 const recipientBalanceBaseAsset = await recipient1.getBalance( - provider.getBaseAssetId() + await provider.getBaseAssetId() ); const recipientBalanceAssetA = await recipient1.getBalance(ASSET_A); const recipientBalanceAssetB = await recipient2.getBalance(ASSET_B); diff --git a/apps/docs/src/guide/contracts/snippets/utilities/add-transfer-single-recipient.ts b/apps/docs/src/guide/contracts/snippets/utilities/add-transfer-single-recipient.ts index 0124502ed68..6bf1d2ee0da 100644 --- a/apps/docs/src/guide/contracts/snippets/utilities/add-transfer-single-recipient.ts +++ b/apps/docs/src/guide/contracts/snippets/utilities/add-transfer-single-recipient.ts @@ -4,7 +4,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { EchoValuesFactory } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const deployer = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const deployContract = await EchoValuesFactory.deploy(deployer); @@ -17,14 +17,16 @@ const { waitForResult } = await contract.functions .addTransfer({ destination: recipient.address, amount: 100, - assetId: provider.getBaseAssetId(), + assetId: await provider.getBaseAssetId(), }) .call(); await waitForResult(); // #endregion add-transfer-1 -const recipientBalance = await recipient.getBalance(provider.getBaseAssetId()); +const recipientBalance = await recipient.getBalance( + await provider.getBaseAssetId() +); console.log( 'Recipient balance should equal 100', recipientBalance.toNumber() === 100 diff --git a/apps/docs/src/guide/contracts/snippets/utilities/minted-token-asset-id.ts b/apps/docs/src/guide/contracts/snippets/utilities/minted-token-asset-id.ts index d9c31e46d2a..70ca8e96c79 100644 --- a/apps/docs/src/guide/contracts/snippets/utilities/minted-token-asset-id.ts +++ b/apps/docs/src/guide/contracts/snippets/utilities/minted-token-asset-id.ts @@ -4,7 +4,7 @@ import { bn, getMintedAssetId, Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { TokenFactory } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const deployer = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const deployContract = await TokenFactory.deploy(deployer); diff --git a/apps/docs/src/guide/contracts/snippets/utilities/using-different-wallet.ts b/apps/docs/src/guide/contracts/snippets/utilities/using-different-wallet.ts index 80b56bc8c31..9ebd0b43643 100644 --- a/apps/docs/src/guide/contracts/snippets/utilities/using-different-wallet.ts +++ b/apps/docs/src/guide/contracts/snippets/utilities/using-different-wallet.ts @@ -4,7 +4,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { ReturnContextFactory } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const deployer = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const deployContract = await ReturnContextFactory.deploy(deployer); diff --git a/apps/docs/src/guide/contracts/snippets/utilities/variable-outputs.ts b/apps/docs/src/guide/contracts/snippets/utilities/variable-outputs.ts index 1354d72e6bc..dcff3ba317c 100644 --- a/apps/docs/src/guide/contracts/snippets/utilities/variable-outputs.ts +++ b/apps/docs/src/guide/contracts/snippets/utilities/variable-outputs.ts @@ -4,7 +4,7 @@ import { Provider, Wallet, getMintedAssetId, getRandomB256 } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { TokenFactory } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const deployer = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const deployContract = await TokenFactory.deploy(deployer); diff --git a/apps/docs/src/guide/cookbook/snippets/combining-utxos.ts b/apps/docs/src/guide/cookbook/snippets/combining-utxos.ts index 2da509bb66c..45489043e7d 100644 --- a/apps/docs/src/guide/cookbook/snippets/combining-utxos.ts +++ b/apps/docs/src/guide/cookbook/snippets/combining-utxos.ts @@ -3,7 +3,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../env'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const fundingWallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const wallet = Wallet.generate({ provider }); @@ -14,20 +14,20 @@ for (let i = 0; i < 10; i++) { const initTx = await fundingWallet.transfer( wallet.address, 1000, - provider.getBaseAssetId() + await provider.getBaseAssetId() ); await initTx.waitForResult(); } // We can fetch the coins to see how many UTXOs we have, and confirm it is 10. const { coins: initialCoins } = await wallet.getCoins( - provider.getBaseAssetId() + await provider.getBaseAssetId() ); console.log('Initial Coins Length', initialCoins.length); // 10 // But we can also confirm the total balance of the base asset for this account is 10_000. -const initialBalance = await wallet.getBalance(provider.getBaseAssetId()); +const initialBalance = await wallet.getBalance(await provider.getBaseAssetId()); console.log('Initial Balance', initialBalance.toNumber()); // 10_000 @@ -36,7 +36,7 @@ console.log('Initial Balance', initialBalance.toNumber()); const combineTx = await wallet.transfer( wallet.address, 9500, - provider.getBaseAssetId() + await provider.getBaseAssetId() ); await combineTx.wait(); @@ -44,14 +44,16 @@ await combineTx.wait(); // We have 2 in this instance, as we have performed the transfer in the base asset: // a UTXO for our transfer, and another for what is left after paying the fees. const { coins: combinedCoins } = await wallet.getCoins( - provider.getBaseAssetId() + await provider.getBaseAssetId() ); console.log('Combined Coins Length', combinedCoins.length); // 2 // And we can also confirm the final balance of the base asset for this account is 9_998, // so the cost of combining is also minimal. -const combinedBalance = await wallet.getBalance(provider.getBaseAssetId()); +const combinedBalance = await wallet.getBalance( + await provider.getBaseAssetId() +); console.log('Combined Balance', combinedBalance.toNumber()); // 9_998 // #endregion combining-utxos diff --git a/apps/docs/src/guide/cookbook/snippets/custom-contract-calls.ts b/apps/docs/src/guide/cookbook/snippets/custom-contract-calls.ts index 407895191ab..2a4ac74153e 100644 --- a/apps/docs/src/guide/cookbook/snippets/custom-contract-calls.ts +++ b/apps/docs/src/guide/cookbook/snippets/custom-contract-calls.ts @@ -4,7 +4,7 @@ import { bn, buildFunctionResult, Contract, Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../env'; import { CounterFactory } from '../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const deploy = await CounterFactory.deploy(wallet); const { contract } = await deploy.waitForResult(); @@ -20,7 +20,7 @@ const scope = contractInstance.functions .addTransfer({ amount: amountToRecipient, destination: receiverWallet.address, - assetId: provider.getBaseAssetId(), + assetId: await provider.getBaseAssetId(), }); // Build a transaction request from the invocation scope @@ -29,7 +29,7 @@ const transactionRequest = await scope.getTransactionRequest(); transactionRequest.addCoinOutput( receiverWallet.address, amountToRecipient, - provider.getBaseAssetId() + await provider.getBaseAssetId() ); const txCost = await wallet.getTransactionCost(transactionRequest); @@ -55,7 +55,7 @@ console.log('value', value); // #endregion custom-transactions-contract-calls const receiverBalance = await receiverWallet.getBalance( - provider.getBaseAssetId() + await provider.getBaseAssetId() ); console.log('balance', receiverBalance.toNumber()); diff --git a/apps/docs/src/guide/cookbook/snippets/deposit-and-withdraw/deposit.ts b/apps/docs/src/guide/cookbook/snippets/deposit-and-withdraw/deposit.ts index 3bb98e70d57..44e00e589b3 100644 --- a/apps/docs/src/guide/cookbook/snippets/deposit-and-withdraw/deposit.ts +++ b/apps/docs/src/guide/cookbook/snippets/deposit-and-withdraw/deposit.ts @@ -4,12 +4,12 @@ import { getMintedAssetId, Provider, Wallet, ZeroBytes32 } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { LiquidityPoolFactory } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const deploy = await LiquidityPoolFactory.deploy(wallet, { configurableConstants: { - TOKEN: { bits: provider.getBaseAssetId() }, + TOKEN: { bits: await provider.getBaseAssetId() }, }, }); @@ -26,7 +26,7 @@ const assetId = getMintedAssetId(contractId, subId); const { waitForResult } = await contract.functions .deposit({ bits: liquidityOwner.address.toB256() }) - .callParams({ forward: [depositAmount, provider.getBaseAssetId()] }) + .callParams({ forward: [depositAmount, await provider.getBaseAssetId()] }) .txParams({ variableOutputs: 1 }) .call(); diff --git a/apps/docs/src/guide/cookbook/snippets/deposit-and-withdraw/withdraw.ts b/apps/docs/src/guide/cookbook/snippets/deposit-and-withdraw/withdraw.ts index 7019b598ce4..0ae2f4bebdf 100644 --- a/apps/docs/src/guide/cookbook/snippets/deposit-and-withdraw/withdraw.ts +++ b/apps/docs/src/guide/cookbook/snippets/deposit-and-withdraw/withdraw.ts @@ -4,12 +4,12 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { LiquidityPoolFactory } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const deploy = await LiquidityPoolFactory.deploy(wallet, { configurableConstants: { - TOKEN: { bits: provider.getBaseAssetId() }, + TOKEN: { bits: await provider.getBaseAssetId() }, }, }); @@ -20,14 +20,14 @@ const liquidityOwner = Wallet.generate({ provider }); const { waitForResult } = await contract.functions .withdraw({ bits: liquidityOwner.address.toB256() }) - .callParams({ forward: [depositAmount, provider.getBaseAssetId()] }) + .callParams({ forward: [depositAmount, await provider.getBaseAssetId()] }) .txParams({ variableOutputs: 1 }) .call(); await waitForResult(); const baseAssetAfterWithdraw = await liquidityOwner.getBalance( - provider.getBaseAssetId() + await provider.getBaseAssetId() ); // #endregion deposit-and-withdraw-cookbook-3 diff --git a/apps/docs/src/guide/cookbook/snippets/fake-resources.ts b/apps/docs/src/guide/cookbook/snippets/fake-resources.ts index ea28bccd2cb..f1387ff9854 100644 --- a/apps/docs/src/guide/cookbook/snippets/fake-resources.ts +++ b/apps/docs/src/guide/cookbook/snippets/fake-resources.ts @@ -11,10 +11,10 @@ import { import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../env'; import { ReturnScript } from '../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); -const baseAssetId = provider.getBaseAssetId(); +const baseAssetId = await provider.getBaseAssetId(); const transactionRequest = new ScriptTransactionRequest({ gasLimit: bn(62_000), diff --git a/apps/docs/src/guide/cookbook/snippets/max-outputs.ts b/apps/docs/src/guide/cookbook/snippets/max-outputs.ts index 82e41e7ff5b..fb2e205918a 100644 --- a/apps/docs/src/guide/cookbook/snippets/max-outputs.ts +++ b/apps/docs/src/guide/cookbook/snippets/max-outputs.ts @@ -3,10 +3,10 @@ import { Provider } from 'fuels'; import { LOCAL_NETWORK_URL } from '../../../env'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); -const { maxInputs, maxOutputs } = - provider.getChain().consensusParameters.txParameters; +const { maxInputs, maxOutputs } = (await provider.getChain()) + .consensusParameters.txParameters; // #endregion max-outputs console.log('Max Inputs', maxInputs); diff --git a/apps/docs/src/guide/cookbook/snippets/resubmitting-failed-transactions/right-resubmission.ts b/apps/docs/src/guide/cookbook/snippets/resubmitting-failed-transactions/right-resubmission.ts index b23e8ad48a9..6952cd34296 100644 --- a/apps/docs/src/guide/cookbook/snippets/resubmitting-failed-transactions/right-resubmission.ts +++ b/apps/docs/src/guide/cookbook/snippets/resubmitting-failed-transactions/right-resubmission.ts @@ -3,10 +3,10 @@ import { bn, Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); -const baseAssetId = provider.getBaseAssetId(); +const baseAssetId = await provider.getBaseAssetId(); const transferAmount = 1000; const transactionRequest = await wallet.createTransfer( diff --git a/apps/docs/src/guide/cookbook/snippets/resubmitting-failed-transactions/submitting.ts b/apps/docs/src/guide/cookbook/snippets/resubmitting-failed-transactions/submitting.ts index 7023179e719..bdedea80958 100644 --- a/apps/docs/src/guide/cookbook/snippets/resubmitting-failed-transactions/submitting.ts +++ b/apps/docs/src/guide/cookbook/snippets/resubmitting-failed-transactions/submitting.ts @@ -3,10 +3,10 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); -const baseAssetId = provider.getBaseAssetId(); +const baseAssetId = await provider.getBaseAssetId(); const transferAmount = 1000; diff --git a/apps/docs/src/guide/cookbook/snippets/resubmitting-failed-transactions/wrong-resubmission.ts b/apps/docs/src/guide/cookbook/snippets/resubmitting-failed-transactions/wrong-resubmission.ts index 30486e0ef0d..ff0b97954db 100644 --- a/apps/docs/src/guide/cookbook/snippets/resubmitting-failed-transactions/wrong-resubmission.ts +++ b/apps/docs/src/guide/cookbook/snippets/resubmitting-failed-transactions/wrong-resubmission.ts @@ -3,10 +3,10 @@ import { bn, Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); -const baseAssetId = provider.getBaseAssetId(); +const baseAssetId = await provider.getBaseAssetId(); const transferAmount = 1000; // #region resubmitting-failed-transactions-3 diff --git a/apps/docs/src/guide/cookbook/snippets/signing-transactions/predicate.ts b/apps/docs/src/guide/cookbook/snippets/signing-transactions/predicate.ts index 7960be54fd5..cf29391ed86 100644 --- a/apps/docs/src/guide/cookbook/snippets/signing-transactions/predicate.ts +++ b/apps/docs/src/guide/cookbook/snippets/signing-transactions/predicate.ts @@ -9,7 +9,7 @@ import { } from '../../../../env'; import { PredicateSigning } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const sender = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const signer = Wallet.fromPrivateKey(WALLET_PVT_KEY_2, provider); @@ -27,7 +27,7 @@ const predicate = new Predicate<[string]>({ const tx = await sender.transfer( predicate.address, 200_000, - provider.getBaseAssetId() + await provider.getBaseAssetId() ); await tx.waitForResult(); @@ -36,13 +36,13 @@ const request = new ScriptTransactionRequest(); request.addCoinOutput( receiver.address, amountToReceiver, - provider.getBaseAssetId() + await provider.getBaseAssetId() ); // Get the predicate resources and add them and predicate data to the request const resources = await predicate.getResourcesToSpend([ { - assetId: provider.getBaseAssetId(), + assetId: await provider.getBaseAssetId(), amount: amountToReceiver, }, ]); diff --git a/apps/docs/src/guide/cookbook/snippets/signing-transactions/script.ts b/apps/docs/src/guide/cookbook/snippets/signing-transactions/script.ts index 83131036f58..db9b8915d2c 100644 --- a/apps/docs/src/guide/cookbook/snippets/signing-transactions/script.ts +++ b/apps/docs/src/guide/cookbook/snippets/signing-transactions/script.ts @@ -10,7 +10,7 @@ import { } from '../../../../env'; import { ScriptSigning } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const sender = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const signer = Wallet.fromPrivateKey(WALLET_PVT_KEY_2, provider); const receiver = Wallet.fromPrivateKey(WALLET_PVT_KEY_3, provider); @@ -23,7 +23,7 @@ const { waitForResult } = await script.functions .addTransfer({ destination: receiver.address, amount: amountToReceiver, - assetId: provider.getBaseAssetId(), + assetId: await provider.getBaseAssetId(), }) .addSigners(signer) .call(); diff --git a/apps/docs/src/guide/cookbook/snippets/splitting-utxos.ts b/apps/docs/src/guide/cookbook/snippets/splitting-utxos.ts index 6a8dd0e976b..0c2d1a2cbfc 100644 --- a/apps/docs/src/guide/cookbook/snippets/splitting-utxos.ts +++ b/apps/docs/src/guide/cookbook/snippets/splitting-utxos.ts @@ -3,7 +3,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../env'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); // This is the wallet that will fund the sending wallet const fundingWallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); @@ -16,13 +16,13 @@ const destinationWallet = Wallet.generate({ provider }); const fundingTx = await fundingWallet.transfer( wallet.address, 1000, - provider.getBaseAssetId() + await provider.getBaseAssetId() ); await fundingTx.waitForResult(); // We can fetch the coins to see how many UTXOs we have and confirm it is 1 const { coins: initialCoins } = await wallet.getCoins( - provider.getBaseAssetId() + await provider.getBaseAssetId() ); console.log('Initial Coins Length', initialCoins.length); // 1 @@ -31,7 +31,7 @@ console.log('Initial Coins Length', initialCoins.length); // Including the address to send the funds to and the assetId we want to send const splitTxns = new Array(5).fill({ amount: 200, - assetId: provider.getBaseAssetId(), + assetId: await provider.getBaseAssetId(), destination: destinationWallet.address, }); @@ -40,7 +40,7 @@ const splitTxns = new Array(5).fill({ const fundTx = await fundingWallet.transfer( wallet.address, 500, - provider.getBaseAssetId() + await provider.getBaseAssetId() ); await fundTx.waitForResult(); diff --git a/apps/docs/src/guide/creating-a-fuel-dapp/snippets/decrement-counter.ts b/apps/docs/src/guide/creating-a-fuel-dapp/snippets/decrement-counter.ts index 537da3b53d1..38f45a9d744 100644 --- a/apps/docs/src/guide/creating-a-fuel-dapp/snippets/decrement-counter.ts +++ b/apps/docs/src/guide/creating-a-fuel-dapp/snippets/decrement-counter.ts @@ -6,7 +6,7 @@ import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../env'; import { CounterFactory } from '../../../typegend/contracts'; // Let's create our provider from the network URL. -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); // Let's create our wallet from the private key. const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); diff --git a/apps/docs/src/guide/encoding/snippets/encode-and-decode.ts b/apps/docs/src/guide/encoding/snippets/encode-and-decode.ts index 785d379b190..80a51d6f544 100644 --- a/apps/docs/src/guide/encoding/snippets/encode-and-decode.ts +++ b/apps/docs/src/guide/encoding/snippets/encode-and-decode.ts @@ -15,7 +15,7 @@ import { import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../env'; import { ScriptSum } from '../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); // First we need to build out the transaction via the script that we want to encode. diff --git a/apps/docs/src/guide/getting-started/snippets/connecting-to-localnode.ts b/apps/docs/src/guide/getting-started/snippets/connecting-to-localnode.ts index 32d26a15e26..fbca79e996a 100644 --- a/apps/docs/src/guide/getting-started/snippets/connecting-to-localnode.ts +++ b/apps/docs/src/guide/getting-started/snippets/connecting-to-localnode.ts @@ -6,7 +6,7 @@ import { LOCAL_NETWORK_URL } from '../../../env'; const ADDRESS = '0x767caf5b08eba21c561078a4d5be09bbd7f16b9eca22699a61f1edd9e456126f'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromAddress(ADDRESS, provider); const { balances } = await wallet.getBalances(); diff --git a/apps/docs/src/guide/getting-started/snippets/connecting-to-testnet.ts b/apps/docs/src/guide/getting-started/snippets/connecting-to-testnet.ts index c47478ff548..447ee8712ed 100644 --- a/apps/docs/src/guide/getting-started/snippets/connecting-to-testnet.ts +++ b/apps/docs/src/guide/getting-started/snippets/connecting-to-testnet.ts @@ -4,9 +4,7 @@ import { Provider, Wallet } from 'fuels'; const ADDRESS = '0x767caf5b08eba21c561078a4d5be09bbd7f16b9eca22699a61f1edd9e456126f'; -const provider = await Provider.create( - 'https://testnet.fuel.network/v1/graphql' -); +const provider = new Provider('https://testnet.fuel.network/v1/graphql'); const wallet = Wallet.fromAddress(ADDRESS, provider); const { balances } = await wallet.getBalances(); diff --git a/apps/docs/src/guide/predicates/snippets/configurables/configurable-default.ts b/apps/docs/src/guide/predicates/snippets/configurables/configurable-default.ts index 4ca2fbe3fe0..99cbfebdc21 100644 --- a/apps/docs/src/guide/predicates/snippets/configurables/configurable-default.ts +++ b/apps/docs/src/guide/predicates/snippets/configurables/configurable-default.ts @@ -4,7 +4,7 @@ import { Wallet, Provider } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { WhitelistedAddressPredicate } from '../../../../typegend/predicates/WhitelistedAddressPredicate'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const sender = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const recipient = Wallet.generate({ provider }); @@ -19,7 +19,7 @@ const predicate = new WhitelistedAddressPredicate({ const tx1 = await sender.transfer( predicate.address, 200_000, - provider.getBaseAssetId(), + await provider.getBaseAssetId(), { gasLimit: 1000, } @@ -33,7 +33,7 @@ const amountToTransfer = 100; const tx2 = await predicate.transfer( recipient.address, amountToTransfer, - provider.getBaseAssetId(), + await provider.getBaseAssetId(), { gasLimit: 1000, } @@ -43,7 +43,7 @@ await tx2.waitForResult(); // #endregion full const destinationBalance = await recipient.getBalance( - provider.getBaseAssetId() + await provider.getBaseAssetId() ); console.log( diff --git a/apps/docs/src/guide/predicates/snippets/configurables/configurable-set-data.ts b/apps/docs/src/guide/predicates/snippets/configurables/configurable-set-data.ts index 3ce011b973a..c7fd2c2e598 100644 --- a/apps/docs/src/guide/predicates/snippets/configurables/configurable-set-data.ts +++ b/apps/docs/src/guide/predicates/snippets/configurables/configurable-set-data.ts @@ -8,7 +8,7 @@ import { } from '../../../../env'; import { WhitelistedAddressPredicate } from '../../../../typegend/predicates/WhitelistedAddressPredicate'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const whitelisted = Wallet.fromAddress(WALLET_ADDRESS, provider); const sender = Wallet.fromPrivateKey(WALLET_PVT_KEY_2, provider); @@ -27,7 +27,7 @@ const predicate = new WhitelistedAddressPredicate({ const tx1 = await sender.transfer( predicate.address, 200_000, - provider.getBaseAssetId(), + await provider.getBaseAssetId(), { gasLimit: 1000, } @@ -41,7 +41,7 @@ const amountToTransfer = 100; const tx2 = await predicate.transfer( recipient.address, amountToTransfer, - provider.getBaseAssetId(), + await provider.getBaseAssetId(), { gasLimit: 1000, } @@ -51,7 +51,7 @@ await tx2.waitForResult(); // #endregion full const destinationBalance = await recipient.getBalance( - provider.getBaseAssetId() + await provider.getBaseAssetId() ); console.log( diff --git a/apps/docs/src/guide/predicates/snippets/cookbook/failure-not-enough-funds.ts b/apps/docs/src/guide/predicates/snippets/cookbook/failure-not-enough-funds.ts index 87b1ba671dc..72ad1bb2308 100644 --- a/apps/docs/src/guide/predicates/snippets/cookbook/failure-not-enough-funds.ts +++ b/apps/docs/src/guide/predicates/snippets/cookbook/failure-not-enough-funds.ts @@ -4,7 +4,7 @@ import { safeExec } from 'fuels/test-utils'; import { LOCAL_NETWORK_URL } from '../../../../env'; import { SimplePredicate } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const receiver = Wallet.generate({ provider }); const inputAddress = @@ -20,7 +20,7 @@ const { error } = await safeExec(async () => predicate.transfer( receiver.address, amountOfCoinsToFail, - provider.getBaseAssetId() + await provider.getBaseAssetId() ) ); diff --git a/apps/docs/src/guide/predicates/snippets/cookbook/failure-returns-false.ts b/apps/docs/src/guide/predicates/snippets/cookbook/failure-returns-false.ts index 5fc4e22e7ff..f193dc277e0 100644 --- a/apps/docs/src/guide/predicates/snippets/cookbook/failure-returns-false.ts +++ b/apps/docs/src/guide/predicates/snippets/cookbook/failure-returns-false.ts @@ -4,7 +4,7 @@ import { safeExec } from 'fuels/test-utils'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { SimplePredicate } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const sender = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const receiver = Wallet.generate({ provider }); @@ -18,7 +18,7 @@ const amountToPredicate = 10_000_000; const tx = await sender.transfer( predicate.address, amountToPredicate, - provider.getBaseAssetId(), + await provider.getBaseAssetId(), { gasLimit: 1_000, } @@ -28,7 +28,11 @@ console.log('Transfer to predicate should be successful', isStatusSuccess); const amountOfCoins = 100; const { error } = await safeExec(async () => - predicate.transfer(receiver.address, amountOfCoins, provider.getBaseAssetId()) + predicate.transfer( + receiver.address, + amountOfCoins, + await provider.getBaseAssetId() + ) ); // #region send-and-spend-funds-from-predicates-7 diff --git a/apps/docs/src/guide/predicates/snippets/cookbook/pre-stage.ts b/apps/docs/src/guide/predicates/snippets/cookbook/pre-stage.ts index dd2b3e4b1d2..e3a5a178754 100644 --- a/apps/docs/src/guide/predicates/snippets/cookbook/pre-stage.ts +++ b/apps/docs/src/guide/predicates/snippets/cookbook/pre-stage.ts @@ -3,7 +3,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { SimplePredicate } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const sender = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const receiver = Wallet.generate({ provider }); @@ -19,7 +19,7 @@ const amountToPredicate = 10_000_000; const tx = await sender.transfer( predicate.address, amountToPredicate, - provider.getBaseAssetId(), + await provider.getBaseAssetId(), { gasLimit: 1_000, } @@ -34,14 +34,14 @@ const amountToReceiver = 200; const transactionRequest = await predicate.createTransfer( receiver.address, amountToReceiver, - provider.getBaseAssetId(), + await provider.getBaseAssetId(), { gasLimit: 1000, } ); // We can obtain the transaction ID before submitting the transaction. -const chainId = provider.getChainId(); +const chainId = await provider.getChainId(); const transactionId = transactionRequest.getTransactionId(chainId); // We can submit the transaction and wait for the result. diff --git a/apps/docs/src/guide/predicates/snippets/cookbook/transferring-assets.ts b/apps/docs/src/guide/predicates/snippets/cookbook/transferring-assets.ts index 2b24bcefaa4..389bf320bc3 100644 --- a/apps/docs/src/guide/predicates/snippets/cookbook/transferring-assets.ts +++ b/apps/docs/src/guide/predicates/snippets/cookbook/transferring-assets.ts @@ -4,7 +4,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { SimplePredicate } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const sender = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const receiver = Wallet.generate({ provider }); @@ -26,7 +26,7 @@ const amountToPredicate = 10_000_000; const fundPredicateTx = await sender.transfer( predicate.address, amountToPredicate, - provider.getBaseAssetId(), + await provider.getBaseAssetId(), { gasLimit: 1000, } @@ -49,7 +49,7 @@ const amountToReceiver = 200; const transferFromPredicateTx = await predicate.transfer( receiver.address, amountToReceiver, - provider.getBaseAssetId() + await provider.getBaseAssetId() ); // Wait for the transaction diff --git a/apps/docs/src/guide/predicates/snippets/custom-transactions.ts b/apps/docs/src/guide/predicates/snippets/custom-transactions.ts index cbf976af3a0..560b483acda 100644 --- a/apps/docs/src/guide/predicates/snippets/custom-transactions.ts +++ b/apps/docs/src/guide/predicates/snippets/custom-transactions.ts @@ -6,10 +6,10 @@ import { ConfigurablePin } from '../../../typegend'; import type { ConfigurablePinInputs } from '../../../typegend/predicates/ConfigurablePin'; // Setup -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const sender = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const receiver = Wallet.generate({ provider }); -const assetId = provider.getBaseAssetId(); +const assetId = await provider.getBaseAssetId(); const amountToFundPredicate = 300_000; const amountToReceiver = 100_000; diff --git a/apps/docs/src/guide/predicates/snippets/deploying-predicates.ts b/apps/docs/src/guide/predicates/snippets/deploying-predicates.ts index 5b21a1573e4..d5593232a51 100644 --- a/apps/docs/src/guide/predicates/snippets/deploying-predicates.ts +++ b/apps/docs/src/guide/predicates/snippets/deploying-predicates.ts @@ -7,11 +7,11 @@ import { ConfigurablePinLoader, } from '../../../typegend/predicates'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const receiver = Wallet.generate({ provider }); -const baseAssetId = provider.getBaseAssetId(); +const baseAssetId = await provider.getBaseAssetId(); // We can deploy dynamically or via `fuels deploy` const originalPredicate = new ConfigurablePin({ diff --git a/apps/docs/src/guide/predicates/snippets/instantiation/multi-args.ts b/apps/docs/src/guide/predicates/snippets/instantiation/multi-args.ts index b454b7080c8..abb2b4e637d 100644 --- a/apps/docs/src/guide/predicates/snippets/instantiation/multi-args.ts +++ b/apps/docs/src/guide/predicates/snippets/instantiation/multi-args.ts @@ -4,7 +4,7 @@ import { Provider } from 'fuels'; import { LOCAL_NETWORK_URL } from '../../../../env'; import { PredicateMultiArgs } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const predicate = new PredicateMultiArgs({ provider, data: [20, 30] }); // #endregion predicate-multi-args-2 diff --git a/apps/docs/src/guide/predicates/snippets/instantiation/simple.ts b/apps/docs/src/guide/predicates/snippets/instantiation/simple.ts index d1f1a2553fe..9ebfff10508 100644 --- a/apps/docs/src/guide/predicates/snippets/instantiation/simple.ts +++ b/apps/docs/src/guide/predicates/snippets/instantiation/simple.ts @@ -4,7 +4,7 @@ import { Provider } from 'fuels'; import { LOCAL_NETWORK_URL } from '../../../../env'; import { ReturnTruePredicate } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const predicate = new ReturnTruePredicate({ provider, diff --git a/apps/docs/src/guide/predicates/snippets/instantiation/struct-arg.ts b/apps/docs/src/guide/predicates/snippets/instantiation/struct-arg.ts index 86932998644..ef991c8c13f 100644 --- a/apps/docs/src/guide/predicates/snippets/instantiation/struct-arg.ts +++ b/apps/docs/src/guide/predicates/snippets/instantiation/struct-arg.ts @@ -4,7 +4,7 @@ import { Provider } from 'fuels'; import { LOCAL_NETWORK_URL } from '../../../../env'; import { PredicateMainArgsStruct } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const predicate = new PredicateMainArgsStruct({ provider, diff --git a/apps/docs/src/guide/predicates/snippets/methods/create-transfer.ts b/apps/docs/src/guide/predicates/snippets/methods/create-transfer.ts index fc15d45e852..1a36968e604 100644 --- a/apps/docs/src/guide/predicates/snippets/methods/create-transfer.ts +++ b/apps/docs/src/guide/predicates/snippets/methods/create-transfer.ts @@ -4,7 +4,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { ReturnTruePredicate } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const funder = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const predicate = new ReturnTruePredicate({ @@ -15,7 +15,7 @@ const predicate = new ReturnTruePredicate({ const fundPredicate = await funder.transfer( predicate.address, 100_000_000, - provider.getBaseAssetId() + await provider.getBaseAssetId() ); await fundPredicate.waitForResult(); @@ -25,7 +25,7 @@ const amountToReceiver = 1000; const transactionRequest = await predicate.createTransfer( receiver.address, amountToReceiver, - provider.getBaseAssetId(), + await provider.getBaseAssetId(), { gasLimit: 1000, } diff --git a/apps/docs/src/guide/predicates/snippets/methods/get-resources-to-spend.ts b/apps/docs/src/guide/predicates/snippets/methods/get-resources-to-spend.ts index d79416b6be6..9d2c8aeae89 100644 --- a/apps/docs/src/guide/predicates/snippets/methods/get-resources-to-spend.ts +++ b/apps/docs/src/guide/predicates/snippets/methods/get-resources-to-spend.ts @@ -4,7 +4,9 @@ import { bn, Provider, ScriptTransactionRequest, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { ReturnTruePredicate } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); +const baseAssetId = await provider.getBaseAssetId(); + const funder = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const predicate = new ReturnTruePredicate({ @@ -15,7 +17,7 @@ const predicate = new ReturnTruePredicate({ const fundPredicate = await funder.transfer( predicate.address, 100_000_000, - provider.getBaseAssetId() + baseAssetId ); await fundPredicate.waitForResult(); @@ -27,7 +29,7 @@ const transactionRequest = new ScriptTransactionRequest({ // Get the resources available to send from the predicate. const predicateCoins = await predicate.getResourcesToSpend([ - { amount: 2000, assetId: provider.getBaseAssetId() }, + { amount: 2000, assetId: baseAssetId }, ]); // Add the predicate input and resources. diff --git a/apps/docs/src/guide/predicates/snippets/methods/send-transaction.ts b/apps/docs/src/guide/predicates/snippets/methods/send-transaction.ts index cfcab9cbfb9..9938e930173 100644 --- a/apps/docs/src/guide/predicates/snippets/methods/send-transaction.ts +++ b/apps/docs/src/guide/predicates/snippets/methods/send-transaction.ts @@ -4,7 +4,9 @@ import { bn, Provider, ScriptTransactionRequest, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { ReturnTruePredicate } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); +const baseAssetId = await provider.getBaseAssetId(); + const funder = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const predicate = new ReturnTruePredicate({ @@ -15,8 +17,9 @@ const predicate = new ReturnTruePredicate({ const fundPredicate = await funder.transfer( predicate.address, 100_000_000, - provider.getBaseAssetId() + baseAssetId ); + await fundPredicate.waitForResult(); // Instantiate the transaction request. @@ -27,7 +30,7 @@ const transactionRequest = new ScriptTransactionRequest({ // Get the resources available to send from the predicate. const predicateCoins = await predicate.getResourcesToSpend([ - { amount: 2000, assetId: provider.getBaseAssetId() }, + { amount: 2000, assetId: baseAssetId }, ]); // Add the predicate input and resources. diff --git a/apps/docs/src/guide/predicates/snippets/methods/simulate-transaction.ts b/apps/docs/src/guide/predicates/snippets/methods/simulate-transaction.ts index ed8012819ca..2df426a86c5 100644 --- a/apps/docs/src/guide/predicates/snippets/methods/simulate-transaction.ts +++ b/apps/docs/src/guide/predicates/snippets/methods/simulate-transaction.ts @@ -10,7 +10,9 @@ import { import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { ReturnTruePredicate } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); +const baseAssetId = await provider.getBaseAssetId(); + const funder = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const receiver = Wallet.generate({ provider }); @@ -21,7 +23,7 @@ const predicate = new ReturnTruePredicate({ const fundPredicate = await funder.transfer( predicate.address, 100_000_000, - provider.getBaseAssetId() + baseAssetId ); await fundPredicate.waitForResult(); @@ -31,11 +33,7 @@ const transactionRequest = new ScriptTransactionRequest({ maxFee: bn(0), }); -transactionRequest.addCoinOutput( - receiver.address, - 1000000, - provider.getBaseAssetId() -); +transactionRequest.addCoinOutput(receiver.address, 1000000, baseAssetId); const txCost = await predicate.getTransactionCost(transactionRequest); diff --git a/apps/docs/src/guide/predicates/snippets/methods/transfer.ts b/apps/docs/src/guide/predicates/snippets/methods/transfer.ts index ed67418e473..9adfff36def 100644 --- a/apps/docs/src/guide/predicates/snippets/methods/transfer.ts +++ b/apps/docs/src/guide/predicates/snippets/methods/transfer.ts @@ -4,7 +4,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { ReturnTruePredicate } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const funder = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const predicate = new ReturnTruePredicate({ @@ -14,7 +14,7 @@ const predicate = new ReturnTruePredicate({ const fundPredicate = await funder.transfer( predicate.address, 100_000_000, - provider.getBaseAssetId() + await provider.getBaseAssetId() ); await fundPredicate.waitForResult(); @@ -24,7 +24,7 @@ const amountToReceiver = 1000; const transferPredicateCoins = await predicate.transfer( receiver.address, amountToReceiver, - provider.getBaseAssetId(), + await provider.getBaseAssetId(), { gasLimit: 1000, } diff --git a/apps/docs/src/guide/provider/snippets/functionality/get-balances.ts b/apps/docs/src/guide/provider/snippets/functionality/get-balances.ts index dea29e7e321..dede99ab2c9 100644 --- a/apps/docs/src/guide/provider/snippets/functionality/get-balances.ts +++ b/apps/docs/src/guide/provider/snippets/functionality/get-balances.ts @@ -3,7 +3,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const { balances } = await provider.getBalances(wallet.address); diff --git a/apps/docs/src/guide/provider/snippets/functionality/get-base-asset-id.ts b/apps/docs/src/guide/provider/snippets/functionality/get-base-asset-id.ts index 2a2c03bce9d..479feb1c13e 100644 --- a/apps/docs/src/guide/provider/snippets/functionality/get-base-asset-id.ts +++ b/apps/docs/src/guide/provider/snippets/functionality/get-base-asset-id.ts @@ -4,8 +4,8 @@ import { Address, Provider, ScriptTransactionRequest } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_ADDRESS } from '../../../../env'; // Fetch the base asset ID using the provider -const provider = await Provider.create(LOCAL_NETWORK_URL); -const baseAssetId = provider.getBaseAssetId(); +const provider = new Provider(LOCAL_NETWORK_URL); +const baseAssetId = await provider.getBaseAssetId(); // 0x... // Instantiate our recipients address diff --git a/apps/docs/src/guide/provider/snippets/functionality/get-blocks.ts b/apps/docs/src/guide/provider/snippets/functionality/get-blocks.ts index 88e77e4f2bc..89a9a8e205a 100644 --- a/apps/docs/src/guide/provider/snippets/functionality/get-blocks.ts +++ b/apps/docs/src/guide/provider/snippets/functionality/get-blocks.ts @@ -3,7 +3,7 @@ import { Provider } from 'fuels'; import { LOCAL_NETWORK_URL } from '../../../../env'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const blockToProduce = 3; diff --git a/apps/docs/src/guide/provider/snippets/functionality/get-coins-from-account.ts b/apps/docs/src/guide/provider/snippets/functionality/get-coins-from-account.ts index 00b3249685e..8a3d8a34b8f 100644 --- a/apps/docs/src/guide/provider/snippets/functionality/get-coins-from-account.ts +++ b/apps/docs/src/guide/provider/snippets/functionality/get-coins-from-account.ts @@ -3,10 +3,10 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); -const baseAssetId = provider.getBaseAssetId(); +const baseAssetId = await provider.getBaseAssetId(); const { coins } = await wallet.getCoins(baseAssetId); // [ diff --git a/apps/docs/src/guide/provider/snippets/functionality/get-coins-from-provider.ts b/apps/docs/src/guide/provider/snippets/functionality/get-coins-from-provider.ts index bb6bf62b199..86329d20928 100644 --- a/apps/docs/src/guide/provider/snippets/functionality/get-coins-from-provider.ts +++ b/apps/docs/src/guide/provider/snippets/functionality/get-coins-from-provider.ts @@ -4,12 +4,12 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const assetIdA = '0x0101010101010101010101010101010101010101010101010101010101010101'; -const baseAssetId = provider.getBaseAssetId(); +const baseAssetId = await provider.getBaseAssetId(); // Fetches up to 100 coins that have an asset ID that is equal to the base asset ID const { coins: coinsOnlyBaseAsset } = await provider.getCoins( diff --git a/apps/docs/src/guide/provider/snippets/functionality/get-messages.ts b/apps/docs/src/guide/provider/snippets/functionality/get-messages.ts index b6caaec570e..96fc1e39da1 100644 --- a/apps/docs/src/guide/provider/snippets/functionality/get-messages.ts +++ b/apps/docs/src/guide/provider/snippets/functionality/get-messages.ts @@ -4,7 +4,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; // Instantiate a provider and wallet -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); // Retrieves messages from the wallet diff --git a/apps/docs/src/guide/provider/snippets/functionality/get-resources-to-spend-from-account.ts b/apps/docs/src/guide/provider/snippets/functionality/get-resources-to-spend-from-account.ts index b815c8462e1..8d1731c541f 100644 --- a/apps/docs/src/guide/provider/snippets/functionality/get-resources-to-spend-from-account.ts +++ b/apps/docs/src/guide/provider/snippets/functionality/get-resources-to-spend-from-account.ts @@ -4,12 +4,12 @@ import { Provider, ScriptTransactionRequest, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const assetIdA = '0x0101010101010101010101010101010101010101010101010101010101010101'; -const baseAssetId = provider.getBaseAssetId(); +const baseAssetId = await provider.getBaseAssetId(); const quantities: CoinQuantityLike[] = [ { amount: 32, assetId: baseAssetId, max: 42 }, diff --git a/apps/docs/src/guide/provider/snippets/functionality/get-resources-to-spend-from-provider.ts b/apps/docs/src/guide/provider/snippets/functionality/get-resources-to-spend-from-provider.ts index d2f17816801..a9aa005587e 100644 --- a/apps/docs/src/guide/provider/snippets/functionality/get-resources-to-spend-from-provider.ts +++ b/apps/docs/src/guide/provider/snippets/functionality/get-resources-to-spend-from-provider.ts @@ -4,12 +4,12 @@ import { Provider, ScriptTransactionRequest, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const assetIdA = '0x0101010101010101010101010101010101010101010101010101010101010101'; -const baseAssetId = provider.getBaseAssetId(); +const baseAssetId = await provider.getBaseAssetId(); const quantities: CoinQuantityLike[] = [ { amount: 32, assetId: baseAssetId, max: 42 }, diff --git a/apps/docs/src/guide/provider/snippets/functionality/get-transactions.ts b/apps/docs/src/guide/provider/snippets/functionality/get-transactions.ts index 3b4abed7a8e..45b89f16b38 100644 --- a/apps/docs/src/guide/provider/snippets/functionality/get-transactions.ts +++ b/apps/docs/src/guide/provider/snippets/functionality/get-transactions.ts @@ -3,7 +3,7 @@ import { Provider } from 'fuels'; import { LOCAL_NETWORK_URL } from '../../../../env'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const { transactions } = await provider.getTransactions(); // #endregion getTransactions diff --git a/apps/docs/src/guide/provider/snippets/pagination.ts b/apps/docs/src/guide/provider/snippets/pagination.ts index 079f6e89299..e2d29c2971e 100644 --- a/apps/docs/src/guide/provider/snippets/pagination.ts +++ b/apps/docs/src/guide/provider/snippets/pagination.ts @@ -24,7 +24,8 @@ const pageInfoExample: PageInfo = { console.log('pageInfoExample', pageInfoExample); // #region pagination-next-page -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); +const baseAssetId = await provider.getBaseAssetId(); let paginationArgs: CursorPaginationArgs = { first: 10, // It will return only the first 10 coins @@ -32,7 +33,7 @@ let paginationArgs: CursorPaginationArgs = { const { coins, pageInfo } = await provider.getCoins( WALLET_ADDRESS, - provider.getBaseAssetId(), + baseAssetId, paginationArgs ); @@ -42,11 +43,7 @@ if (pageInfo.hasNextPage) { first: 10, }; // The coins array will include the next 10 coins after the last one in the previous array - await provider.getCoins( - WALLET_ADDRESS, - provider.getBaseAssetId(), - paginationArgs - ); + await provider.getCoins(WALLET_ADDRESS, baseAssetId, paginationArgs); } // #endregion pagination-next-page @@ -58,11 +55,7 @@ if (pageInfo.hasPreviousPage) { }; // It will includes the previous 10 coins before the first one in the previous array - await provider.getCoins( - WALLET_ADDRESS, - provider.getBaseAssetId(), - paginationArgs - ); + await provider.getCoins(WALLET_ADDRESS, baseAssetId, paginationArgs); } // #endregion pagination-previous-page diff --git a/apps/docs/src/guide/provider/snippets/provider-instantiation.ts b/apps/docs/src/guide/provider/snippets/provider-instantiation.ts index b64263d084c..f03149c17d1 100644 --- a/apps/docs/src/guide/provider/snippets/provider-instantiation.ts +++ b/apps/docs/src/guide/provider/snippets/provider-instantiation.ts @@ -4,10 +4,10 @@ import { Provider, WalletUnlocked } from 'fuels'; import { LOCAL_NETWORK_URL } from '../../../env'; // Create the provider -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); // Querying the blockchain -const { consensusParameters } = provider.getChain(); +const { consensusParameters } = await provider.getChain(); // Create a new wallet const wallet = WalletUnlocked.generate({ provider }); diff --git a/apps/docs/src/guide/provider/snippets/provider-operations.ts b/apps/docs/src/guide/provider/snippets/provider-operations.ts index 26bdec7f759..40f7d79cf6d 100644 --- a/apps/docs/src/guide/provider/snippets/provider-operations.ts +++ b/apps/docs/src/guide/provider/snippets/provider-operations.ts @@ -4,7 +4,7 @@ import { Provider } from 'fuels'; import { LOCAL_NETWORK_URL } from '../../../env'; // Create the provider -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const chain = await provider.operations.getChain(); const nodeInfo = await provider.operations.getNodeInfo(); diff --git a/apps/docs/src/guide/provider/snippets/provider-options.ts b/apps/docs/src/guide/provider/snippets/provider-options.ts index d288fe89bdf..780c2037850 100644 --- a/apps/docs/src/guide/provider/snippets/provider-options.ts +++ b/apps/docs/src/guide/provider/snippets/provider-options.ts @@ -14,7 +14,7 @@ const NETWORK_URL = LOCAL_NETWORK_URL; // #region requestMiddleware // synchronous request middleware -await Provider.create(NETWORK_URL, { +new Provider(NETWORK_URL, { requestMiddleware: (request: RequestInit) => { request.credentials = 'omit'; @@ -23,7 +23,7 @@ await Provider.create(NETWORK_URL, { }); // asynchronous request middleware -await Provider.create(NETWORK_URL, { +new Provider(NETWORK_URL, { requestMiddleware: async (request: RequestInit) => { const credentials = await fetchSomeExternalCredentials(); request.headers ??= {}; @@ -35,13 +35,13 @@ await Provider.create(NETWORK_URL, { // #endregion requestMiddleware // #region timeout -await Provider.create(NETWORK_URL, { +new Provider(NETWORK_URL, { timeout: 3000, // will abort if request takes 30 seconds to complete }); // #endregion timeout // #region retryOptions -await Provider.create(NETWORK_URL, { +new Provider(NETWORK_URL, { retryOptions: { maxRetries: 5, baseDelay: 100, @@ -51,7 +51,7 @@ await Provider.create(NETWORK_URL, { // #endregion retryOptions // #region fetch -await Provider.create(NETWORK_URL, { +new Provider(NETWORK_URL, { fetch: async (url: string, requestInit: RequestInit | undefined) => { // native fetch const response = await fetch(url, requestInit); @@ -64,7 +64,7 @@ await Provider.create(NETWORK_URL, { // #endregion fetch // #region cache-utxo -await Provider.create(NETWORK_URL, { +new Provider(NETWORK_URL, { // Cache resources (Coin's and Message's) for 5 seconds resourceCacheTTL: 5000, }); diff --git a/apps/docs/src/guide/scripts/snippets/deploying-scripts.ts b/apps/docs/src/guide/scripts/snippets/deploying-scripts.ts index bc48321afc3..bd13ba5288a 100644 --- a/apps/docs/src/guide/scripts/snippets/deploying-scripts.ts +++ b/apps/docs/src/guide/scripts/snippets/deploying-scripts.ts @@ -22,7 +22,7 @@ const { waitForResult: waitForDeploy } = await waitForDeploy(); // #region deploying-scripts -const provider = await Provider.create(providerUrl); +const provider = new Provider(providerUrl); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); // First, we will need to instantiate the script via it's loader bytecode. This can be imported from the typegen outputs diff --git a/apps/docs/src/guide/scripts/snippets/initialising-scripts.ts b/apps/docs/src/guide/scripts/snippets/initialising-scripts.ts index 8b98087fb4c..6516ba10849 100644 --- a/apps/docs/src/guide/scripts/snippets/initialising-scripts.ts +++ b/apps/docs/src/guide/scripts/snippets/initialising-scripts.ts @@ -5,7 +5,7 @@ import { arrayify, Provider, ReceiptType, ScriptRequest, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../env'; import { CallTestScript } from '../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const script = new CallTestScript(wallet); diff --git a/apps/docs/src/guide/scripts/snippets/script-with-configurable.ts b/apps/docs/src/guide/scripts/snippets/script-with-configurable.ts index f37ebde4d17..63d452efd1e 100644 --- a/apps/docs/src/guide/scripts/snippets/script-with-configurable.ts +++ b/apps/docs/src/guide/scripts/snippets/script-with-configurable.ts @@ -6,7 +6,7 @@ import { WALLET_PVT_KEY, LOCAL_NETWORK_URL } from '../../../env'; import { ScriptSum } from '../../../typegend/scripts/ScriptSum'; // #region script-with-configurable-contants-2 -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const script = new Script(ScriptSum.bytecode, ScriptSum.abi, wallet); diff --git a/apps/docs/src/guide/scripts/snippets/script-with-main-args.ts b/apps/docs/src/guide/scripts/snippets/script-with-main-args.ts index 65325d8f78f..9f473dcc1e7 100644 --- a/apps/docs/src/guide/scripts/snippets/script-with-main-args.ts +++ b/apps/docs/src/guide/scripts/snippets/script-with-main-args.ts @@ -4,7 +4,7 @@ import { bn, Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../env'; import { ScriptMainArgs } from '../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const foo = 3; diff --git a/apps/docs/src/guide/transactions/snippets/transaction-parameters.ts b/apps/docs/src/guide/transactions/snippets/transaction-parameters.ts index 57e79fdb7b9..49ad4907aff 100644 --- a/apps/docs/src/guide/transactions/snippets/transaction-parameters.ts +++ b/apps/docs/src/guide/transactions/snippets/transaction-parameters.ts @@ -6,7 +6,7 @@ import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../env'; import { CounterFactory } from '../../../typegend'; import { ScriptSum } from '../../../typegend/scripts'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const deploy = await CounterFactory.deploy(wallet); diff --git a/apps/docs/src/guide/transactions/snippets/transaction-policies/policies-from-response.ts b/apps/docs/src/guide/transactions/snippets/transaction-policies/policies-from-response.ts index 657dda2d008..0862206e0af 100644 --- a/apps/docs/src/guide/transactions/snippets/transaction-policies/policies-from-response.ts +++ b/apps/docs/src/guide/transactions/snippets/transaction-policies/policies-from-response.ts @@ -5,7 +5,7 @@ import { Provider, Wallet, ScriptTransactionRequest, bn } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { ScriptSum } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); /** @@ -26,7 +26,7 @@ transactionRequest.setData(ScriptSum.abi, scriptArguments); // Fund the transaction const resources = await wallet.getResourcesToSpend([ - { amount: 1000, assetId: provider.getBaseAssetId() }, + { amount: 1000, assetId: await provider.getBaseAssetId() }, ]); transactionRequest.addResources(resources); diff --git a/apps/docs/src/guide/transactions/snippets/transaction-request/add-output-coin.ts b/apps/docs/src/guide/transactions/snippets/transaction-request/add-output-coin.ts index 568c2b300b8..eb8d881c140 100644 --- a/apps/docs/src/guide/transactions/snippets/transaction-request/add-output-coin.ts +++ b/apps/docs/src/guide/transactions/snippets/transaction-request/add-output-coin.ts @@ -9,12 +9,12 @@ import { import { ScriptSum } from '../../../../typegend'; // #region transaction-request-3 -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const recipient1 = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const recipient2 = Wallet.fromPrivateKey(WALLET_PVT_KEY_2, provider); -const baseAssetId = provider.getBaseAssetId(); +const baseAssetId = await provider.getBaseAssetId(); const assetA = TestAssetId.A.value; const transactionRequest = new ScriptTransactionRequest({ diff --git a/apps/docs/src/guide/transactions/snippets/transaction-request/add-predicate.ts b/apps/docs/src/guide/transactions/snippets/transaction-request/add-predicate.ts index 557fe8df8b8..597fc250d1d 100644 --- a/apps/docs/src/guide/transactions/snippets/transaction-request/add-predicate.ts +++ b/apps/docs/src/guide/transactions/snippets/transaction-request/add-predicate.ts @@ -10,7 +10,7 @@ import { import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { ScriptSum, SimplePredicate } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); // #region transaction-request-9 @@ -37,7 +37,7 @@ const tx = await wallet.transfer(predicate.address, bn(100_000)); await tx.waitForResult(); const predicateCoins = await predicate.getResourcesToSpend([ - { amount: 2000, assetId: provider.getBaseAssetId() }, + { amount: 2000, assetId: await provider.getBaseAssetId() }, ]); // Add the predicate input and resources diff --git a/apps/docs/src/guide/transactions/snippets/transaction-request/add-witness.ts b/apps/docs/src/guide/transactions/snippets/transaction-request/add-witness.ts index 3903cd1eec2..0100f756901 100644 --- a/apps/docs/src/guide/transactions/snippets/transaction-request/add-witness.ts +++ b/apps/docs/src/guide/transactions/snippets/transaction-request/add-witness.ts @@ -4,7 +4,7 @@ import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { ScriptSum } from '../../../../typegend'; // #region transaction-request-10 -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const accountA = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const accountB = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); @@ -23,7 +23,7 @@ await transactionRequest.addAccountWitnesses([accountB]); // #region transaction-request-11 // Get the chain ID -const chainId = provider.getChainId(); +const chainId = await provider.getChainId(); // Get the transaction ID using the Chain ID const transactionId = transactionRequest.getTransactionId(chainId); diff --git a/apps/docs/src/guide/transactions/snippets/transaction-request/estimate-and-fund.ts b/apps/docs/src/guide/transactions/snippets/transaction-request/estimate-and-fund.ts index 4b593a11678..aeb8b8c47eb 100644 --- a/apps/docs/src/guide/transactions/snippets/transaction-request/estimate-and-fund.ts +++ b/apps/docs/src/guide/transactions/snippets/transaction-request/estimate-and-fund.ts @@ -3,7 +3,7 @@ import { Provider, ScriptTransactionRequest, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { ScriptSum } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); // #region transaction-request-4 diff --git a/apps/docs/src/guide/transactions/snippets/transaction-request/fetch-coins.ts b/apps/docs/src/guide/transactions/snippets/transaction-request/fetch-coins.ts index aedcb18b45f..d1447525a1e 100644 --- a/apps/docs/src/guide/transactions/snippets/transaction-request/fetch-coins.ts +++ b/apps/docs/src/guide/transactions/snippets/transaction-request/fetch-coins.ts @@ -3,9 +3,9 @@ import { Provider, ScriptTransactionRequest, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { ScriptSum } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); -const baseAssetId = provider.getBaseAssetId(); +const baseAssetId = await provider.getBaseAssetId(); const transactionRequest = new ScriptTransactionRequest({ script: ScriptSum.bytecode, diff --git a/apps/docs/src/guide/transactions/snippets/transaction-request/fetch-resources.ts b/apps/docs/src/guide/transactions/snippets/transaction-request/fetch-resources.ts index dc7bec20eec..01f967012aa 100644 --- a/apps/docs/src/guide/transactions/snippets/transaction-request/fetch-resources.ts +++ b/apps/docs/src/guide/transactions/snippets/transaction-request/fetch-resources.ts @@ -5,7 +5,7 @@ import { TestAssetId } from 'fuels/test-utils'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { ScriptSum } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); // #region transaction-request-5 @@ -14,7 +14,7 @@ const transactionRequest = new ScriptTransactionRequest({ script: ScriptSum.bytecode, }); -const baseAssetId = provider.getBaseAssetId(); +const baseAssetId = await provider.getBaseAssetId(); const assetA = TestAssetId.A.value; // Define the quantities to fetch diff --git a/apps/docs/src/guide/transactions/snippets/transaction-request/input-contract.ts b/apps/docs/src/guide/transactions/snippets/transaction-request/input-contract.ts index ccb38131e4c..1f9c99aecd7 100644 --- a/apps/docs/src/guide/transactions/snippets/transaction-request/input-contract.ts +++ b/apps/docs/src/guide/transactions/snippets/transaction-request/input-contract.ts @@ -3,7 +3,7 @@ import { Provider, ScriptTransactionRequest, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { CounterFactory, ScriptSum } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); // #region transaction-request-8 diff --git a/apps/docs/src/guide/transactions/snippets/transaction-response/contract-call.ts b/apps/docs/src/guide/transactions/snippets/transaction-response/contract-call.ts index cdbf7d93c32..d61a36ffdb3 100644 --- a/apps/docs/src/guide/transactions/snippets/transaction-response/contract-call.ts +++ b/apps/docs/src/guide/transactions/snippets/transaction-response/contract-call.ts @@ -3,7 +3,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { CounterFactory } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const deploy = await CounterFactory.deploy(wallet); diff --git a/apps/docs/src/guide/transactions/snippets/transaction-response/from-submitted-request.ts b/apps/docs/src/guide/transactions/snippets/transaction-response/from-submitted-request.ts index a66a82ac260..d3c5d4e4fae 100644 --- a/apps/docs/src/guide/transactions/snippets/transaction-response/from-submitted-request.ts +++ b/apps/docs/src/guide/transactions/snippets/transaction-response/from-submitted-request.ts @@ -8,7 +8,7 @@ import { import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { ScriptSum } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); // #region transaction-response-2 diff --git a/apps/docs/src/guide/transactions/snippets/transaction.ts b/apps/docs/src/guide/transactions/snippets/transaction.ts index 312dcd9ccc1..683556a2b45 100644 --- a/apps/docs/src/guide/transactions/snippets/transaction.ts +++ b/apps/docs/src/guide/transactions/snippets/transaction.ts @@ -6,16 +6,16 @@ import { WALLET_PVT_KEY_2, } from '../../../env'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const sender = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); -const assetId = provider.getBaseAssetId(); +const assetId = await provider.getBaseAssetId(); const receiver = Wallet.fromPrivateKey(WALLET_PVT_KEY_2, provider); // #region transactions-1 const tx = await sender.transfer(receiver.address, 100, assetId); await tx.waitForResult(); -const newBalance = await receiver.getBalance(provider.getBaseAssetId()); +const newBalance = await receiver.getBalance(await provider.getBaseAssetId()); // 100 // #endregion transactions-1 console.log('balance', newBalance.toNumber()); diff --git a/apps/docs/src/guide/types/snippets/address/from-a-public-key.ts b/apps/docs/src/guide/types/snippets/address/from-a-public-key.ts index c409a800a3a..83077dd8ea4 100644 --- a/apps/docs/src/guide/types/snippets/address/from-a-public-key.ts +++ b/apps/docs/src/guide/types/snippets/address/from-a-public-key.ts @@ -3,7 +3,7 @@ import { Address, Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL } from '../../../../env'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.generate({ provider }); diff --git a/apps/docs/src/guide/types/snippets/arrays.ts b/apps/docs/src/guide/types/snippets/arrays.ts index f8c96e145a7..a26ef8de1f5 100644 --- a/apps/docs/src/guide/types/snippets/arrays.ts +++ b/apps/docs/src/guide/types/snippets/arrays.ts @@ -15,7 +15,7 @@ const boolArray: boolean[] = [true, false, true]; console.log('numberArray', numberArray); console.log('boolArray', boolArray); -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const deploy = await EchoValuesFactory.deploy(wallet); const { contract } = await deploy.waitForResult(); diff --git a/apps/docs/src/guide/types/snippets/asset-id/using-an-asset-id-1.ts b/apps/docs/src/guide/types/snippets/asset-id/using-an-asset-id-1.ts index 2621d4cc6f1..4eb3298a9c6 100644 --- a/apps/docs/src/guide/types/snippets/asset-id/using-an-asset-id-1.ts +++ b/apps/docs/src/guide/types/snippets/asset-id/using-an-asset-id-1.ts @@ -4,7 +4,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { EchoAssetIdFactory } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const deploy = await EchoAssetIdFactory.deploy(wallet); const { contract } = await deploy.waitForResult(); diff --git a/apps/docs/src/guide/types/snippets/asset-id/using-an-asset-id-2.ts b/apps/docs/src/guide/types/snippets/asset-id/using-an-asset-id-2.ts index 6d0c107b3d5..d07f4e9b594 100644 --- a/apps/docs/src/guide/types/snippets/asset-id/using-an-asset-id-2.ts +++ b/apps/docs/src/guide/types/snippets/asset-id/using-an-asset-id-2.ts @@ -3,7 +3,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { EchoAssetIdFactory } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const deploy = await EchoAssetIdFactory.deploy(wallet); const { contract } = await deploy.waitForResult(); diff --git a/apps/docs/src/guide/types/snippets/bits512/b512-in-the-sdk.ts b/apps/docs/src/guide/types/snippets/bits512/b512-in-the-sdk.ts index a73b9ff5eb6..71fab13c95c 100644 --- a/apps/docs/src/guide/types/snippets/bits512/b512-in-the-sdk.ts +++ b/apps/docs/src/guide/types/snippets/bits512/b512-in-the-sdk.ts @@ -3,7 +3,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL } from '../../../../env'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.generate({ provider }); console.log('public key', wallet.publicKey); diff --git a/apps/docs/src/guide/types/snippets/bits512/echoing-a-b512.ts b/apps/docs/src/guide/types/snippets/bits512/echoing-a-b512.ts index 6e90b00299e..8cf86108c56 100644 --- a/apps/docs/src/guide/types/snippets/bits512/echoing-a-b512.ts +++ b/apps/docs/src/guide/types/snippets/bits512/echoing-a-b512.ts @@ -3,7 +3,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { EchoValuesFactory } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); diff --git a/apps/docs/src/guide/types/snippets/bytes.ts b/apps/docs/src/guide/types/snippets/bytes.ts index b14eac6c5e7..dac70031ebb 100644 --- a/apps/docs/src/guide/types/snippets/bytes.ts +++ b/apps/docs/src/guide/types/snippets/bytes.ts @@ -4,7 +4,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../env'; import { EchoBytesFactory } from '../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const deploy = await EchoBytesFactory.deploy(wallet); const { contract } = await deploy.waitForResult(); diff --git a/apps/docs/src/guide/types/snippets/enums/using-enums-of-enums-1.ts b/apps/docs/src/guide/types/snippets/enums/using-enums-of-enums-1.ts index 06a256f7ec5..d3bc38d837d 100644 --- a/apps/docs/src/guide/types/snippets/enums/using-enums-of-enums-1.ts +++ b/apps/docs/src/guide/types/snippets/enums/using-enums-of-enums-1.ts @@ -4,7 +4,7 @@ import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { EchoEnumFactory } from '../../../../typegend'; import { UserErrorInput } from '../../../../typegend/contracts/EchoEnum'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const deploy = await EchoEnumFactory.deploy(wallet); const { contract } = await deploy.waitForResult(); diff --git a/apps/docs/src/guide/types/snippets/enums/using-enums-of-enums-2.ts b/apps/docs/src/guide/types/snippets/enums/using-enums-of-enums-2.ts index cf9faa6cc0d..d38469bd533 100644 --- a/apps/docs/src/guide/types/snippets/enums/using-enums-of-enums-2.ts +++ b/apps/docs/src/guide/types/snippets/enums/using-enums-of-enums-2.ts @@ -4,7 +4,7 @@ import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { EchoEnumFactory } from '../../../../typegend'; import { StateErrorInput } from '../../../../typegend/contracts/EchoEnum'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const deploy = await EchoEnumFactory.deploy(wallet); const { contract } = await deploy.waitForResult(); diff --git a/apps/docs/src/guide/types/snippets/enums/using-sway-enums.ts b/apps/docs/src/guide/types/snippets/enums/using-sway-enums.ts index 64e796e9ef8..4c3b0233ace 100644 --- a/apps/docs/src/guide/types/snippets/enums/using-sway-enums.ts +++ b/apps/docs/src/guide/types/snippets/enums/using-sway-enums.ts @@ -5,7 +5,7 @@ import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { EchoEnumFactory } from '../../../../typegend'; import { StateErrorInput } from '../../../../typegend/contracts/EchoEnum'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const deploy = await EchoEnumFactory.deploy(wallet); const { contract } = await deploy.waitForResult(); diff --git a/apps/docs/src/guide/types/snippets/evm-address/using-an-evm-address-1.ts b/apps/docs/src/guide/types/snippets/evm-address/using-an-evm-address-1.ts index 36c8a18f106..c18f53aa076 100644 --- a/apps/docs/src/guide/types/snippets/evm-address/using-an-evm-address-1.ts +++ b/apps/docs/src/guide/types/snippets/evm-address/using-an-evm-address-1.ts @@ -3,7 +3,7 @@ import { Provider, Wallet, type EvmAddress } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { EchoEvmAddressFactory } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const deploy = await EchoEvmAddressFactory.deploy(wallet); const { contract } = await deploy.waitForResult(); diff --git a/apps/docs/src/guide/types/snippets/evm-address/using-an-evm-address-2.ts b/apps/docs/src/guide/types/snippets/evm-address/using-an-evm-address-2.ts index f4df4095ffe..d9936a5a393 100644 --- a/apps/docs/src/guide/types/snippets/evm-address/using-an-evm-address-2.ts +++ b/apps/docs/src/guide/types/snippets/evm-address/using-an-evm-address-2.ts @@ -3,7 +3,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { EchoEvmAddressFactory } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const deploy = await EchoEvmAddressFactory.deploy(wallet); const { contract } = await deploy.waitForResult(); diff --git a/apps/docs/src/guide/types/snippets/native-parameters/address.ts b/apps/docs/src/guide/types/snippets/native-parameters/address.ts index f6d219e5418..dd94bf65de9 100644 --- a/apps/docs/src/guide/types/snippets/native-parameters/address.ts +++ b/apps/docs/src/guide/types/snippets/native-parameters/address.ts @@ -3,7 +3,7 @@ import { Address, Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { InputOutputTypesFactory } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const deploy = await InputOutputTypesFactory.deploy(wallet); const { contract } = await deploy.waitForResult(); diff --git a/apps/docs/src/guide/types/snippets/native-parameters/asset-id.ts b/apps/docs/src/guide/types/snippets/native-parameters/asset-id.ts index c2dbd79e6c4..c90c2ee0329 100644 --- a/apps/docs/src/guide/types/snippets/native-parameters/asset-id.ts +++ b/apps/docs/src/guide/types/snippets/native-parameters/asset-id.ts @@ -3,7 +3,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { InputOutputTypesFactory } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const deploy = await InputOutputTypesFactory.deploy(wallet); const { contract } = await deploy.waitForResult(); diff --git a/apps/docs/src/guide/types/snippets/native-parameters/contract-id.ts b/apps/docs/src/guide/types/snippets/native-parameters/contract-id.ts index fcaa94f12b6..c4171207349 100644 --- a/apps/docs/src/guide/types/snippets/native-parameters/contract-id.ts +++ b/apps/docs/src/guide/types/snippets/native-parameters/contract-id.ts @@ -3,7 +3,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { InputOutputTypesFactory } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const deploy = await InputOutputTypesFactory.deploy(wallet); const { contract } = await deploy.waitForResult(); diff --git a/apps/docs/src/guide/types/snippets/native-parameters/identity-address.ts b/apps/docs/src/guide/types/snippets/native-parameters/identity-address.ts index 36642e3fb95..bc7bccbade4 100644 --- a/apps/docs/src/guide/types/snippets/native-parameters/identity-address.ts +++ b/apps/docs/src/guide/types/snippets/native-parameters/identity-address.ts @@ -7,7 +7,7 @@ import type { AddressOutput, } from '../../../../typegend/contracts/InputOutputTypes'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const deploy = await InputOutputTypesFactory.deploy(wallet); const { contract } = await deploy.waitForResult(); diff --git a/apps/docs/src/guide/types/snippets/native-parameters/identity-contract.ts b/apps/docs/src/guide/types/snippets/native-parameters/identity-contract.ts index 6a1021ef45a..cc1897a5d08 100644 --- a/apps/docs/src/guide/types/snippets/native-parameters/identity-contract.ts +++ b/apps/docs/src/guide/types/snippets/native-parameters/identity-contract.ts @@ -7,7 +7,7 @@ import type { IdentityOutput, } from '../../../../typegend/contracts/InputOutputTypes'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const deploy = await InputOutputTypesFactory.deploy(wallet); const { contract } = await deploy.waitForResult(); diff --git a/apps/docs/src/guide/types/snippets/numbers/for-u64-and-u256-3.ts b/apps/docs/src/guide/types/snippets/numbers/for-u64-and-u256-3.ts index bc792c96a27..0c71fc04b21 100644 --- a/apps/docs/src/guide/types/snippets/numbers/for-u64-and-u256-3.ts +++ b/apps/docs/src/guide/types/snippets/numbers/for-u64-and-u256-3.ts @@ -3,7 +3,7 @@ import { bn, Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { EchoValuesFactory } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const deploy = await EchoValuesFactory.deploy(wallet); const { contract } = await deploy.waitForResult(); diff --git a/apps/docs/src/guide/types/snippets/numbers/for-u8-u16-and-u32-1.ts b/apps/docs/src/guide/types/snippets/numbers/for-u8-u16-and-u32-1.ts index 1190049de08..f47df403b7e 100644 --- a/apps/docs/src/guide/types/snippets/numbers/for-u8-u16-and-u32-1.ts +++ b/apps/docs/src/guide/types/snippets/numbers/for-u8-u16-and-u32-1.ts @@ -3,7 +3,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { EchoValuesFactory } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const deploy = await EchoValuesFactory.deploy(wallet); const { contract } = await deploy.waitForResult(); diff --git a/apps/docs/src/guide/types/snippets/options/example-option-u8.ts b/apps/docs/src/guide/types/snippets/options/example-option-u8.ts index 3ec3b662738..3e23e223741 100644 --- a/apps/docs/src/guide/types/snippets/options/example-option-u8.ts +++ b/apps/docs/src/guide/types/snippets/options/example-option-u8.ts @@ -3,7 +3,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { SumOptionU8Factory } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const deploy = await SumOptionU8Factory.deploy(wallet); const { contract } = await deploy.waitForResult(); diff --git a/apps/docs/src/guide/types/snippets/options/overview-of-option.ts b/apps/docs/src/guide/types/snippets/options/overview-of-option.ts index c901b47e12a..ccfa73412f9 100644 --- a/apps/docs/src/guide/types/snippets/options/overview-of-option.ts +++ b/apps/docs/src/guide/types/snippets/options/overview-of-option.ts @@ -3,7 +3,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { SumOptionU8Factory } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const deploy = await SumOptionU8Factory.deploy(wallet); const { contract } = await deploy.waitForResult(); diff --git a/apps/docs/src/guide/types/snippets/raw-slice.ts b/apps/docs/src/guide/types/snippets/raw-slice.ts index 0d30fab669a..69ba948bd24 100644 --- a/apps/docs/src/guide/types/snippets/raw-slice.ts +++ b/apps/docs/src/guide/types/snippets/raw-slice.ts @@ -5,7 +5,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../env'; import { EchoRawSliceFactory } from '../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const deploy = await EchoRawSliceFactory.deploy(wallet); const { contract } = await deploy.waitForResult(); diff --git a/apps/docs/src/guide/types/snippets/std-string.ts b/apps/docs/src/guide/types/snippets/std-string.ts index c2b469cd3e4..f42a1eab118 100644 --- a/apps/docs/src/guide/types/snippets/std-string.ts +++ b/apps/docs/src/guide/types/snippets/std-string.ts @@ -4,7 +4,7 @@ import { Provider, Wallet, type StdString } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../env'; import { EchoStdStringFactory } from '../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const deploy = await EchoStdStringFactory.deploy(wallet); const { contract } = await deploy.waitForResult(); diff --git a/apps/docs/src/guide/types/snippets/string.ts b/apps/docs/src/guide/types/snippets/string.ts index 34b0c6cf53c..4b8c7ce9a52 100644 --- a/apps/docs/src/guide/types/snippets/string.ts +++ b/apps/docs/src/guide/types/snippets/string.ts @@ -4,7 +4,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../env'; import { EchoValuesFactory } from '../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const deploy = await EchoValuesFactory.deploy(wallet); const { contract } = await deploy.waitForResult(); diff --git a/apps/docs/src/guide/types/snippets/tuples.ts b/apps/docs/src/guide/types/snippets/tuples.ts index 4d4494f796c..208ffca7f45 100644 --- a/apps/docs/src/guide/types/snippets/tuples.ts +++ b/apps/docs/src/guide/types/snippets/tuples.ts @@ -4,7 +4,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../env'; import { EchoValuesFactory } from '../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const deploy = await EchoValuesFactory.deploy(wallet); const { contract } = await deploy.waitForResult(); diff --git a/apps/docs/src/guide/types/snippets/vectors.ts b/apps/docs/src/guide/types/snippets/vectors.ts index 9fcedea29e9..1d4d147e8be 100644 --- a/apps/docs/src/guide/types/snippets/vectors.ts +++ b/apps/docs/src/guide/types/snippets/vectors.ts @@ -8,7 +8,7 @@ import { } from '../../../typegend'; import type { EmployeeDataInput } from '../../../typegend/contracts/EchoEmployeeDataVector'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const deploy = await EchoEmployeeDataVectorFactory.deploy(wallet); const { contract } = await deploy.waitForResult(); diff --git a/apps/docs/src/guide/utilities/snippets/address-conversion/contract.ts b/apps/docs/src/guide/utilities/snippets/address-conversion/contract.ts index be3dac1d8ac..0182740b52a 100644 --- a/apps/docs/src/guide/utilities/snippets/address-conversion/contract.ts +++ b/apps/docs/src/guide/utilities/snippets/address-conversion/contract.ts @@ -5,7 +5,7 @@ import { Address, Provider, Contract } from 'fuels'; import { LOCAL_NETWORK_URL } from '../../../../env'; import { Counter } from '../../../../typegend/contracts'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const contractAbi = Counter.abi; const contractAddress = Address.fromB256( diff --git a/apps/docs/src/guide/utilities/snippets/address-conversion/wallet.ts b/apps/docs/src/guide/utilities/snippets/address-conversion/wallet.ts index 9301faa9957..03c90a4a6ba 100644 --- a/apps/docs/src/guide/utilities/snippets/address-conversion/wallet.ts +++ b/apps/docs/src/guide/utilities/snippets/address-conversion/wallet.ts @@ -4,7 +4,7 @@ import { Address, Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL } from '../../../../env'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const address = Address.fromB256( '0x6d309766c0f1c6f103d147b287fabecaedd31beb180d45cf1bf7d88397aecc6f' diff --git a/apps/docs/src/guide/utilities/snippets/unit-conversion.ts b/apps/docs/src/guide/utilities/snippets/unit-conversion.ts index ab06b24b972..28446296bcf 100644 --- a/apps/docs/src/guide/utilities/snippets/unit-conversion.ts +++ b/apps/docs/src/guide/utilities/snippets/unit-conversion.ts @@ -22,7 +22,7 @@ const resultTwo = bn('100000000').toString(); // #region contract-calls-1 // Let's deploy a contract that has a function that takes a u64 as input -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = await Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); diff --git a/apps/docs/src/guide/utilities/snippets/using-assets.ts b/apps/docs/src/guide/utilities/snippets/using-assets.ts index 25f2d9cca38..a54840b67a8 100644 --- a/apps/docs/src/guide/utilities/snippets/using-assets.ts +++ b/apps/docs/src/guide/utilities/snippets/using-assets.ts @@ -5,7 +5,7 @@ import { assets, CHAIN_IDS, getAssetFuel, Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../env'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const sender = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const recipient = Wallet.generate({ provider }); diff --git a/apps/docs/src/guide/wallets/snippets/access.ts b/apps/docs/src/guide/wallets/snippets/access.ts index 909bcae59a5..f0275e136ba 100644 --- a/apps/docs/src/guide/wallets/snippets/access.ts +++ b/apps/docs/src/guide/wallets/snippets/access.ts @@ -7,7 +7,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL } from '../../../env'; // We can use the `generate` to create a new unlocked wallet. -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const myWallet: WalletUnlocked = Wallet.generate({ provider }); // or use an Address to create a wallet diff --git a/apps/docs/src/guide/wallets/snippets/checking-balances-two.ts b/apps/docs/src/guide/wallets/snippets/checking-balances-two.ts index 218c18f4392..ab92f5d363c 100644 --- a/apps/docs/src/guide/wallets/snippets/checking-balances-two.ts +++ b/apps/docs/src/guide/wallets/snippets/checking-balances-two.ts @@ -3,7 +3,7 @@ import { Provider, Wallet } from 'fuels'; import { WALLET_PVT_KEY_2, LOCAL_NETWORK_URL } from '../../../env'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const myOtherWallet = Wallet.fromPrivateKey(WALLET_PVT_KEY_2, provider); const { balances } = await myOtherWallet.getBalances(); diff --git a/apps/docs/src/guide/wallets/snippets/checking-balances.ts b/apps/docs/src/guide/wallets/snippets/checking-balances.ts index 0a5cb587edf..69c8c7fb227 100644 --- a/apps/docs/src/guide/wallets/snippets/checking-balances.ts +++ b/apps/docs/src/guide/wallets/snippets/checking-balances.ts @@ -4,12 +4,12 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../env'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const myWallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); // The returned amount is a BigNumber -const balance: BN = await myWallet.getBalance(provider.getBaseAssetId()); +const balance: BN = await myWallet.getBalance(await provider.getBaseAssetId()); // #endregion checking-balances-1 console.log('balance', balance); diff --git a/apps/docs/src/guide/wallets/snippets/encrypting-and-decrypting-json-wallets-two.ts b/apps/docs/src/guide/wallets/snippets/encrypting-and-decrypting-json-wallets-two.ts index de617bb6ec4..b5a3cc0f098 100644 --- a/apps/docs/src/guide/wallets/snippets/encrypting-and-decrypting-json-wallets-two.ts +++ b/apps/docs/src/guide/wallets/snippets/encrypting-and-decrypting-json-wallets-two.ts @@ -3,7 +3,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL } from '../../../env'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const newJsonWallet = await Wallet.generate({ provider, diff --git a/apps/docs/src/guide/wallets/snippets/encrypting-and-decrypting-wallets.ts b/apps/docs/src/guide/wallets/snippets/encrypting-and-decrypting-wallets.ts index 44752188fe5..1a0c65c301f 100644 --- a/apps/docs/src/guide/wallets/snippets/encrypting-and-decrypting-wallets.ts +++ b/apps/docs/src/guide/wallets/snippets/encrypting-and-decrypting-wallets.ts @@ -3,7 +3,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL } from '../../../env'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = Wallet.generate({ provider }); diff --git a/apps/docs/src/guide/wallets/snippets/getting-started-with-wallet-manager.ts b/apps/docs/src/guide/wallets/snippets/getting-started-with-wallet-manager.ts index 84b2bf12341..f8650001456 100644 --- a/apps/docs/src/guide/wallets/snippets/getting-started-with-wallet-manager.ts +++ b/apps/docs/src/guide/wallets/snippets/getting-started-with-wallet-manager.ts @@ -18,7 +18,7 @@ await walletManager.unlock(password); // #region getting-started-with-wallet-manager-3 // Initialize a Provider -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const myWallet = Wallet.generate({ provider, }); diff --git a/apps/docs/src/guide/wallets/snippets/instantiating/connect-existing-wallet.ts b/apps/docs/src/guide/wallets/snippets/instantiating/connect-existing-wallet.ts index 9cd2778843e..1cfe25833e6 100644 --- a/apps/docs/src/guide/wallets/snippets/instantiating/connect-existing-wallet.ts +++ b/apps/docs/src/guide/wallets/snippets/instantiating/connect-existing-wallet.ts @@ -4,7 +4,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_ADDRESS } from '../../../../env'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet: WalletLocked = Wallet.fromAddress(WALLET_ADDRESS); wallet.connect(provider); diff --git a/apps/docs/src/guide/wallets/snippets/instantiating/connect-new-wallet.ts b/apps/docs/src/guide/wallets/snippets/instantiating/connect-new-wallet.ts index 79ac6e5a158..a345ab4aa07 100644 --- a/apps/docs/src/guide/wallets/snippets/instantiating/connect-new-wallet.ts +++ b/apps/docs/src/guide/wallets/snippets/instantiating/connect-new-wallet.ts @@ -4,7 +4,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_ADDRESS } from '../../../../env'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet: WalletLocked = Wallet.fromAddress(WALLET_ADDRESS, provider); // #endregion instantiating-wallets-10 diff --git a/apps/docs/src/guide/wallets/snippets/instantiating/from-wallet.ts b/apps/docs/src/guide/wallets/snippets/instantiating/from-wallet.ts index dc0eda15af9..e6726438b04 100644 --- a/apps/docs/src/guide/wallets/snippets/instantiating/from-wallet.ts +++ b/apps/docs/src/guide/wallets/snippets/instantiating/from-wallet.ts @@ -8,7 +8,7 @@ import { WALLET_PVT_KEY, } from '../../../../env'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); // Generate a locked wallet const lockedWallet: WalletLocked = Wallet.fromAddress(WALLET_ADDRESS, provider); diff --git a/apps/docs/src/guide/wallets/snippets/locked-to-unlocked.ts b/apps/docs/src/guide/wallets/snippets/locked-to-unlocked.ts index bcc70eab18f..adbb347294a 100644 --- a/apps/docs/src/guide/wallets/snippets/locked-to-unlocked.ts +++ b/apps/docs/src/guide/wallets/snippets/locked-to-unlocked.ts @@ -4,7 +4,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL } from '../../../env'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet: WalletUnlocked = Wallet.generate({ provider }); const PRIVATE_KEY = wallet.privateKey; diff --git a/apps/docs/src/guide/wallets/snippets/signing/fund-transaction.ts b/apps/docs/src/guide/wallets/snippets/signing/fund-transaction.ts index ce6df960d24..3c78f452cc8 100644 --- a/apps/docs/src/guide/wallets/snippets/signing/fund-transaction.ts +++ b/apps/docs/src/guide/wallets/snippets/signing/fund-transaction.ts @@ -3,7 +3,7 @@ import { Address, Provider, ScriptTransactionRequest, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const sender = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const receiverAddress = Address.fromRandom(); @@ -11,7 +11,7 @@ const request = new ScriptTransactionRequest({ gasLimit: 10000, }); -request.addCoinOutput(receiverAddress, 1000, provider.getBaseAssetId()); +request.addCoinOutput(receiverAddress, 1000, await provider.getBaseAssetId()); const txCost = await sender.getTransactionCost(request); diff --git a/apps/docs/src/guide/wallets/snippets/signing/sign-message.ts b/apps/docs/src/guide/wallets/snippets/signing/sign-message.ts index 094919d72b7..f1a8e0ab0a5 100644 --- a/apps/docs/src/guide/wallets/snippets/signing/sign-message.ts +++ b/apps/docs/src/guide/wallets/snippets/signing/sign-message.ts @@ -3,7 +3,7 @@ import { hashMessage, Provider, Signer, WalletUnlocked } from 'fuels'; import { LOCAL_NETWORK_URL } from '../../../../env'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const wallet = WalletUnlocked.generate({ provider }); diff --git a/apps/docs/src/guide/wallets/snippets/signing/sign-transaction.ts b/apps/docs/src/guide/wallets/snippets/signing/sign-transaction.ts index dabaab4a0f1..6d29610f1f4 100644 --- a/apps/docs/src/guide/wallets/snippets/signing/sign-transaction.ts +++ b/apps/docs/src/guide/wallets/snippets/signing/sign-transaction.ts @@ -9,7 +9,7 @@ import { import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const sender = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const receiverAddress = Address.fromRandom(); @@ -17,7 +17,7 @@ const request = new ScriptTransactionRequest({ gasLimit: 10000, }); -request.addCoinOutput(receiverAddress, 1000, provider.getBaseAssetId()); +request.addCoinOutput(receiverAddress, 1000, await provider.getBaseAssetId()); const txCost = await sender.getTransactionCost(request); @@ -27,7 +27,7 @@ request.maxFee = txCost.maxFee; await sender.fund(request, txCost); const signedTransaction = await sender.signTransaction(request); -const transactionId = request.getTransactionId(provider.getChainId()); +const transactionId = request.getTransactionId(await provider.getChainId()); const recoveredAddress = Signer.recoverAddress( transactionId, diff --git a/apps/docs/src/guide/wallets/snippets/transfers/batch-transfer.ts b/apps/docs/src/guide/wallets/snippets/transfers/batch-transfer.ts index d7c790cae8a..4a1be23ee5e 100644 --- a/apps/docs/src/guide/wallets/snippets/transfers/batch-transfer.ts +++ b/apps/docs/src/guide/wallets/snippets/transfers/batch-transfer.ts @@ -4,7 +4,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const sender = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const recipient1 = Wallet.generate({ provider }); @@ -16,12 +16,12 @@ const transfersToMake: TransferParams[] = [ { amount: 100, destination: recipient1.address, - assetId: provider.getBaseAssetId(), + assetId: await provider.getBaseAssetId(), }, { amount: 200, destination: recipient2.address, - assetId: provider.getBaseAssetId(), + assetId: await provider.getBaseAssetId(), }, { amount: 300, diff --git a/apps/docs/src/guide/wallets/snippets/unlocked-to-locked.ts b/apps/docs/src/guide/wallets/snippets/unlocked-to-locked.ts index cff1f034ad2..6960d4690de 100644 --- a/apps/docs/src/guide/wallets/snippets/unlocked-to-locked.ts +++ b/apps/docs/src/guide/wallets/snippets/unlocked-to-locked.ts @@ -4,7 +4,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL } from '../../../env'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const unlockedWallet: WalletUnlocked = Wallet.generate({ provider }); const newlyLockedWallet = unlockedWallet.lock(); diff --git a/apps/docs/src/guide/wallets/snippets/wallet-transferring/between-accounts.ts b/apps/docs/src/guide/wallets/snippets/wallet-transferring/between-accounts.ts index 59e071844ae..3e92372c051 100644 --- a/apps/docs/src/guide/wallets/snippets/wallet-transferring/between-accounts.ts +++ b/apps/docs/src/guide/wallets/snippets/wallet-transferring/between-accounts.ts @@ -7,12 +7,13 @@ import { WALLET_PVT_KEY_2, } from '../../../../env'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); +const baseAssetId = await provider.getBaseAssetId(); + const sender = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const destination = Wallet.fromPrivateKey(WALLET_PVT_KEY_2, provider); const amountToTransfer = 500; -const baseAssetId = sender.provider.getBaseAssetId(); const response = await sender.transfer( destination.address, diff --git a/apps/docs/src/guide/wallets/snippets/wallet-transferring/create-transfer-2.ts b/apps/docs/src/guide/wallets/snippets/wallet-transferring/create-transfer-2.ts index 4f441fd4ff7..1fb79b2a19a 100644 --- a/apps/docs/src/guide/wallets/snippets/wallet-transferring/create-transfer-2.ts +++ b/apps/docs/src/guide/wallets/snippets/wallet-transferring/create-transfer-2.ts @@ -7,12 +7,12 @@ import { WALLET_PVT_KEY_2, } from '../../../../env'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const sender = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const destination = Wallet.fromPrivateKey(WALLET_PVT_KEY_2, provider); const amountToTransfer = 200; -const assetId = provider.getBaseAssetId(); +const assetId = await provider.getBaseAssetId(); const transactionRequest = await sender.createTransfer( destination.address, @@ -20,7 +20,7 @@ const transactionRequest = await sender.createTransfer( assetId ); -const chainId = provider.getChainId(); +const chainId = await provider.getChainId(); const transactionId = transactionRequest.getTransactionId(chainId); diff --git a/apps/docs/src/guide/wallets/snippets/wallet-transferring/create-transfer.ts b/apps/docs/src/guide/wallets/snippets/wallet-transferring/create-transfer.ts index 3c14d7a770a..e6c12889ed1 100644 --- a/apps/docs/src/guide/wallets/snippets/wallet-transferring/create-transfer.ts +++ b/apps/docs/src/guide/wallets/snippets/wallet-transferring/create-transfer.ts @@ -7,12 +7,12 @@ import { WALLET_PVT_KEY_2, } from '../../../../env'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const sender = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const destination = Wallet.fromPrivateKey(WALLET_PVT_KEY_2, provider); const amountToTransfer = 200; -const assetId = provider.getBaseAssetId(); +const assetId = await provider.getBaseAssetId(); const transactionRequest = await sender.createTransfer( destination.address, @@ -20,7 +20,7 @@ const transactionRequest = await sender.createTransfer( assetId ); -const chainId = provider.getChainId(); +const chainId = await provider.getChainId(); const transactionId = transactionRequest.getTransactionId(chainId); diff --git a/apps/docs/src/guide/wallets/snippets/wallet-transferring/transferring-to-contracts.ts b/apps/docs/src/guide/wallets/snippets/wallet-transferring/transferring-to-contracts.ts index 1644994a6fb..96089eb75cd 100644 --- a/apps/docs/src/guide/wallets/snippets/wallet-transferring/transferring-to-contracts.ts +++ b/apps/docs/src/guide/wallets/snippets/wallet-transferring/transferring-to-contracts.ts @@ -4,13 +4,13 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { CounterFactory } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const sender = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const deploy = await CounterFactory.deploy(sender); const { contract } = await deploy.waitForResult(); const amountToTransfer = 400; -const assetId = provider.getBaseAssetId(); +const assetId = await provider.getBaseAssetId(); const contractId = contract.id; const tx = await sender.transferToContract( diff --git a/apps/docs/src/guide/wallets/snippets/wallet-transferring/transferring-to-multiple-contracts.ts b/apps/docs/src/guide/wallets/snippets/wallet-transferring/transferring-to-multiple-contracts.ts index d735150269c..6eb4ae76df8 100644 --- a/apps/docs/src/guide/wallets/snippets/wallet-transferring/transferring-to-multiple-contracts.ts +++ b/apps/docs/src/guide/wallets/snippets/wallet-transferring/transferring-to-multiple-contracts.ts @@ -6,9 +6,9 @@ import { TestAssetId } from 'fuels/test-utils'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { CounterFactory, EchoValuesFactory } from '../../../../typegend'; -const provider = await Provider.create(LOCAL_NETWORK_URL); +const provider = new Provider(LOCAL_NETWORK_URL); const sender = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); -const baseAssetId = provider.getBaseAssetId(); +const baseAssetId = await provider.getBaseAssetId(); const assetA = TestAssetId.A.value; const deploy1 = await CounterFactory.deploy(sender); diff --git a/packages/account/src/account.test.ts b/packages/account/src/account.test.ts index afdf434f5d4..7b1cb7c2089 100644 --- a/packages/account/src/account.test.ts +++ b/packages/account/src/account.test.ts @@ -119,12 +119,14 @@ describe('Account', () => { provider ); + const assetId = await provider.getBaseAssetId(); + const { coins } = await account.getCoins(); const assetA = coins.find((c) => c.assetId === ASSET_A); expect(assetA?.amount.gt(1)).toBeTruthy(); const assetB = coins.find((c) => c.assetId === ASSET_B); expect(assetB?.amount.gt(1)).toBeTruthy(); - const assetC = coins.find((c) => c.assetId === provider.getBaseAssetId()); + const assetC = coins.find((c) => c.assetId === assetId); expect(assetC?.amount.gt(1)).toBeTruthy(); }); @@ -227,7 +229,7 @@ describe('Account', () => { provider ); - const newProviderInstance = await Provider.create(provider.url); + const newProviderInstance = new Provider(provider.url); expect(account.provider).not.toBe(newProviderInstance); @@ -276,13 +278,13 @@ describe('Account', () => { expect(addAmountToCoinQuantitiesSpy).toBeCalledTimes(1); expect(addAmountToCoinQuantitiesSpy).toHaveBeenCalledWith({ amount: bn(fee), - assetId: provider.getBaseAssetId(), + assetId: await provider.getBaseAssetId(), coinQuantities: quantities, }); const expectedTotalResources = [ { amount: bn(quantities[0].amount), assetId: quantities[0].assetId }, - { amount: bn(fee), assetId: provider.getBaseAssetId() }, + { amount: bn(fee), assetId: await provider.getBaseAssetId() }, ]; expect(getResourcesToSpendSpy).toHaveBeenCalled(); expect(getResourcesToSpendSpy).toBeCalledWith(expectedTotalResources, { @@ -422,7 +424,11 @@ describe('Account', () => { ]; const transferConfig: TransferParams[] = [ - { amount: amounts[0], destination: receivers[0].address, assetId: provider.getBaseAssetId() }, + { + amount: amounts[0], + destination: receivers[0].address, + assetId: await provider.getBaseAssetId(), + }, { amount: amounts[1], destination: receivers[1].address, assetId: ASSET_A }, { amount: amounts[2], destination: receivers[2].address, assetId: ASSET_B }, { amount: amounts[3], destination: receivers[2].address, assetId: ASSET_A }, @@ -433,7 +439,11 @@ describe('Account', () => { expect(isStatusSuccess).toBeTruthy(); const expectedBalances = [ - { receiver: receivers[0], assetId: provider.getBaseAssetId(), expectedBalance: amounts[0] }, + { + receiver: receivers[0], + assetId: await provider.getBaseAssetId(), + expectedBalance: amounts[0], + }, { receiver: receivers[1], assetId: ASSET_A, expectedBalance: amounts[1] }, { receiver: receivers[2], assetId: ASSET_B, expectedBalance: amounts[2] }, { receiver: receivers[2], assetId: ASSET_A, expectedBalance: amounts[3] }, @@ -493,7 +503,7 @@ describe('Account', () => { const request = await sender.createTransfer( receiver.address.toB256(), 1, - provider.getBaseAssetId(), + await provider.getBaseAssetId(), { gasLimit: 10_000, } @@ -505,7 +515,7 @@ describe('Account', () => { const { balances: receiverBalances } = await receiver.getBalances(); expect(isStatusSuccess).toBeTruthy(); - expect(receiverBalances).toEqual([{ assetId: provider.getBaseAssetId(), amount: bn(1) }]); + expect(receiverBalances).toEqual([{ assetId: await provider.getBaseAssetId(), amount: bn(1) }]); }); it('can set "gasLimit" and "maxFee" when transferring amounts', async () => { @@ -520,7 +530,7 @@ describe('Account', () => { const gasLimit = 30_000; const maxFee = 60_000; - const request = await sender.createTransfer(receiver, 1, provider.getBaseAssetId(), { + const request = await sender.createTransfer(receiver, 1, await provider.getBaseAssetId(), { gasLimit, maxFee, }); @@ -544,7 +554,7 @@ describe('Account', () => { const receiver = Wallet.generate({ provider }); - const tx = await sender.transfer(receiver.address, 1, provider.getBaseAssetId(), { + const tx = await sender.transfer(receiver.address, 1, await provider.getBaseAssetId(), { gasLimit: 1000, tip: 10, witnessLimit: 10000, @@ -552,7 +562,7 @@ describe('Account', () => { const response = await tx.wait(); const { balances: receiverBalances } = await receiver.getBalances(); - expect(receiverBalances).toEqual([{ assetId: provider.getBaseAssetId(), amount: bn(1) }]); + expect(receiverBalances).toEqual([{ assetId: await provider.getBaseAssetId(), amount: bn(1) }]); expect(response.isStatusSuccess).toBeTruthy(); }); @@ -685,7 +695,7 @@ describe('Account', () => { // Wait for the next block to be minter on out case we are using a local provider // so we can create a new tx to generate next block - const resp = await sender.transfer(recipient, AMOUNT, provider.getBaseAssetId(), { + const resp = await sender.transfer(recipient, AMOUNT, await provider.getBaseAssetId(), { gasLimit: 10_000, }); const nextBlock = await resp.waitForResult(); @@ -719,7 +729,7 @@ describe('Account', () => { // seed wallet with 3 distinct utxos const amount = bn(1_500_000); for (let i = 0; i < 3; i++) { - request.addCoinOutput(sender.address, amount.div(3), provider.getBaseAssetId()); + request.addCoinOutput(sender.address, amount.div(3), await provider.getBaseAssetId()); } const txCost = await fundingWallet.getTransactionCost(request); @@ -732,13 +742,15 @@ describe('Account', () => { const tx1 = await fundingWallet.sendTransaction(request); await tx1.waitForResult(); - const transfer = await sender.transfer(receiver.address, 110, provider.getBaseAssetId(), { + const transfer = await sender.transfer(receiver.address, 110, await provider.getBaseAssetId(), { gasLimit: 10_000, }); await transfer.wait(); const { balances: receiverBalances } = await receiver.getBalances(); - expect(receiverBalances).toEqual([{ assetId: provider.getBaseAssetId(), amount: bn(110) }]); + expect(receiverBalances).toEqual([ + { assetId: await provider.getBaseAssetId(), amount: bn(110) }, + ]); }); it('can generate and use fake coins', async () => { @@ -754,7 +766,7 @@ describe('Account', () => { const amountToTransferBaseAsset = bn(1000); const fakeCoinsConfig: FakeResources[] = [ - { amount: amount1, assetId: provider.getBaseAssetId() }, + { amount: amount1, assetId: await provider.getBaseAssetId() }, { amount: amount2, assetId: ASSET_A }, { amount: amount3, assetId: ASSET_B }, ]; @@ -769,7 +781,7 @@ describe('Account', () => { request.addCoinOutput( Address.fromRandom(), amountToTransferBaseAsset, - provider.getBaseAssetId() + await provider.getBaseAssetId() ); request.addCoinOutput(Address.fromRandom(), amount2, ASSET_A); request.addCoinOutput(Address.fromRandom(), amount3, ASSET_B); @@ -796,7 +808,7 @@ describe('Account', () => { const fundingAmount = bn(1_500_000); for (let i = 0; i < 3; i++) { - request.addCoinOutput(sender.address, fundingAmount.div(3), provider.getBaseAssetId()); + request.addCoinOutput(sender.address, fundingAmount.div(3), await provider.getBaseAssetId()); } const txCost = await fundingWallet.getTransactionCost(request); @@ -857,7 +869,7 @@ describe('Account', () => { } = launched; await expect(async () => { - const result = await sender.transfer(receiver.address, 1, provider.getBaseAssetId(), { + const result = await sender.transfer(receiver.address, 1, await provider.getBaseAssetId(), { gasLimit: 0, }); await result.wait(); @@ -895,14 +907,14 @@ describe('Account', () => { await expectToThrowFuelError( async () => { - await sender.transfer(receiver.address, 0, provider.getBaseAssetId()); + await sender.transfer(receiver.address, 0, await provider.getBaseAssetId()); }, new FuelError(ErrorCode.INVALID_TRANSFER_AMOUNT, 'Transfer amount must be a positive number.') ); await expectToThrowFuelError( async () => { - await sender.transfer(receiver.address, -1, provider.getBaseAssetId()); + await sender.transfer(receiver.address, -1, await provider.getBaseAssetId()); }, new FuelError(ErrorCode.INVALID_TRANSFER_AMOUNT, 'Transfer amount must be a positive number.') ); @@ -919,15 +931,19 @@ describe('Account', () => { await account.getCoins(); expect(spy.mock.calls[0]).toStrictEqual([account.address, undefined, undefined]); - await account.getCoins(provider.getBaseAssetId()); + await account.getCoins(await provider.getBaseAssetId()); expect(spy.mock.calls[1]).toStrictEqual([ account.address, - provider.getBaseAssetId(), + await provider.getBaseAssetId(), undefined, ]); - await account.getCoins(provider.getBaseAssetId(), args); - expect(spy.mock.calls[2]).toStrictEqual([account.address, provider.getBaseAssetId(), args]); + await account.getCoins(await provider.getBaseAssetId(), args); + expect(spy.mock.calls[2]).toStrictEqual([ + account.address, + await provider.getBaseAssetId(), + args, + ]); expect(spy).toHaveBeenCalled(); vi.restoreAllMocks(); @@ -965,7 +981,7 @@ describe('Account', () => { } = launched; const request = new ScriptTransactionRequest(); - request.addCoinOutput(wallet.address, 30_000, provider.getBaseAssetId()); + request.addCoinOutput(wallet.address, 30_000, await provider.getBaseAssetId()); const txCost = await wallet.getTransactionCost(request); @@ -994,10 +1010,13 @@ describe('Account', () => { const { balances } = await wallet.getBalances(); + const baseAssetId = await provider.getBaseAssetId(); + expect(balances.length).toBe(3); + balances.forEach((balance) => { expect(balance.amount.toNumber()).toBe(fundAmount); - expect([provider.getBaseAssetId(), ASSET_A, ASSET_B].includes(balance.assetId)).toBeTruthy(); + expect([baseAssetId, ASSET_A, ASSET_B].includes(balance.assetId)).toBeTruthy(); }); }); }); diff --git a/packages/account/src/account.ts b/packages/account/src/account.ts index 60484577999..3f48d1911c5 100644 --- a/packages/account/src/account.ts +++ b/packages/account/src/account.ts @@ -56,13 +56,13 @@ export type TxParamsType = Pick< export type TransferParams = { destination: string | AbstractAddress; amount: BigNumberish; - assetId?: BytesLike; + assetId: BytesLike; }; export type ContractTransferParams = { contractId: string | AbstractAddress; amount: BigNumberish; - assetId?: BytesLike; + assetId: BytesLike; }; export type EstimatedTxParams = Pick< @@ -184,7 +184,7 @@ export class Account extends AbstractAccount { * @returns A promise that resolves to the balance amount. */ async getBalance(assetId?: BytesLike): Promise { - const assetIdToFetch = assetId ?? this.provider.getBaseAssetId(); + const assetIdToFetch = assetId ?? (await this.provider.getBaseAssetId()); const amount = await this.provider.getBalance(this.address, assetIdToFetch); return amount; } @@ -211,7 +211,7 @@ export class Account extends AbstractAccount { params; const fee = request.maxFee; - const baseAssetId = this.provider.getBaseAssetId(); + const baseAssetId = await this.provider.getBaseAssetId(); const requiredInBaseAsset = requiredQuantities.find((quantity) => quantity.assetId === baseAssetId)?.amount || bn(0); @@ -308,7 +308,7 @@ export class Account extends AbstractAccount { ); } - this.provider.validateTransaction(request); + await this.provider.validateTransaction(request); request.updatePredicateGasUsed(estimatedPredicates); @@ -347,8 +347,15 @@ export class Account extends AbstractAccount { txParams: TxParamsType = {} ): Promise { let request = new ScriptTransactionRequest(txParams); - request = this.addTransfer(request, { destination, amount, assetId }); + + request = this.addTransfer(request, { + destination, + amount, + assetId: assetId || (await this.provider.getBaseAssetId()), + }); + request = await this.estimateAndFundTransaction(request, txParams); + return request; } @@ -398,11 +405,7 @@ export class Account extends AbstractAccount { addTransfer(request: ScriptTransactionRequest, transferParams: TransferParams) { const { destination, amount, assetId } = transferParams; this.validateTransferAmount(amount); - request.addCoinOutput( - Address.fromAddressOrString(destination), - amount, - assetId ?? this.provider.getBaseAssetId() - ); + request.addCoinOutput(Address.fromAddressOrString(destination), amount, assetId); return request; } @@ -437,7 +440,7 @@ export class Account extends AbstractAccount { async transferToContract( contractId: string | AbstractAddress, amount: BigNumberish, - assetId?: BytesLike, + assetId: BytesLike, txParams: TxParamsType = {} ): Promise { return this.batchTransferToContracts([{ amount, assetId, contractId }], txParams); @@ -453,13 +456,13 @@ export class Account extends AbstractAccount { const quantities: CoinQuantity[] = []; + const defaultAssetId = await this.provider.getBaseAssetId(); + const transferParams = contractTransferParams.map((transferParam) => { const amount = bn(transferParam.amount); const contractAddress = Address.fromAddressOrString(transferParam.contractId); - const assetId = transferParam.assetId - ? hexlify(transferParam.assetId) - : this.provider.getBaseAssetId(); + const assetId = transferParam.assetId ? hexlify(transferParam.assetId) : defaultAssetId; if (amount.lte(0)) { throw new FuelError( @@ -517,7 +520,7 @@ export class Account extends AbstractAccount { const params: ScriptTransactionRequestLike = { script, ...txParams }; - const baseAssetId = this.provider.getBaseAssetId(); + const baseAssetId = await this.provider.getBaseAssetId(); let request = new ScriptTransactionRequest(params); const quantities = [{ amount: bn(amount), assetId: baseAssetId }]; @@ -550,7 +553,7 @@ export class Account extends AbstractAccount { { signatureCallback, quantities = [] }: TransactionCostParams = {} ): Promise { const txRequestClone = clone(transactionRequestify(transactionRequestLike)); - const baseAssetId = this.provider.getBaseAssetId(); + const baseAssetId = await this.provider.getBaseAssetId(); // Fund with fake UTXOs to avoid not enough funds error // Getting coin quantities from amounts being transferred diff --git a/packages/account/src/connectors/fuel.ts b/packages/account/src/connectors/fuel.ts index d0caf31ddb1..2ebaa84a1fb 100644 --- a/packages/account/src/connectors/fuel.ts +++ b/packages/account/src/connectors/fuel.ts @@ -447,11 +447,11 @@ export class Fuel extends FuelConnector implements FuelSdk { provider = providerOrNetwork; // If the provided param is a valid network use it } else if (providerOrNetwork && 'chainId' in providerOrNetwork && 'url' in providerOrNetwork) { - provider = await Provider.create(providerOrNetwork.url); + provider = new Provider(providerOrNetwork.url); // If nor provider or network is provided use the current network } else if (!providerOrNetwork) { const currentNetwork = await this.currentNetwork(); - provider = await Provider.create(currentNetwork.url); + provider = new Provider(currentNetwork.url); // If a provider or network was informed but is not valid // throw an error } else { diff --git a/packages/account/src/providers/provider.test.ts b/packages/account/src/providers/provider.test.ts index d9775e3252d..9378e2d464a 100644 --- a/packages/account/src/providers/provider.test.ts +++ b/packages/account/src/providers/provider.test.ts @@ -91,7 +91,7 @@ describe('Provider', () => { } = launched; const { urlWithAuth, expectedHeaders } = createBasicAuth(url); - const provider = await Provider.create(urlWithAuth); + const provider = new Provider(urlWithAuth); const fetchSpy = vi.spyOn(global, 'fetch'); @@ -107,7 +107,7 @@ describe('Provider', () => { const { provider: { url }, } = launched; - const provider = await Provider.create(url); + const provider = new Provider(url); const fetchSpy = vi.spyOn(global, 'fetch'); @@ -125,7 +125,7 @@ describe('Provider', () => { } = launched; const { urlWithAuth, expectedHeaders } = createBasicAuth(url); - const provider = await Provider.create(urlWithAuth); + const provider = new Provider(urlWithAuth); const fetchSpy = vi.spyOn(global, 'fetch'); @@ -136,7 +136,7 @@ describe('Provider', () => { expect(requestA?.headers).toMatchObject(expectedHeaders); // Reuse the provider URL to connect to an authenticated endpoint - const newProvider = await Provider.create(provider.url); + const newProvider = new Provider(provider.url); fetchSpy.mockClear(); @@ -156,9 +156,9 @@ describe('Provider', () => { const requestMiddleware = vi.fn().mockImplementation((options) => options); - await Provider.create(urlWithAuth, { - requestMiddleware, - }); + const temp = new Provider(urlWithAuth, { requestMiddleware }); + + await temp.init(); expect(requestMiddleware).toHaveBeenCalled(); }); @@ -175,7 +175,7 @@ describe('Provider', () => { // Should enable connection via `create` method const basicAuthA = createBasicAuth(urlA); - const provider = await Provider.create(basicAuthA.urlWithAuth); + const provider = new Provider(basicAuthA.urlWithAuth); const fetchSpy = vi.spyOn(global, 'fetch'); @@ -216,7 +216,7 @@ describe('Provider', () => { 'X-Custom-Header': 'custom-value', }; - const provider = await Provider.create(url, { + const provider = new Provider(url, { headers: customHeaders, }); @@ -231,7 +231,7 @@ describe('Provider', () => { const url = 'immanotavalidurl'; await expectToThrowFuelError( - async () => Provider.create(url), + () => new Provider(url), new FuelError(ErrorCode.INVALID_URL, 'Invalid URL provided.') ); }); @@ -240,7 +240,7 @@ describe('Provider', () => { using launched = await setupTestProviderAndWallets(); const { provider } = launched; - const mockProvider = await Provider.create(provider.url, { + const mockProvider = new Provider(provider.url, { fetch: getCustomFetch('getTransaction', { transaction: { id: '0x1234567890abcdef', @@ -270,7 +270,7 @@ describe('Provider', () => { const { provider: nodeProvider } = launched; // Create a mock provider with custom getTransactions operation - const mockProvider = await Provider.create(nodeProvider.url, { + const mockProvider = new Provider(nodeProvider.url, { fetch: getCustomFetch('getTransactions', { transactions: { edges: [ @@ -325,7 +325,7 @@ describe('Provider', () => { it('can call()', async () => { using launched = await setupTestProviderAndWallets(); const { provider } = launched; - const baseAssetId = provider.getBaseAssetId(); + const baseAssetId = await provider.getBaseAssetId(); const CoinInputs: CoinTransactionRequestInput[] = [ { @@ -391,9 +391,10 @@ describe('Provider', () => { it('can get all chain info', async () => { using launched = await setupTestProviderAndWallets(); + const { provider } = launched; - const { consensusParameters } = provider.getChain(); + const { consensusParameters } = await provider.getChain(); expect(consensusParameters.version).toBeDefined(); expect(consensusParameters.chainId).toBeDefined(); @@ -430,7 +431,7 @@ describe('Provider', () => { using launched = await setupTestProviderAndWallets(); const { provider } = launched; - const chainId = provider.getChainId(); + const chainId = await provider.getChainId(); expect(chainId).toBe(0); }); @@ -439,7 +440,7 @@ describe('Provider', () => { using launched = await setupTestProviderAndWallets(); const { provider } = launched; - const baseAssetId = provider.getBaseAssetId(); + const baseAssetId = await provider.getBaseAssetId(); expect(baseAssetId).toBeDefined(); }); @@ -465,7 +466,7 @@ describe('Provider', () => { const providerUrl = providerForUrl.url; - const provider = await Provider.create(providerUrl, { + const provider = new Provider(providerUrl, { fetch: getCustomFetch('getVersion', { nodeInfo: { nodeVersion: '0.30.0' } }), }); @@ -489,12 +490,14 @@ describe('Provider', () => { nodeInfo: {} as NodeInfo, }); - const provider = await Provider.create(providerUrl, { + const provider = new Provider(providerUrl, { fetch: () => { throw new Error('This should never happen'); }, }); + await provider.init(); + expect(fetchChainAndNodeInfo).toHaveBeenCalledTimes(1); /** @@ -634,7 +637,7 @@ describe('Provider', () => { wallets: [wallet, receiver], } = launched; - const baseAssetId = provider.getBaseAssetId(); + const baseAssetId = await provider.getBaseAssetId(); const { coins } = await wallet.getCoins(baseAssetId); expect(coins.length).toBe(utxosAmount); @@ -670,7 +673,7 @@ describe('Provider', () => { wallets: [wallet, receiver], } = launched; - const baseAssetId = provider.getBaseAssetId(); + const baseAssetId = await provider.getBaseAssetId(); const maxFee = 100_000; const transferAmount = 10_000; @@ -717,7 +720,7 @@ describe('Provider', () => { wallets: [wallet, receiver], } = launched; - const baseAssetId = provider.getBaseAssetId(); + const baseAssetId = await provider.getBaseAssetId(); const maxFee = 100_000; const transferAmount = 10_000; @@ -774,7 +777,7 @@ describe('Provider', () => { provider, wallets: [wallet, receiver], } = launched; - const baseAssetId = provider.getBaseAssetId(); + const baseAssetId = await provider.getBaseAssetId(); const transferAmount = 10_000; const { @@ -864,11 +867,11 @@ describe('Provider', () => { const quantities = [ coinQuantityfy([1000, ASSET_A]), coinQuantityfy([500, ASSET_B]), - coinQuantityfy([5000, provider.getBaseAssetId()]), + coinQuantityfy([5000, await provider.getBaseAssetId()]), ]; const resources = await sender.getResourcesToSpend(quantities); - request.addCoinOutput(receiver.address, 500, provider.getBaseAssetId()); + request.addCoinOutput(receiver.address, 500, await provider.getBaseAssetId()); request.addResources(resources); // We need to add more resources manually here as a single `getResourcesToSpend` call @@ -899,9 +902,9 @@ describe('Provider', () => { } = launched; const request = new ScriptTransactionRequest(); - request.addCoinOutput(wallet.address, 40_000, provider.getBaseAssetId()); + request.addCoinOutput(wallet.address, 40_000, await provider.getBaseAssetId()); - const { coins } = await wallet.getCoins(provider.getBaseAssetId()); + const { coins } = await wallet.getCoins(await provider.getBaseAssetId()); request.addResources(coins); await expectToThrowFuelError(() => wallet.getTransactionCost(request), { @@ -937,7 +940,7 @@ describe('Provider', () => { provider, } = launched; - const baseAssetId = provider.getBaseAssetId(); + const baseAssetId = await provider.getBaseAssetId(); const request = new ScriptTransactionRequest(); const resources = await sender.getResourcesToSpend([[1000, baseAssetId]]); @@ -1039,7 +1042,7 @@ describe('Provider', () => { using launched = await setupTestProviderAndWallets(); const { provider: nodeProvider } = launched; - const provider = await Provider.create(nodeProvider.url, { + const provider = new Provider(nodeProvider.url, { fetch: async (url, options) => getCustomFetch('getMessageProof', { messageProof: MESSAGE_PROOF_RAW_RESPONSE })( url, @@ -1062,7 +1065,7 @@ describe('Provider', () => { using launched = await setupTestProviderAndWallets(); const { provider: nodeProvider } = launched; - const provider = await Provider.create(nodeProvider.url, { + const provider = new Provider(nodeProvider.url, { fetch: async (url, options) => getCustomFetch('getMessageStatus', { messageStatus: messageStatusResponse })(url, options), }); @@ -1079,17 +1082,17 @@ describe('Provider', () => { // check if the provider was initialized properly expect(provider).toBeInstanceOf(Provider); - expect(provider.getChain()).toBeDefined(); - expect(provider.getNode()).toBeDefined(); + expect(await provider.getChain()).toBeDefined(); + expect(await provider.getNode()).toBeDefined(); }); it('should ensure getChain and getNode uses the cache and does not fetch new data', async () => { using launched = await setupTestProviderAndWallets(); const { provider } = launched; - const { error } = await safeExec(() => { - provider.getChain(); - provider.getNode(); + const { error } = await safeExec(async () => { + await provider.getChain(); + await provider.getNode(); }); expect(error).toBeUndefined(); @@ -1104,9 +1107,7 @@ describe('Provider', () => { const INSTANCES_NUM = 5; - const promises = Array.from({ length: INSTANCES_NUM }, async () => - Provider.create(provider.url) - ); + const promises = Array.from({ length: INSTANCES_NUM }, () => new Provider(provider.url).init()); await Promise.all(promises); expect(spyFetchChainAndNodeInfo).toHaveBeenCalledTimes(INSTANCES_NUM); @@ -1131,7 +1132,7 @@ describe('Provider', () => { using launched = await setupTestProviderAndWallets(); const { provider } = launched; - const gasConfig = provider.getGasConfig(); + const gasConfig = await provider.getGasConfig(); expect(gasConfig.gasPerByte).toBeDefined(); expect(gasConfig.gasPriceFactor).toBeDefined(); @@ -1139,14 +1140,14 @@ describe('Provider', () => { expect(gasConfig.maxGasPerTx).toBeDefined(); }); - it('should throws when using getChain or getNode and without cached data', async () => { + it.skip('should throws when using getChain or getNode and without cached data', async () => { using launched = await setupTestProviderAndWallets(); const { provider } = launched; Provider.clearChainAndNodeCaches(); await expectToThrowFuelError( - () => provider.getChain(), + async () => provider.getChain(), new FuelError( ErrorCode.CHAIN_INFO_CACHE_EMPTY, 'Chain info cache is empty. Make sure you have called `Provider.create` to initialize the provider.' @@ -1186,7 +1187,7 @@ describe('Provider', () => { using launched = await setupTestProviderAndWallets(); const { provider } = launched; - await Provider.create(provider.url); + await new Provider(provider.url).init(); expect(consoleWarnSpy).toHaveBeenCalledOnce(); expect(consoleWarnSpy).toHaveBeenCalledWith( @@ -1221,7 +1222,7 @@ Supported fuel-core version: ${mock.supportedVersion}.` using launched = await setupTestProviderAndWallets(); const { provider } = launched; - await Provider.create(provider.url); + await new Provider(provider.url).init(); expect(consoleWarnSpy).toHaveBeenCalledOnce(); expect(consoleWarnSpy).toHaveBeenCalledWith( @@ -1249,7 +1250,8 @@ Supported fuel-core version: ${mock.supportedVersion}.` { code: FuelError.CODES.INVALID_REQUEST } ); - const response = new TransactionResponse('invalid transaction id', provider); + const chainId = await provider.getChainId(); + const response = new TransactionResponse('invalid transaction id', provider, chainId); await expectToThrowFuelError(() => response.waitForResult(), { code: FuelError.CODES.INVALID_REQUEST, @@ -1311,7 +1313,7 @@ Supported fuel-core version: ${mock.supportedVersion}.` it('should ensure calculateMaxgas considers gasLimit for ScriptTransactionRequest', async () => { using launched = await setupTestProviderAndWallets(); const { provider } = launched; - const { gasPerByte, maxGasPerTx } = provider.getGasConfig(); + const { gasPerByte, maxGasPerTx } = await provider.getGasConfig(); const gasLimit = bn(1000); const transactionRequest = new ScriptTransactionRequest({ @@ -1320,7 +1322,7 @@ Supported fuel-core version: ${mock.supportedVersion}.` const maxGasSpy = vi.spyOn(gasMod, 'getMaxGas'); - const chainInfo = provider.getChain(); + const chainInfo = await provider.getChain(); const minGas = bn(200); const witnessesLength = transactionRequest @@ -1341,7 +1343,7 @@ Supported fuel-core version: ${mock.supportedVersion}.` it('should ensure calculateMaxgas does NOT considers gasLimit for CreateTransactionRequest', async () => { using launched = await setupTestProviderAndWallets(); const { provider } = launched; - const { gasPerByte, maxGasPerTx } = provider.getGasConfig(); + const { gasPerByte, maxGasPerTx } = await provider.getGasConfig(); const transactionRequest = new CreateTransactionRequest({ witnesses: [ZeroBytes32], @@ -1351,7 +1353,7 @@ Supported fuel-core version: ${mock.supportedVersion}.` const maxGasSpy = vi.spyOn(gasMod, 'getMaxGas'); - const chainInfo = provider.getChain(); + const chainInfo = await provider.getChain(); const minGas = bn(700); const witnessesLength = transactionRequest @@ -1394,7 +1396,7 @@ Supported fuel-core version: ${mock.supportedVersion}.` } = launched; const request = new ScriptTransactionRequest(); - request.addCoinOutput(wallet.address, 1000, provider.getBaseAssetId()); + request.addCoinOutput(wallet.address, 1000, await provider.getBaseAssetId()); const spyGetGasUsedFromReceipts = vi.spyOn(gasMod, 'getGasUsedFromReceipts'); const cost = await wallet.getTransactionCost(request); @@ -1410,7 +1412,7 @@ Supported fuel-core version: ${mock.supportedVersion}.` using launched = await setupTestProviderAndWallets(); const { provider } = launched; - const baseAssetId = provider.getBaseAssetId(); + const baseAssetId = await provider.getBaseAssetId(); const b256Str = Address.fromRandom().toB256(); const methodCalls = [ @@ -1748,13 +1750,14 @@ Supported fuel-core version: ${mock.supportedVersion}.` Provider.clearChainAndNodeCaches(); const fetchSpy = vi.spyOn(global, 'fetch'); - await Provider.create(provider.url, { + + await new Provider(provider.url, { requestMiddleware: (request) => { request.headers ??= {}; (request.headers as Record)['x-custom-header'] = 'custom-value'; return request; }, - }); + }).init(); const requestObject = fetchSpy.mock.calls[0][1]; @@ -1769,13 +1772,14 @@ Supported fuel-core version: ${mock.supportedVersion}.` Provider.clearChainAndNodeCaches(); const fetchSpy = vi.spyOn(global, 'fetch'); - await Provider.create(provider.url, { + + await new Provider(provider.url, { requestMiddleware: (request) => { request.headers ??= {}; (request.headers as Record)['x-custom-header'] = 'custom-value'; return Promise.resolve(request); }, - }); + }).init(); const requestObject = fetchSpy.mock.calls[0][1]; @@ -1789,7 +1793,7 @@ Supported fuel-core version: ${mock.supportedVersion}.` const { provider: nodeProvider } = launched; const fetchSpy = vi.spyOn(global, 'fetch'); - const provider = await Provider.create(nodeProvider.url, { + const provider = new Provider(nodeProvider.url, { requestMiddleware: (request) => { request.headers ??= {}; (request.headers as Record)['x-custom-header'] = 'custom-value'; @@ -1821,7 +1825,8 @@ Supported fuel-core version: ${mock.supportedVersion}.` Provider.clearChainAndNodeCaches(); let requestHeaders: HeadersInit | undefined; - await Provider.create(provider.url, { + + await new Provider(provider.url, { fetch: async (url, requestInit) => { requestHeaders = requestInit?.headers; return fetch(url, requestInit); @@ -1831,7 +1836,7 @@ Supported fuel-core version: ${mock.supportedVersion}.` (request.headers as Record)['x-custom-header'] = 'custom-value'; return request; }, - }); + }).init(); expect(requestHeaders).toMatchObject({ 'x-custom-header': 'custom-value', @@ -1843,7 +1848,7 @@ Supported fuel-core version: ${mock.supportedVersion}.` const { provider: nodeProvider } = launched; const timeout = 500; - const provider = await Provider.create(nodeProvider.url, { + const provider = new Provider(nodeProvider.url, { fetch: async (url, requestInit) => fetch(url, requestInit), timeout, }); @@ -1952,7 +1957,7 @@ Supported fuel-core version: ${mock.supportedVersion}.` wallets: [wallet], } = launched; - const baseAssetId = provider.getBaseAssetId(); + const baseAssetId = await provider.getBaseAssetId(); // can fetch 1000 coins let { coins, pageInfo } = await provider.getCoins(wallet.address, baseAssetId, { @@ -2146,7 +2151,7 @@ Supported fuel-core version: ${mock.supportedVersion}.` }, }); const { provider } = launched; - const baseAssetId = provider.getBaseAssetId(); + const baseAssetId = await provider.getBaseAssetId(); const address = Address.fromRandom(); const exceededLimit = RESOURCES_PAGE_SIZE_LIMIT + 1; const safeLimit = BLOCKS_PAGE_SIZE_LIMIT; @@ -2243,7 +2248,7 @@ Supported fuel-core version: ${mock.supportedVersion}.` wallets: [wallet], } = launched; - const baseAssetId = provider.getBaseAssetId(); + const baseAssetId = await provider.getBaseAssetId(); const { balances } = await provider.getBalances(wallet.address); @@ -2258,7 +2263,7 @@ Supported fuel-core version: ${mock.supportedVersion}.` test('should not refetch consensus params in less than 1min', async () => { using launched = await setupTestProviderAndWallets(); - const provider = await Provider.create(launched.provider.url); + const provider = new Provider(launched.provider.url); const fetchChainAndNodeInfo = vi.spyOn(provider, 'fetchChainAndNodeInfo'); // calling twice @@ -2271,12 +2276,13 @@ Supported fuel-core version: ${mock.supportedVersion}.` test('should refetch consensus params if >1 min has passed', async () => { using launched = await setupTestProviderAndWallets(); - const provider = await Provider.create(launched.provider.url); + const provider = new Provider(launched.provider.url); const fetchChainAndNodeInfo = vi.spyOn(provider, 'fetchChainAndNodeInfo'); // calling twice await provider.autoRefetchConfigs(); provider.consensusParametersTimestamp = 0; + await provider.autoRefetchConfigs(); expect(fetchChainAndNodeInfo).toHaveBeenCalledTimes(2); diff --git a/packages/account/src/providers/provider.ts b/packages/account/src/providers/provider.ts index 5f9ffe88f42..4b3c25a800b 100644 --- a/packages/account/src/providers/provider.ts +++ b/packages/account/src/providers/provider.ts @@ -465,7 +465,7 @@ export default class Provider { * @param options - Additional options for the provider * @hidden */ - protected constructor(url: string, options: ProviderOptions = {}) { + constructor(url: string, options: ProviderOptions = {}) { const { url: rawUrl, urlWithoutAuth, headers: authHeaders } = Provider.extractBasicAuth(url); this.url = rawUrl; @@ -521,63 +521,44 @@ export default class Provider { } /** - * Creates a new instance of the Provider class. This is the recommended way to initialize a Provider. - * - * @param url - GraphQL endpoint of the Fuel node - * @param options - Additional options for the provider - * - * @returns A promise that resolves to a Provider instance. + * Initialize Provider async stuff */ - static async create(url: string, options: ProviderOptions = {}): Promise { - const provider = new Provider(url, options); - - await provider.fetchChainAndNodeInfo(); - - return provider; + async init(): Promise { + await this.fetchChainAndNodeInfo(); + return this; } /** - * Returns the cached chainInfo for the current URL. + * Returns the `chainInfo` for the current network. * * @returns the chain information configuration. */ - getChain(): ChainInfo { - const chain = Provider.chainInfoCache[this.urlWithoutAuth]; - if (!chain) { - throw new FuelError( - ErrorCode.CHAIN_INFO_CACHE_EMPTY, - 'Chain info cache is empty. Make sure you have called `Provider.create` to initialize the provider.' - ); - } - return chain; + async getChain(): Promise { + await this.init(); + return Provider.chainInfoCache[this.urlWithoutAuth]; } /** - * Returns the cached nodeInfo for the current URL. + * Returns the `nodeInfo` for the current network. * * @returns the node information configuration. */ - getNode(): NodeInfo { - const node = Provider.nodeInfoCache[this.urlWithoutAuth]; - if (!node) { - throw new FuelError( - ErrorCode.NODE_INFO_CACHE_EMPTY, - 'Node info cache is empty. Make sure you have called `Provider.create` to initialize the provider.' - ); - } - return node; + async getNode(): Promise { + await this.init(); + return Provider.nodeInfoCache[this.urlWithoutAuth]; } /** * Returns some helpful parameters related to gas fees. */ - getGasConfig() { + async getGasConfig() { const { txParameters: { maxGasPerTx }, predicateParameters: { maxGasPerPredicate }, feeParameters: { gasPriceFactor, gasPerByte }, gasCosts, - } = this.getChain().consensusParameters; + } = (await this.getChain()).consensusParameters; + return { maxGasPerTx, maxGasPerPredicate, @@ -602,7 +583,8 @@ export default class Provider { this.options = { ...this.options, headers: { ...this.options.headers, ...headers } }; this.operations = this.createOperations(); - await this.fetchChainAndNodeInfo(); + + await this.init(); } /** @@ -615,11 +597,14 @@ export default class Provider { let chain: ChainInfo; try { - if (ignoreCache) { - throw new Error(`Jumps to the catch block andre-fetch`); + nodeInfo = Provider.nodeInfoCache[this.urlWithoutAuth]; + chain = Provider.chainInfoCache[this.urlWithoutAuth]; + + const noCache = !nodeInfo || !chain; + + if (ignoreCache || noCache) { + throw new Error(`Jumps to the catch block and re-fetch`); } - nodeInfo = this.getNode(); - chain = this.getChain(); } catch (_err) { const data = await this.operations.getChainAndNodeInfo(); @@ -802,10 +787,10 @@ Supported fuel-core version: ${supportedVersion}.` * * @returns A promise that resolves to the chain ID number. */ - getChainId() { + async getChainId() { const { consensusParameters: { chainId }, - } = this.getChain(); + } = await this.getChain(); return chainId.toNumber(); } @@ -814,10 +799,11 @@ Supported fuel-core version: ${supportedVersion}.` * * @returns the base asset ID. */ - getBaseAssetId() { + async getBaseAssetId() { + const all = await this.getChain(); const { consensusParameters: { baseAssetId }, - } = this.getChain(); + } = all; return baseAssetId; } @@ -847,12 +833,12 @@ Supported fuel-core version: ${supportedVersion}.` /** * @hidden */ - validateTransaction(tx: TransactionRequest) { + async validateTransaction(tx: TransactionRequest) { const { consensusParameters: { txParameters: { maxInputs, maxOutputs }, }, - } = this.getChain(); + } = await this.getChain(); if (bn(tx.inputs.length).gt(maxInputs)) { throw new FuelError( ErrorCode.MAX_INPUTS_EXCEEDED, @@ -887,7 +873,7 @@ Supported fuel-core version: ${supportedVersion}.` await this.estimateTxDependencies(transactionRequest); } - this.validateTransaction(transactionRequest); + await this.validateTransaction(transactionRequest); const encodedTransaction = hexlify(transactionRequest.toTransactionBytes()); @@ -900,10 +886,11 @@ Supported fuel-core version: ${supportedVersion}.` this.#cacheInputs( transactionRequest.inputs, - transactionRequest.getTransactionId(this.getChainId()) + transactionRequest.getTransactionId(await this.getChainId()) ); - return new TransactionResponse(transactionRequest, this, abis, subscription); + const chainId = await this.getChainId(); + return new TransactionResponse(transactionRequest, this, chainId, abis, subscription); } /** @@ -1003,7 +990,7 @@ Supported fuel-core version: ${supportedVersion}.` let outputVariables = 0; let dryRunStatus: DryRunStatus | undefined; - this.validateTransaction(transactionRequest); + await this.validateTransaction(transactionRequest); for (let attempt = 0; attempt < MAX_RETRIES; attempt++) { const { @@ -1171,7 +1158,13 @@ Supported fuel-core version: ${supportedVersion}.` return; } - const chainInfo = this.getChain(); + // no cache? refetch. + if (!Provider.chainInfoCache?.[this.urlWithoutAuth]) { + await this.fetchChainAndNodeInfo(true); + return; + } + + const chainInfo = Provider.chainInfoCache[this.urlWithoutAuth]; const { consensusParameters: { version: previous }, @@ -1185,6 +1178,7 @@ Supported fuel-core version: ${supportedVersion}.` }, } = await this.operations.getConsensusParametersVersion(); + // old cache? refetch. if (previous !== current) { // calling with true to skip cache await this.fetchChainAndNodeInfo(true); @@ -1202,8 +1196,8 @@ Supported fuel-core version: ${supportedVersion}.` await this.autoRefetchConfigs(); - const chainInfo = this.getChain(); - const { gasPriceFactor, maxGasPerTx } = this.getGasConfig(); + const chainInfo = await this.getChain(); + const { gasPriceFactor, maxGasPerTx } = await this.getGasConfig(); const minGas = transactionRequest.calculateMinGas(chainInfo); if (!isDefined(gasPrice)) { @@ -1364,7 +1358,7 @@ Supported fuel-core version: ${supportedVersion}.` throw this.extractDryRunError(txRequestClone, receipts, dryRunStatus); } - const { maxGasPerTx } = this.getGasConfig(); + const { maxGasPerTx } = await this.getGasConfig(); const pristineGasUsed = getGasUsedFromReceipts(receipts); gasUsed = bn(pristineGasUsed.muln(GAS_USED_MODIFIER)).max(maxGasPerTx.sub(minGas)); @@ -2050,9 +2044,10 @@ Supported fuel-core version: ${supportedVersion}.` * @param transactionId - The transaction ID to get the response for. * @returns A promise that resolves to the transaction response. */ - // eslint-disable-next-line @typescript-eslint/require-await + async getTransactionResponse(transactionId: string): Promise { - return new TransactionResponse(transactionId, this); + const chainId = await this.getChainId(); + return new TransactionResponse(transactionId, this, chainId); } /** diff --git a/packages/account/src/providers/transaction-request/transaction-request.test.ts b/packages/account/src/providers/transaction-request/transaction-request.test.ts index abbbcd629e1..073b4597c90 100644 --- a/packages/account/src/providers/transaction-request/transaction-request.test.ts +++ b/packages/account/src/providers/transaction-request/transaction-request.test.ts @@ -121,17 +121,12 @@ describe('TransactionRequest', () => { it('adds account based witnesses', async () => { class ProviderCustom extends Provider { - // eslint-disable-next-line @typescript-eslint/require-await - static override async create(url: string) { - return new ProviderCustom(url, {}); - } - - override getChainId(): number { - return 1; + override async getChainId(): Promise { + return Promise.resolve(1); } } - const provider = await ProviderCustom.create('http://example.com'); + const provider = new ProviderCustom('http://example.com'); const signer = WalletUnlocked.generate({ provider }); const txRequest = new ScriptTransactionRequest(); diff --git a/packages/account/src/providers/transaction-response/transaction-response.ts b/packages/account/src/providers/transaction-response/transaction-response.ts index 845d41a7263..1b02a5cec38 100644 --- a/packages/account/src/providers/transaction-response/transaction-response.ts +++ b/packages/account/src/providers/transaction-response/transaction-response.ts @@ -145,10 +145,11 @@ export class TransactionResponse { constructor( tx: string | TransactionRequest, provider: Provider, + chainId: number, abis?: JsonAbisFromAllCalls, private submitTxSubscription?: AsyncIterable ) { - this.id = typeof tx === 'string' ? tx : tx.getTransactionId(provider.getChainId()); + this.id = typeof tx === 'string' ? tx : tx.getTransactionId(chainId); this.provider = provider; this.abis = abis; @@ -168,7 +169,8 @@ export class TransactionResponse { provider: Provider, abis?: JsonAbisFromAllCalls ): Promise { - const response = new TransactionResponse(id, provider, abis); + const chainId = await provider.getChainId(); + const response = new TransactionResponse(id, provider, chainId, abis); await response.fetch(); return response; } @@ -295,10 +297,11 @@ export class TransactionResponse { const { tx: transaction, bytes: transactionBytes } = await this.getTransaction(); - const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig(); + const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = + await this.provider.getGasConfig(); const gasPrice = await this.provider.getLatestGasPrice(); - const maxInputs = this.provider.getChain().consensusParameters.txParameters.maxInputs; - const baseAssetId = this.provider.getBaseAssetId(); + const maxInputs = (await this.provider.getChain()).consensusParameters.txParameters.maxInputs; + const baseAssetId = await this.provider.getBaseAssetId(); const transactionSummary = assembleTransactionSummary({ id: this.id, diff --git a/packages/account/src/providers/transaction-summary/assemble-transaction-summary.test.ts b/packages/account/src/providers/transaction-summary/assemble-transaction-summary.test.ts index f8cf0ff777b..ede6df68606 100644 --- a/packages/account/src/providers/transaction-summary/assemble-transaction-summary.test.ts +++ b/packages/account/src/providers/transaction-summary/assemble-transaction-summary.test.ts @@ -104,7 +104,7 @@ describe('TransactionSummary', () => { type: expect.any(String), }; - runTest(MOCK_SUCCESS_STATUS, expected, provider.getBaseAssetId()); + runTest(MOCK_SUCCESS_STATUS, expected, await provider.getBaseAssetId()); }); it('should assemble transaction summary just fine (FAILURE)', async () => { @@ -131,7 +131,7 @@ describe('TransactionSummary', () => { type: expect.any(String), }; - runTest(MOCK_FAILURE_STATUS, expected, provider.getBaseAssetId()); + runTest(MOCK_FAILURE_STATUS, expected, await provider.getBaseAssetId()); }); it('should assemble transaction summary just fine (SUBMITTED)', async () => { @@ -158,7 +158,7 @@ describe('TransactionSummary', () => { type: expect.any(String), }; - runTest(MOCK_SUBMITTED_STATUS, expected, provider.getBaseAssetId()); + runTest(MOCK_SUBMITTED_STATUS, expected, await provider.getBaseAssetId()); }); it('should assemble transaction summary just fine (SQUEEZEDOUT)', async () => { @@ -185,6 +185,6 @@ describe('TransactionSummary', () => { type: expect.any(String), }; - runTest(MOCK_SQUEEZEDOUT_STATUS, expected, provider.getBaseAssetId()); + runTest(MOCK_SQUEEZEDOUT_STATUS, expected, await provider.getBaseAssetId()); }); }); diff --git a/packages/account/src/providers/transaction-summary/get-transaction-summary.ts b/packages/account/src/providers/transaction-summary/get-transaction-summary.ts index 2ed5e7c490b..7c8fa136757 100644 --- a/packages/account/src/providers/transaction-summary/get-transaction-summary.ts +++ b/packages/account/src/providers/transaction-summary/get-transaction-summary.ts @@ -59,10 +59,10 @@ export async function getTransactionSummary( txParameters: { maxInputs, maxGasPerTx }, gasCosts, }, - } = provider.getChain(); + } = await provider.getChain(); const gasPrice = await provider.getLatestGasPrice(); - const baseAssetId = provider.getBaseAssetId(); + const baseAssetId = await provider.getBaseAssetId(); const transactionInfo = assembleTransactionSummary({ id: gqlTransaction.id, @@ -99,17 +99,17 @@ export async function getTransactionSummaryFromRequest( const { receipts } = await provider.dryRun(transactionRequest); - const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = provider.getGasConfig(); - const maxInputs = provider.getChain().consensusParameters.txParameters.maxInputs; + const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = await provider.getGasConfig(); + const maxInputs = (await provider.getChain()).consensusParameters.txParameters.maxInputs; const transaction = transactionRequest.toTransaction(); const transactionBytes = transactionRequest.toTransactionBytes(); const gasPrice = await provider.getLatestGasPrice(); - const baseAssetId = provider.getBaseAssetId(); + const baseAssetId = await provider.getBaseAssetId(); const transactionSummary = assembleTransactionSummary({ - id: transactionRequest.getTransactionId(provider.getChainId()), + id: transactionRequest.getTransactionId(await provider.getChainId()), receipts, transaction, transactionBytes, @@ -168,10 +168,10 @@ export async function getTransactionsSummaries( txParameters: { maxInputs, maxGasPerTx }, gasCosts, }, - } = provider.getChain(); + } = await provider.getChain(); const gasPrice = await provider.getLatestGasPrice(); - const baseAssetId = provider.getBaseAssetId(); + const baseAssetId = await provider.getBaseAssetId(); const transactions = edges.map((edge) => { const { node: gqlTransaction } = edge; diff --git a/packages/account/src/providers/transaction-summary/input.ts b/packages/account/src/providers/transaction-summary/input.ts index 7fad93a2eb7..f9374cfc05e 100644 --- a/packages/account/src/providers/transaction-summary/input.ts +++ b/packages/account/src/providers/transaction-summary/input.ts @@ -47,12 +47,12 @@ function findCoinInput(inputs: Input[], assetId: string): InputCoin | undefined /** @hidden */ export function aggregateInputsAmountsByAssetAndOwner( inputs: Input[], - baseAssetID: string + baseAssetId: string ): Map> { const aggregated = new Map>(); getInputsCoinAndMessage(inputs).forEach((input) => { - const assetId = isInputCoin(input) ? input.assetId : baseAssetID; + const assetId = isInputCoin(input) ? input.assetId : baseAssetId; const owner = isInputCoin(input) ? input.owner : input.recipient; // Ensure that the map for the assetId exists diff --git a/packages/account/src/test-utils/launchNode.test.ts b/packages/account/src/test-utils/launchNode.test.ts index ab52fd47603..4fd8888c2b9 100644 --- a/packages/account/src/test-utils/launchNode.test.ts +++ b/packages/account/src/test-utils/launchNode.test.ts @@ -108,7 +108,8 @@ describe('launchNode', () => { const spawnSpy = vi.spyOn(childProcessMod, 'spawn'); process.env.FUEL_CORE_PATH = 'fuels-core'; const { cleanup, url } = await launchNode({ loggingEnabled: false }); - await Provider.create(url); + + await new Provider(url).init(); const command = spawnSpy.mock.calls[0][0]; expect(command).toEqual('fuels-core'); diff --git a/packages/account/src/test-utils/setup-test-provider-and-wallets.test.ts b/packages/account/src/test-utils/setup-test-provider-and-wallets.test.ts index 9ac08fe07d9..cf2fad98ab8 100644 --- a/packages/account/src/test-utils/setup-test-provider-and-wallets.test.ts +++ b/packages/account/src/test-utils/setup-test-provider-and-wallets.test.ts @@ -33,7 +33,7 @@ describe('setupTestProviderAndWallets', () => { await waitUntilUnreachable(url); const { error } = await safeExec(async () => { - const p = await Provider.create(url); + const p = new Provider(url); return p.getBlockNumber(); }); diff --git a/packages/account/src/test-utils/setup-test-provider-and-wallets.ts b/packages/account/src/test-utils/setup-test-provider-and-wallets.ts index 01c1c7cbc42..245b2351120 100644 --- a/packages/account/src/test-utils/setup-test-provider-and-wallets.ts +++ b/packages/account/src/test-utils/setup-test-provider-and-wallets.ts @@ -97,7 +97,8 @@ export async function setupTestProviderAndWallets({ let provider: Provider; try { - provider = await Provider.create(url, providerOptions); + provider = new Provider(url, providerOptions); + await provider.init(); } catch (err) { cleanup(); throw err; diff --git a/packages/account/src/utils/deployScriptOrPredicate.ts b/packages/account/src/utils/deployScriptOrPredicate.ts index 3ef7dad9c70..fea92dabee6 100644 --- a/packages/account/src/utils/deployScriptOrPredicate.ts +++ b/packages/account/src/utils/deployScriptOrPredicate.ts @@ -15,7 +15,7 @@ import { async function fundBlobTx(deployer: Account, blobTxRequest: BlobTransactionRequest) { // Check the account can afford to deploy all chunks and loader let totalCost = bn(0); - const chainInfo = deployer.provider.getChain(); + const chainInfo = await deployer.provider.getChain(); const gasPrice = await deployer.provider.estimateGasPrice(10); const priceFactor = chainInfo.consensusParameters.feeParameters.gasPriceFactor; diff --git a/packages/account/src/wallet/base-wallet-unlocked.ts b/packages/account/src/wallet/base-wallet-unlocked.ts index 01e82236be0..3eb66e13437 100644 --- a/packages/account/src/wallet/base-wallet-unlocked.ts +++ b/packages/account/src/wallet/base-wallet-unlocked.ts @@ -80,7 +80,7 @@ export class BaseWalletUnlocked extends Account { */ override async signTransaction(transactionRequestLike: TransactionRequestLike): Promise { const transactionRequest = transactionRequestify(transactionRequestLike); - const chainId = this.provider.getChainId(); + const chainId = await this.provider.getChainId(); const hashedTransaction = transactionRequest.getTransactionId(chainId); const signature = await this.signer().sign(hashedTransaction); return hexlify(signature); diff --git a/packages/account/src/wallet/wallet-unlocked.test.ts b/packages/account/src/wallet/wallet-unlocked.test.ts index b21576af0da..c6f4919a8ef 100644 --- a/packages/account/src/wallet/wallet-unlocked.test.ts +++ b/packages/account/src/wallet/wallet-unlocked.test.ts @@ -56,7 +56,7 @@ describe('WalletUnlocked', () => { const wallet = Wallet.fromPrivateKey(PRIVATE_KEY, provider); const signedTransaction = await wallet.signTransaction(SCRIPT_TX_REQUEST); - const chainId = wallet.provider.getChainId(); + const chainId = await wallet.provider.getChainId(); const verifiedAddress = Signer.recoverAddress( SCRIPT_TX_REQUEST.getTransactionId(chainId), signedTransaction diff --git a/packages/account/src/wallet/wallet.test.ts b/packages/account/src/wallet/wallet.test.ts index 0565b93b300..1b9e9dbdbf4 100644 --- a/packages/account/src/wallet/wallet.test.ts +++ b/packages/account/src/wallet/wallet.test.ts @@ -238,7 +238,7 @@ describe('Wallet', () => { wallets: [wallet], } = launched; - const newProviderInstance = await Provider.create(provider.url); + const newProviderInstance = new Provider(provider.url); wallet.connect(newProviderInstance); diff --git a/packages/account/test/fuel-wallet-connector.test.ts b/packages/account/test/fuel-wallet-connector.test.ts index 4ead4c44258..77e0d17d315 100644 --- a/packages/account/test/fuel-wallet-connector.test.ts +++ b/packages/account/test/fuel-wallet-connector.test.ts @@ -414,10 +414,15 @@ describe('Fuel Connector', () => { const wallet = await fuel.getWallet(account); expect(wallet.provider.url).toEqual(network.url); const receiver = Wallet.fromAddress(Address.fromRandom(), provider); - const response = await wallet.transfer(receiver.address, bn(1000), provider.getBaseAssetId(), { - tip: bn(1), - gasLimit: bn(100_000), - }); + const response = await wallet.transfer( + receiver.address, + bn(1000), + await provider.getBaseAssetId(), + { + tip: bn(1), + gasLimit: bn(100_000), + } + ); const { status } = await response.waitForResult(); expect(status).toEqual(TransactionStatus.success); expect((await receiver.getBalance()).toString()).toEqual('1000'); @@ -584,10 +589,8 @@ describe('Fuel Connector', () => { }).init(); class CustomProvider extends Provider { - static override async create(_url: string, opts?: ProviderOptions) { - const provider = new CustomProvider(nodeProvider.url, opts); - await provider.fetchChainAndNodeInfo(); - return provider; + constructor(_url: string, opts?: ProviderOptions) { + super(nodeProvider.url, opts); } // eslint-disable-next-line @typescript-eslint/require-await @@ -604,7 +607,7 @@ describe('Fuel Connector', () => { throw new Error('Account not found'); } - const provider = await CustomProvider.create(nodeProvider.url); + const provider = new CustomProvider(nodeProvider.url); const wallet = await fuel.getWallet(currentAccount, provider); expect(wallet.provider).toBeInstanceOf(CustomProvider); expect(await wallet.getBalance()).toEqual(bn(1234)); diff --git a/packages/contract/src/contract-factory.ts b/packages/contract/src/contract-factory.ts index 3427651eb40..5cdb063e6bd 100644 --- a/packages/contract/src/contract-factory.ts +++ b/packages/contract/src/contract-factory.ts @@ -202,7 +202,7 @@ export default class ContractFactory { deployOptions: DeployContractOptions = {} ): Promise> { const account = this.getAccount(); - const { consensusParameters } = account.provider.getChain(); + const { consensusParameters } = await account.provider.getChain(); const maxContractSize = consensusParameters.contractParameters.contractMaxSize.toNumber(); return this.bytecode.length > maxContractSize @@ -220,7 +220,7 @@ export default class ContractFactory { deployOptions: DeployContractOptions = {} ): Promise> { const account = this.getAccount(); - const { consensusParameters } = account.provider.getChain(); + const { consensusParameters } = await account.provider.getChain(); const maxContractSize = consensusParameters.contractParameters.contractMaxSize.toNumber(); if (this.bytecode.length > maxContractSize) { @@ -266,7 +266,7 @@ export default class ContractFactory { } // Generate the chunks based on the maximum chunk size and create blob txs - const chunkSize = this.getMaxChunkSize(deployOptions, chunkSizeMultiplier); + const chunkSize = await this.getMaxChunkSize(deployOptions, chunkSizeMultiplier); const chunks = getContractChunks(arrayify(this.bytecode), chunkSize).map((c) => { const transactionRequest = this.blobTransactionRequest({ ...deployOptions, @@ -294,7 +294,7 @@ export default class ContractFactory { // Check the account can afford to deploy all chunks and loader let totalCost = bn(0); - const chainInfo = account.provider.getChain(); + const chainInfo = await account.provider.getChain(); const gasPrice = await account.provider.estimateGasPrice(10); const priceFactor = chainInfo.consensusParameters.feeParameters.gasPriceFactor; @@ -365,7 +365,7 @@ export default class ContractFactory { } await this.fundTransactionRequest(createRequest, deployOptions); - txIdResolver(createRequest.getTransactionId(account.provider.getChainId())); + txIdResolver(createRequest.getTransactionId(await account.provider.getChainId())); const transactionResponse = await account.sendTransaction(createRequest); const transactionResult = await transactionResponse.waitForResult(); const contract = new Contract(contractId, this.interface, account) as T; @@ -463,7 +463,7 @@ export default class ContractFactory { /** * Get the maximum chunk size for deploying a contract by chunks. */ - private getMaxChunkSize( + private async getMaxChunkSize( deployOptions: DeployContractOptions, chunkSizeMultiplier: number = CHUNK_SIZE_MULTIPLIER ) { @@ -475,7 +475,7 @@ export default class ContractFactory { } const account = this.getAccount(); - const { consensusParameters } = account.provider.getChain(); + const { consensusParameters } = await account.provider.getChain(); const contractSizeLimit = consensusParameters.contractParameters.contractMaxSize.toNumber(); const transactionSizeLimit = consensusParameters.txParameters.maxSize.toNumber(); const maxLimit = 64000; @@ -489,7 +489,9 @@ export default class ContractFactory { ...deployOptions, bytecode: randomBytes(32), }).addResources( - account.generateFakeResources([{ assetId: account.provider.getBaseAssetId(), amount: bn(1) }]) + account.generateFakeResources([ + { assetId: await account.provider.getBaseAssetId(), amount: bn(1) }, + ]) ); // Given above, calculate the maximum chunk size const maxChunkSize = (sizeLimit - blobTx.byteLength() - WORD_SIZE) * chunkSizeMultiplier; diff --git a/packages/contract/src/test-utils/launch-test-node.test.ts b/packages/contract/src/test-utils/launch-test-node.test.ts index 36f7b46681c..f6667d7a0e7 100644 --- a/packages/contract/src/test-utils/launch-test-node.test.ts +++ b/packages/contract/src/test-utils/launch-test-node.test.ts @@ -76,7 +76,7 @@ describe('launchTestNode', () => { await waitUntilUnreachable(url); const { error } = await safeExec(async () => { - const p = await Provider.create(url); + const p = new Provider(url); await p.getBlockNumber(); }); @@ -269,7 +269,7 @@ describe('launchTestNode', () => { const { provider } = launched; - expect(provider.getNode().maxDepth.toNumber()).toEqual(20); + expect((await provider.getNode()).maxDepth.toNumber()).toEqual(20); process.env.DEFAULT_FUEL_CORE_ARGS = ''; }); diff --git a/packages/fuel-gauge/src/await-execution.test.ts b/packages/fuel-gauge/src/await-execution.test.ts index e0e27761218..d17f993cb72 100644 --- a/packages/fuel-gauge/src/await-execution.test.ts +++ b/packages/fuel-gauge/src/await-execution.test.ts @@ -23,7 +23,7 @@ describe('await-execution', () => { const transfer = await genesisWallet.createTransfer( destination.address, 100, - provider.getBaseAssetId(), + await provider.getBaseAssetId(), { gasLimit: 10_000, } diff --git a/packages/fuel-gauge/src/blob-deploy.test.ts b/packages/fuel-gauge/src/blob-deploy.test.ts index 9bbcd328d66..83ce551c2a3 100644 --- a/packages/fuel-gauge/src/blob-deploy.test.ts +++ b/packages/fuel-gauge/src/blob-deploy.test.ts @@ -241,9 +241,9 @@ describe('deploying blobs', () => { configurableConstants: configurable, }); - await wallet.transfer(predicate.address, 10_000, provider.getBaseAssetId()); + await wallet.transfer(predicate.address, 10_000, await provider.getBaseAssetId()); - const tx = await predicate.transfer(receiver.address, 1000, provider.getBaseAssetId()); + const tx = await predicate.transfer(receiver.address, 1000, await provider.getBaseAssetId()); const response = await tx.waitForResult(); expect(response.isStatusSuccess).toBe(true); }); diff --git a/packages/fuel-gauge/src/bytes.test.ts b/packages/fuel-gauge/src/bytes.test.ts index d544f7c89c3..34bb2dedd7a 100644 --- a/packages/fuel-gauge/src/bytes.test.ts +++ b/packages/fuel-gauge/src/bytes.test.ts @@ -97,7 +97,7 @@ describe('Bytes Tests', () => { const setupTx = await wallet.transfer( predicate.address, amountToPredicate, - launched.provider.getBaseAssetId(), + await launched.provider.getBaseAssetId(), { gasLimit: 10_000, } @@ -109,7 +109,7 @@ describe('Bytes Tests', () => { const tx = await predicate.transfer( receiver.address, amountToReceiver, - launched.provider.getBaseAssetId(), + await launched.provider.getBaseAssetId(), { gasLimit: 10_000, } diff --git a/packages/fuel-gauge/src/call-test-contract.test.ts b/packages/fuel-gauge/src/call-test-contract.test.ts index 7378835cc77..acb82f9815a 100644 --- a/packages/fuel-gauge/src/call-test-contract.test.ts +++ b/packages/fuel-gauge/src/call-test-contract.test.ts @@ -152,7 +152,7 @@ describe('CallTestContract', () => { it('Forward amount value on contract call', async () => { using contract = await setupContract(); - const baseAssetId = contract.provider.getBaseAssetId(); + const baseAssetId = await contract.provider.getBaseAssetId(); const { waitForResult } = await contract.functions .return_context_amount() .callParams({ diff --git a/packages/fuel-gauge/src/check-user-account.test.ts b/packages/fuel-gauge/src/check-user-account.test.ts index e007b2f8508..0bbf62fd394 100644 --- a/packages/fuel-gauge/src/check-user-account.test.ts +++ b/packages/fuel-gauge/src/check-user-account.test.ts @@ -59,7 +59,7 @@ describe('User account tests', () => { wallets: [wallet], } = launch; - const tx = await wallet.transfer(wallet.address, 100, provider.getBaseAssetId()); + const tx = await wallet.transfer(wallet.address, 100, await provider.getBaseAssetId()); await tx.wait(); diff --git a/packages/fuel-gauge/src/contract-factory.test.ts b/packages/fuel-gauge/src/contract-factory.test.ts index 8cb8300385c..bfd3f176507 100644 --- a/packages/fuel-gauge/src/contract-factory.test.ts +++ b/packages/fuel-gauge/src/contract-factory.test.ts @@ -398,7 +398,7 @@ describe('Contract Factory', () => { provider, } = launched; - const { consensusParameters } = provider.getChain(); + const { consensusParameters } = await provider.getChain(); const maxContractSize = consensusParameters.contractParameters.contractMaxSize.toNumber(); expect(ConfigurableContractFactory.bytecode.length).toBeLessThan(maxContractSize); @@ -422,7 +422,7 @@ describe('Contract Factory', () => { provider, } = launched; - const { consensusParameters } = provider.getChain(); + const { consensusParameters } = await provider.getChain(); const maxContractSize = consensusParameters.contractParameters.contractMaxSize.toNumber(); expect(LargeContractFactory.bytecode.length).toBeGreaterThan(maxContractSize); diff --git a/packages/fuel-gauge/src/contract.test.ts b/packages/fuel-gauge/src/contract.test.ts index 04fe5dffc7d..419a7ed00cd 100644 --- a/packages/fuel-gauge/src/contract.test.ts +++ b/packages/fuel-gauge/src/contract.test.ts @@ -65,7 +65,7 @@ describe('Contract', () => { expect(contract.provider).toEqual(provider); }); - it('should executes a contract call just nice', async () => { + it.only('should executes a contract call just nice', async () => { using contract = await setupTestContract(); const numberToSend = 1336; @@ -311,7 +311,7 @@ describe('Contract', () => { const { waitForResult } = await contract .multiCall([ contract.functions.return_context_amount().callParams({ - forward: [100, contract.provider.getBaseAssetId()], + forward: [100, await contract.provider.getBaseAssetId()], }), contract.functions.return_context_amount().callParams({ forward: [200, AltToken], @@ -337,7 +337,7 @@ describe('Contract', () => { contract .multiCall([ contract.functions.return_context_amount().callParams({ - forward: [100, contract.provider.getBaseAssetId()], + forward: [100, await contract.provider.getBaseAssetId()], gasLimit: 100, }), contract.functions.return_context_amount().callParams({ @@ -388,7 +388,7 @@ describe('Contract', () => { const invocationScope = contract.multiCall([ contract.functions.return_context_amount().callParams({ - forward: [100, contract.provider.getBaseAssetId()], + forward: [100, await contract.provider.getBaseAssetId()], }), contract.functions.return_context_amount().callParams({ forward: [200, AltToken], @@ -413,7 +413,7 @@ describe('Contract', () => { using contract = await setupTestContract(); const invocationScope = contract.functions.return_context_amount().callParams({ - forward: [100, contract.provider.getBaseAssetId()], + forward: [100, await contract.provider.getBaseAssetId()], }); const { gasUsed } = await invocationScope.getTransactionCost(); @@ -535,7 +535,7 @@ describe('Contract', () => { const { value } = await contract .multiCall([ contract.functions.return_context_amount().callParams({ - forward: [100, contract.provider.getBaseAssetId()], + forward: [100, await contract.provider.getBaseAssetId()], }), contract.functions.return_context_amount().callParams({ forward: [200, AltToken], @@ -651,7 +651,9 @@ describe('Contract', () => { contracts: [contract], } = launched; - const initialBalance = new BN(await contract.getBalance(provider.getBaseAssetId())).toNumber(); + const initialBalance = new BN( + await contract.getBalance(await provider.getBaseAssetId()) + ).toNumber(); const u64Amount = bn(10_000); const amountToContract = u64Amount; @@ -659,12 +661,14 @@ describe('Contract', () => { const tx = await wallet.transferToContract( contract.id, amountToContract, - provider.getBaseAssetId() + await provider.getBaseAssetId() ); await tx.waitForResult(); - const finalBalance = new BN(await contract.getBalance(provider.getBaseAssetId())).toNumber(); + const finalBalance = new BN( + await contract.getBalance(await provider.getBaseAssetId()) + ).toNumber(); expect(finalBalance).toBe(initialBalance + amountToContract.toNumber()); }); @@ -679,7 +683,9 @@ describe('Contract', () => { contracts: [contract], } = launched; - const initialBalance = new BN(await contract.getBalance(provider.getBaseAssetId())).toNumber(); + const initialBalance = new BN( + await contract.getBalance(await provider.getBaseAssetId()) + ).toNumber(); const amountToContract = bn(10_000); const assetId = TestAssetId.A.value; @@ -704,18 +710,22 @@ describe('Contract', () => { contracts: [contract], } = launched; - const initialBalance = new BN(await contract.getBalance(provider.getBaseAssetId())).toNumber(); + const initialBalance = new BN( + await contract.getBalance(await provider.getBaseAssetId()) + ).toNumber(); const amountToContract = bn(2).pow(62); // Very big number const tx = await wallet.transferToContract( contract.id, amountToContract, - provider.getBaseAssetId() + await provider.getBaseAssetId() ); await tx.waitForResult(); - const finalBalance = new BN(await contract.getBalance(provider.getBaseAssetId())).toString(); + const finalBalance = new BN( + await contract.getBalance(await provider.getBaseAssetId()) + ).toString(); expect(finalBalance).toBe(amountToContract.add(initialBalance).toString()); }); @@ -732,7 +742,7 @@ describe('Contract', () => { contracts: [contract], } = launched; - const baseAssetId = provider.getBaseAssetId(); + const baseAssetId = await provider.getBaseAssetId(); const contractTransferParams: ContractTransferParams[] = [ { contractId: contract.id, @@ -782,7 +792,7 @@ describe('Contract', () => { contracts: [storageContract, voidContract, smoContract], } = launched; - const baseAssetId = provider.getBaseAssetId(); + const baseAssetId = await provider.getBaseAssetId(); const assetA = TestAssetId.A.value; const assetB = TestAssetId.B.value; @@ -794,6 +804,7 @@ describe('Contract', () => { { contractId: storageId, amount: 999, + assetId: baseAssetId, }, { contractId: storageId, @@ -864,7 +875,7 @@ describe('Contract', () => { const tx = await wallet.transferToContract( contract.id, amountToContract, - provider.getBaseAssetId(), + await provider.getBaseAssetId(), { gasLimit, maxFee, @@ -895,7 +906,7 @@ describe('Contract', () => { const result = await wallet.transferToContract( contract.id.toB256(), amountToContract, - contract.provider.getBaseAssetId(), + await contract.provider.getBaseAssetId(), { gasLimit: 1, } @@ -939,7 +950,7 @@ describe('Contract', () => { } = launched; const initialBalance = new BN( - await contract.getBalance(contract.provider.getBaseAssetId()) + await contract.getBalance(await contract.provider.getBaseAssetId()) ).toNumber(); const amountToContract = 200; @@ -950,7 +961,7 @@ describe('Contract', () => { const tx1 = await wallet.transfer( predicate.address, amountToPredicate, - provider.getBaseAssetId() + await provider.getBaseAssetId() ); await tx1.waitForResult(); @@ -958,12 +969,14 @@ describe('Contract', () => { const tx2 = await predicate.transferToContract( contract.id, amountToContract, - provider.getBaseAssetId() + await provider.getBaseAssetId() ); await tx2.waitForResult(); - const finalBalance = new BN(await contract.getBalance(provider.getBaseAssetId())).toNumber(); + const finalBalance = new BN( + await contract.getBalance(await provider.getBaseAssetId()) + ).toNumber(); expect(finalBalance).toBe(initialBalance + amountToContract); }); @@ -993,7 +1006,7 @@ describe('Contract', () => { .addTransfer({ destination: receiver.address, amount: amountToTransfer, - assetId: provider.getBaseAssetId(), + assetId: await provider.getBaseAssetId(), }) .call(); @@ -1032,7 +1045,7 @@ describe('Contract', () => { { destination: receiver1.address, amount: amountToTransfer1, - assetId: provider.getBaseAssetId(), + assetId: await provider.getBaseAssetId(), }, { destination: receiver2.address, amount: amountToTransfer2, assetId: ASSET_A }, { destination: receiver3.address, amount: amountToTransfer3, assetId: ASSET_B }, @@ -1041,7 +1054,7 @@ describe('Contract', () => { const call = await contract.functions.sum(40, 50).addBatchTransfer(transferParams).call(); await call.waitForResult(); - const finalBalance1 = await receiver1.getBalance(provider.getBaseAssetId()); + const finalBalance1 = await receiver1.getBalance(await provider.getBaseAssetId()); const finalBalance2 = await receiver2.getBalance(ASSET_A); const finalBalance3 = await receiver3.getBalance(ASSET_B); @@ -1069,14 +1082,14 @@ describe('Contract', () => { await expectToThrowFuelError( async () => { - await wallet.transferToContract(contract.id, 0, provider.getBaseAssetId()); + await wallet.transferToContract(contract.id, 0, await provider.getBaseAssetId()); }, new FuelError(ErrorCode.INVALID_TRANSFER_AMOUNT, 'Transfer amount must be a positive number.') ); await expectToThrowFuelError( async () => { - await wallet.transferToContract(contract.id, -1, provider.getBaseAssetId()); + await wallet.transferToContract(contract.id, -1, await provider.getBaseAssetId()); }, new FuelError(ErrorCode.INVALID_TRANSFER_AMOUNT, 'Transfer amount must be a positive number.') ); @@ -1088,11 +1101,11 @@ describe('Contract', () => { contract.account = Wallet.generate({ provider: contract.provider }); await expectToThrowFuelError( - () => + async () => contract.functions .return_context_amount() .callParams({ - forward: [100, contract.provider.getBaseAssetId()], + forward: [100, await contract.provider.getBaseAssetId()], }) .simulate(), new FuelError( @@ -1110,7 +1123,7 @@ describe('Contract', () => { contract.functions .return_context_amount() .callParams({ - forward: [100, contract.provider.getBaseAssetId()], + forward: [100, await contract.provider.getBaseAssetId()], }) .simulate() ).rejects.toThrowError('Wallet is required!'); @@ -1125,7 +1138,7 @@ describe('Contract', () => { contract.functions .return_context_amount() .callParams({ - forward: [100, contract.provider.getBaseAssetId()], + forward: [100, await contract.provider.getBaseAssetId()], }) .simulate() ).rejects.toThrowError('An unlocked wallet is required to simulate a contract call.'); @@ -1140,7 +1153,7 @@ describe('Contract', () => { contract.functions .return_context_amount() .callParams({ - forward: [100, contract.provider.getBaseAssetId()], + forward: [100, await contract.provider.getBaseAssetId()], }) .dryRun() ).resolves.not.toThrow(); @@ -1306,7 +1319,7 @@ describe('Contract', () => { } = launched; const data = [1, 2, 3, 4, 5, 6, 7, 8]; - const baseAssetId = provider.getBaseAssetId(); + const baseAssetId = await provider.getBaseAssetId(); const { waitForResult } = await contract .multiCall([ diff --git a/packages/fuel-gauge/src/coverage-contract.test.ts b/packages/fuel-gauge/src/coverage-contract.test.ts index 0e8646708da..38f7dd5dddb 100644 --- a/packages/fuel-gauge/src/coverage-contract.test.ts +++ b/packages/fuel-gauge/src/coverage-contract.test.ts @@ -663,7 +663,7 @@ describe('Coverage Contract', { timeout: 15_000 }, () => { provider ); - request.addCoinOutput(recipient.address, 10, provider.getBaseAssetId()); + request.addCoinOutput(recipient.address, 10, await provider.getBaseAssetId()); const txCost = await sender.getTransactionCost(request); diff --git a/packages/fuel-gauge/src/doc-examples.test.ts b/packages/fuel-gauge/src/doc-examples.test.ts index 535e6378ae7..1e2c7d01855 100644 --- a/packages/fuel-gauge/src/doc-examples.test.ts +++ b/packages/fuel-gauge/src/doc-examples.test.ts @@ -145,7 +145,7 @@ describe('Doc Examples', () => { unlockedWallet = Wallet.fromPrivateKey(PRIVATE_KEY, provider); const newlyLockedWallet = unlockedWallet.lock(); - const balance: BigNumberish = await myWallet.getBalance(provider.getBaseAssetId()); + const balance: BigNumberish = await myWallet.getBalance(await provider.getBaseAssetId()); const { balances } = await myWallet.getBalances(); expect(newlyLockedWallet.address).toEqual(someWallet.address); @@ -191,7 +191,7 @@ describe('Doc Examples', () => { wallets: [fundingWallet], } = launched; - const baseAssetId = provider.getBaseAssetId(); + const baseAssetId = await provider.getBaseAssetId(); const walletA = Wallet.generate({ provider }); const walletB = Wallet.generate({ provider }); @@ -214,11 +214,13 @@ describe('Doc Examples', () => { const { balances: walletCBalances } = await walletC.getBalances(); // validate balances - expect(walletABalances).toEqual([{ assetId: provider.getBaseAssetId(), amount: bn(100) }]); + expect(walletABalances).toEqual([ + { assetId: await provider.getBaseAssetId(), amount: bn(100) }, + ]); expect(walletBBalances).toEqual([ { assetId: TestAssetId.A.value, amount: bn(100) }, { assetId: TestAssetId.B.value, amount: bn(100) }, - { assetId: provider.getBaseAssetId(), amount: bn(100) }, + { assetId: await provider.getBaseAssetId(), amount: bn(100) }, ]); expect(walletCBalances).toEqual([]); }); @@ -274,18 +276,23 @@ describe('Doc Examples', () => { const wallet2: WalletUnlocked = Wallet.fromPrivateKey(PRIVATE_KEY_2, provider); const wallet3: WalletUnlocked = Wallet.fromPrivateKey(PRIVATE_KEY_3, provider); + const assetId = await provider.getBaseAssetId(); + const submitted = await fundingWallet.batchTransfer([ { amount: 1_000_000, destination: wallet1.address, + assetId, }, { amount: 2_000_000, destination: wallet2.address, + assetId, }, { amount: 300_000, destination: wallet3.address, + assetId, }, ]); @@ -308,7 +315,7 @@ describe('Doc Examples', () => { const response = await wallet1.transfer( predicate.address, amountToPredicate, - provider.getBaseAssetId(), + await provider.getBaseAssetId(), { gasLimit: 10_000, } @@ -319,7 +326,7 @@ describe('Doc Examples', () => { const depositOnPredicate = await wallet1.transfer( predicate.address, 1000, - provider.getBaseAssetId(), + await provider.getBaseAssetId(), { gasLimit: 10_000, } @@ -330,7 +337,7 @@ describe('Doc Examples', () => { const tx = await predicate.transfer( receiver.address, amountToReceiver, - provider.getBaseAssetId(), + await provider.getBaseAssetId(), { gasLimit: 10_000, } diff --git a/packages/fuel-gauge/src/dry-run-multiple-txs.test.ts b/packages/fuel-gauge/src/dry-run-multiple-txs.test.ts index 729f6dbd1a1..4bb77c2986e 100644 --- a/packages/fuel-gauge/src/dry-run-multiple-txs.test.ts +++ b/packages/fuel-gauge/src/dry-run-multiple-txs.test.ts @@ -36,7 +36,9 @@ describe('dry-run-multiple-txs', () => { wallets: [wallet], } = launched; - const resources = await wallet.getResourcesToSpend([[500_000, provider.getBaseAssetId()]]); + const resources = await wallet.getResourcesToSpend([ + [500_000, await provider.getBaseAssetId()], + ]); const request1 = await revertContract.functions .validate_inputs(10, 0) @@ -144,7 +146,9 @@ describe('dry-run-multiple-txs', () => { // subId defined on multi-token contract const subId = '0x4a778acfad1abc155a009dc976d2cf0db6197d3d360194d74b1fb92b96986b00'; - const resources = await wallet.getResourcesToSpend([[500_000, provider.getBaseAssetId()]]); + const resources = await wallet.getResourcesToSpend([ + [500_000, await provider.getBaseAssetId()], + ]); // creating receives to be used by the request 2 and 3 const addresses: [AddressInput, AddressInput, AddressInput] = [ diff --git a/packages/fuel-gauge/src/e2e-script.test.ts b/packages/fuel-gauge/src/e2e-script.test.ts index 674fed133c8..aabbe7a76c9 100644 --- a/packages/fuel-gauge/src/e2e-script.test.ts +++ b/packages/fuel-gauge/src/e2e-script.test.ts @@ -56,15 +56,16 @@ describe.each(selectedNetworks)('Live Script Test', (selectedNetwork) => { let wallet: WalletUnlocked; let shouldSkip: boolean; - beforeAll(async () => { + beforeAll(() => { const { networkUrl, privateKey } = configuredNetworks[selectedNetwork]; + if (!privateKey) { console.log(`Skipping live Fuel Node test - ${networkUrl}`); shouldSkip = true; return; } - provider = await Provider.create(networkUrl); + provider = new Provider(networkUrl); wallet = new WalletUnlocked(privateKey, provider); }); @@ -126,7 +127,7 @@ describe.each(selectedNetworks)('Live Script Test', (selectedNetwork) => { return; } - const balance = await provider.getBalance(wallet.address, provider.getBaseAssetId()); + const balance = await provider.getBalance(wallet.address, await provider.getBaseAssetId()); expect(bn(balance).gt(0)); }); diff --git a/packages/fuel-gauge/src/edge-cases.test.ts b/packages/fuel-gauge/src/edge-cases.test.ts index 580b6df9dbd..e71299e996b 100644 --- a/packages/fuel-gauge/src/edge-cases.test.ts +++ b/packages/fuel-gauge/src/edge-cases.test.ts @@ -30,7 +30,7 @@ describe('Edge Cases', () => { wallets: [adminWallet], } = launched; - const baseAssetId = provider.getBaseAssetId(); + const baseAssetId = await provider.getBaseAssetId(); const destination = Wallet.generate({ provider, @@ -43,7 +43,8 @@ describe('Edge Cases', () => { { gasLimit: 10_000 } ); - const response = new TransactionResponse(transactionId, provider); + const chainId = await provider.getChainId(); + const response = new TransactionResponse(transactionId, provider, chainId); await response.waitForResult(); diff --git a/packages/fuel-gauge/src/fee.test.ts b/packages/fuel-gauge/src/fee.test.ts index f5c5a53440e..8fe26bd7523 100644 --- a/packages/fuel-gauge/src/fee.test.ts +++ b/packages/fuel-gauge/src/fee.test.ts @@ -105,7 +105,7 @@ describe('Fee', () => { const tx = await wallet.transfer( destination.address, amountToTransfer, - provider.getBaseAssetId(), + await provider.getBaseAssetId(), { gasLimit: 10_000, } @@ -141,7 +141,7 @@ describe('Fee', () => { gasLimit: 10000, }); - request.addCoinOutput(destination1.address, amountToTransfer, provider.getBaseAssetId()); + request.addCoinOutput(destination1.address, amountToTransfer, await provider.getBaseAssetId()); request.addCoinOutput(destination2.address, amountToTransfer, ASSET_A); request.addCoinOutput(destination3.address, amountToTransfer, ASSET_B); @@ -326,12 +326,20 @@ describe('Fee', () => { const predicate = new PredicateU32({ provider, data: [1078] }); - const tx1 = await wallet.transfer(predicate.address, 1_000_000, provider.getBaseAssetId()); + const tx1 = await wallet.transfer( + predicate.address, + 1_000_000, + await provider.getBaseAssetId() + ); await tx1.wait(); const transferAmount = 100; const balanceBefore = await predicate.getBalance(); - const tx2 = await predicate.transfer(wallet.address, transferAmount, provider.getBaseAssetId()); + const tx2 = await predicate.transfer( + wallet.address, + transferAmount, + await provider.getBaseAssetId() + ); const { fee } = await tx2.wait(); @@ -377,7 +385,7 @@ describe('Fee', () => { wallets: [fundedWallet], } = launched; - const baseAssetId = provider.getBaseAssetId(); + const baseAssetId = await provider.getBaseAssetId(); const { messages: [message1, message2], @@ -418,7 +426,7 @@ describe('Fee', () => { wallets: [fundedWallet], } = launched; - const baseAssetId = provider.getBaseAssetId(); + const baseAssetId = await provider.getBaseAssetId(); const { messages: [message1, message2], @@ -501,7 +509,7 @@ describe('Fee', () => { const tx = await wallet.transfer( wallet.address, amountPerCoin * 20, - provider.getBaseAssetId() + await provider.getBaseAssetId() ); const { isStatusSuccess } = await tx.waitForResult(); diff --git a/packages/fuel-gauge/src/funding-transaction.test.ts b/packages/fuel-gauge/src/funding-transaction.test.ts index 3891decd239..19a520ef3e5 100644 --- a/packages/fuel-gauge/src/funding-transaction.test.ts +++ b/packages/fuel-gauge/src/funding-transaction.test.ts @@ -63,7 +63,7 @@ describe('Funding Transactions', () => { account: sender, totalAmount: 400_000, splitIn: 5, - baseAssetId: provider.getBaseAssetId(), + baseAssetId: await provider.getBaseAssetId(), mainWallet: sender, }); @@ -73,7 +73,7 @@ describe('Funding Transactions', () => { const amountToTransfer = 300; - request.addCoinOutput(receiver.address, amountToTransfer, provider.getBaseAssetId()); + request.addCoinOutput(receiver.address, amountToTransfer, await provider.getBaseAssetId()); const txCost = await sender.getTransactionCost(request); @@ -91,7 +91,7 @@ describe('Funding Transactions', () => { // fund method should have been called to fetch the remaining UTXOs expect(getResourcesToSpendSpy).toHaveBeenCalled(); - const receiverBalance = await receiver.getBalance(provider.getBaseAssetId()); + const receiverBalance = await receiver.getBalance(await provider.getBaseAssetId()); expect(receiverBalance.toNumber()).toBe(amountToTransfer + initialAmount); }); @@ -112,12 +112,14 @@ describe('Funding Transactions', () => { account: sender, totalAmount: 400_000, splitIn: 2, - baseAssetId: provider.getBaseAssetId(), + baseAssetId: await provider.getBaseAssetId(), mainWallet, }); // sender has 2 UTXOs for 200_000 each, so it has enough resources to spend 1000 of baseAssetId - const enoughtResources = await sender.getResourcesToSpend([[100, provider.getBaseAssetId()]]); + const enoughtResources = await sender.getResourcesToSpend([ + [100, await provider.getBaseAssetId()], + ]); // confirm we only fetched 1 UTXO from the expected amount expect(enoughtResources.length).toBe(1); @@ -129,7 +131,7 @@ describe('Funding Transactions', () => { const amountToTransfer = 100; - request.addCoinOutput(receiver.address, amountToTransfer, provider.getBaseAssetId()); + request.addCoinOutput(receiver.address, amountToTransfer, await provider.getBaseAssetId()); request.addResources(enoughtResources); const txCost = await sender.getTransactionCost(request); @@ -153,7 +155,7 @@ describe('Funding Transactions', () => { // fund should not have been called since the TX request was already funded expect(getResourcesToSpendSpy).toHaveBeenCalledTimes(0); - const receiverBalance = await receiver.getBalance(provider.getBaseAssetId()); + const receiverBalance = await receiver.getBalance(await provider.getBaseAssetId()); expect(receiverBalance.toNumber()).toBe(amountToTransfer); }); @@ -175,7 +177,7 @@ describe('Funding Transactions', () => { account: sender, totalAmount: 200_000, splitIn: 1, - baseAssetId: provider.getBaseAssetId(), + baseAssetId: await provider.getBaseAssetId(), mainWallet: sender, }); @@ -184,7 +186,7 @@ describe('Funding Transactions', () => { }); const amountToTransfer = 1000; - request.addCoinOutput(receiver.address, amountToTransfer, provider.getBaseAssetId()); + request.addCoinOutput(receiver.address, amountToTransfer, await provider.getBaseAssetId()); const txCost = await sender.getTransactionCost(request); @@ -205,7 +207,7 @@ describe('Funding Transactions', () => { // fund method should have been called to fetch UTXOs expect(getResourcesToSpendSpy).toHaveBeenCalledTimes(1); - const receiverBalance = await receiver.getBalance(provider.getBaseAssetId()); + const receiverBalance = await receiver.getBalance(await provider.getBaseAssetId()); expect(receiverBalance.toNumber()).toBe(amountToTransfer + initialAmount); }); @@ -235,14 +237,14 @@ describe('Funding Transactions', () => { account: sender, totalAmount: 1524, splitIn, - baseAssetId: provider.getBaseAssetId(), + baseAssetId: await provider.getBaseAssetId(), mainWallet: funded, }); const request = new ScriptTransactionRequest(); const amountToTransfer = 1522; - request.addCoinOutput(receiver.address, amountToTransfer, provider.getBaseAssetId()); + request.addCoinOutput(receiver.address, amountToTransfer, await provider.getBaseAssetId()); const txCost = await sender.getTransactionCost(request); @@ -287,6 +289,8 @@ describe('Funding Transactions', () => { wallets: [wallet], } = launched; + const baseAssetId = await provider.getBaseAssetId(); + const receiver = Wallet.generate({ provider }); const wallet1 = Wallet.generate({ provider }); const wallet2 = Wallet.generate({ provider }); @@ -303,7 +307,7 @@ describe('Funding Transactions', () => { const submitted1 = await wallet.transfer( wallet1.address, totalInBaseAsset, - provider.getBaseAssetId() + await provider.getBaseAssetId() ); await submitted1.waitForResult(); @@ -335,12 +339,10 @@ describe('Funding Transactions', () => { // Manually fetching resources from wallet1 to be added to transactionRequest const partiallyResources = await wallet1.getResourcesToSpend([ [partiallyInAssetA, assetA], - [totalInBaseAsset, provider.getBaseAssetId()], + [totalInBaseAsset, baseAssetId], ]); - const baseAssetResource = partiallyResources.find( - (r) => r.assetId === provider.getBaseAssetId() - ); + const baseAssetResource = partiallyResources.find((r) => r.assetId === baseAssetId); const assetAResource = partiallyResources.find((r) => r.assetId === assetA); // Expect to have the correct amount of resources, not enough to cover the required amount in Asset A @@ -384,7 +386,7 @@ describe('Funding Transactions', () => { * Adding CoinOutputs for the receiver address. All required amounts can be * covered by the fundedWallet. */ - transactionRequest.addCoinOutput(receiver.address, 1500, provider.getBaseAssetId()); + transactionRequest.addCoinOutput(receiver.address, 1500, await provider.getBaseAssetId()); transactionRequest.addCoinOutput(receiver.address, 3000, assetA); transactionRequest.addCoinOutput(receiver.address, 4500, assetB); @@ -445,14 +447,14 @@ describe('Funding Transactions', () => { const submission1 = await fundedWallet.transfer( receiver.address, transferAmount, - provider.getBaseAssetId() + await provider.getBaseAssetId() ); // Submitting TX 2 before TX 1 finished to process. const submission2 = await fundedWallet.transfer( receiver.address, transferAmount, - provider.getBaseAssetId() + await provider.getBaseAssetId() ); const result1 = await submission1.waitForResult(); @@ -492,20 +494,24 @@ describe('Funding Transactions', () => { const transferAmount = 100_000; // Submitting TX 1 - await fundedWallet.transfer(receiver.address, transferAmount, provider.getBaseAssetId()); + await fundedWallet.transfer(receiver.address, transferAmount, await provider.getBaseAssetId()); // ensure cache is cleared await sleep(100); // Submitting TX 2 before TX 1 finished to process. - await expect(() => - fundedWallet.transfer(receiver.address, transferAmount, provider.getBaseAssetId()) + await expect(async () => + fundedWallet.transfer(receiver.address, transferAmount, await provider.getBaseAssetId()) ).rejects.toThrowError( /Transaction input validation failed: Transaction id already exists \(id: .*\)/ ); const { error: e } = await safeExec(async () => { - await fundedWallet.transfer(receiver.address, transferAmount, provider.getBaseAssetId()); + await fundedWallet.transfer( + receiver.address, + transferAmount, + await provider.getBaseAssetId() + ); }); const error = e; diff --git a/packages/fuel-gauge/src/mapped-error-messages.test.ts b/packages/fuel-gauge/src/mapped-error-messages.test.ts index d2a1404a8e7..10590ccf4a8 100644 --- a/packages/fuel-gauge/src/mapped-error-messages.test.ts +++ b/packages/fuel-gauge/src/mapped-error-messages.test.ts @@ -35,7 +35,7 @@ describe('mapped error messages', () => { } = launched; const request = new ScriptTransactionRequest(); - request.addCoinOutput(wallet.address, 256, wallet.provider.getBaseAssetId()); + request.addCoinOutput(wallet.address, 256, await wallet.provider.getBaseAssetId()); const txCost = await wallet.getTransactionCost(request); request.gasLimit = txCost.gasUsed; diff --git a/packages/fuel-gauge/src/min-gas.test.ts b/packages/fuel-gauge/src/min-gas.test.ts index 7eb0cfa99a7..788244ada8d 100644 --- a/packages/fuel-gauge/src/min-gas.test.ts +++ b/packages/fuel-gauge/src/min-gas.test.ts @@ -48,7 +48,7 @@ describe('Minimum gas tests', () => { const resources = await provider.getResourcesToSpend(wallet.address, [ { amount: bn(100_000), - assetId: provider.getBaseAssetId(), + assetId: await provider.getBaseAssetId(), }, ]); request.addResources(resources); @@ -85,7 +85,7 @@ describe('Minimum gas tests', () => { script: ComplexScript.bytecode, scriptData: hexlify(new BigNumberCoder('u64').encode(bn(2000))), }); - request.addCoinOutput(Address.fromRandom(), bn(100), provider.getBaseAssetId()); + request.addCoinOutput(Address.fromRandom(), bn(100), await provider.getBaseAssetId()); /** * Get the transaction cost to set a strict gasLimit and min gasPrice @@ -127,14 +127,14 @@ describe('Minimum gas tests', () => { /** * Fund the predicate */ - const tx = await wallet.transfer(predicate.address, 1_000_000, provider.getBaseAssetId()); + const tx = await wallet.transfer(predicate.address, 1_000_000, await provider.getBaseAssetId()); await tx.wait(); /** * Create a script transaction transfer */ const request = new ScriptTransactionRequest(); - request.addCoinOutput(Address.fromRandom(), bn(100), provider.getBaseAssetId()); + request.addCoinOutput(Address.fromRandom(), bn(100), await provider.getBaseAssetId()); /** * Get the transaction cost to set a strict gasLimit and min gasPrice @@ -166,7 +166,7 @@ describe('Minimum gas tests', () => { wallets: [wallet], } = launched; - const baseAssetId = provider.getBaseAssetId(); + const baseAssetId = await provider.getBaseAssetId(); /** * Setup predicate diff --git a/packages/fuel-gauge/src/payable-annotation.test.ts b/packages/fuel-gauge/src/payable-annotation.test.ts index 7974c092efc..3bc9eb3df3c 100644 --- a/packages/fuel-gauge/src/payable-annotation.test.ts +++ b/packages/fuel-gauge/src/payable-annotation.test.ts @@ -16,7 +16,7 @@ function launchPayableContract() { */ test('allow sending coins to payable functions', async () => { using contract = await launchPayableContract(); - const baseAssetId = contract.provider.getBaseAssetId(); + const baseAssetId = await contract.provider.getBaseAssetId(); // This should not fail because the function is payable await expect( @@ -34,7 +34,7 @@ test('allow sending coins to payable functions', async () => { test("don't allow sending coins to non-payable functions", async () => { using contract = await launchPayableContract(); - const baseAssetId = contract.provider.getBaseAssetId(); + const baseAssetId = await contract.provider.getBaseAssetId(); // This should fail because the function is not payable await expect(async () => { diff --git a/packages/fuel-gauge/src/policies.test.ts b/packages/fuel-gauge/src/policies.test.ts index dd0db917c30..af6d875ccc7 100644 --- a/packages/fuel-gauge/src/policies.test.ts +++ b/packages/fuel-gauge/src/policies.test.ts @@ -125,7 +125,7 @@ describe('Policies', () => { const txRequest = new ScriptTransactionRequest(txParams); - txRequest.addCoinOutput(receiver.address, 500, provider.getBaseAssetId()); + txRequest.addCoinOutput(receiver.address, 500, await provider.getBaseAssetId()); const txCost = await wallet.getTransactionCost(txRequest); @@ -272,7 +272,7 @@ describe('Policies', () => { const pendingTx = await wallet.transfer( receiver.address, 500, - provider.getBaseAssetId(), + await provider.getBaseAssetId(), txParams ); @@ -309,7 +309,7 @@ describe('Policies', () => { const pendingTx = await wallet.transferToContract( contract.id, 500, - provider.getBaseAssetId(), + await provider.getBaseAssetId(), txParams ); @@ -339,7 +339,7 @@ describe('Policies', () => { const pendingTx = await wallet.transfer( receiver.address, 500, - provider.getBaseAssetId(), + await provider.getBaseAssetId(), txParams ); @@ -373,7 +373,7 @@ describe('Policies', () => { const pendingTx = await wallet.transfer( receiver.address, 500, - provider.getBaseAssetId(), + await provider.getBaseAssetId(), txParams ); await pendingTx.waitForResult(); @@ -406,7 +406,7 @@ describe('Policies', () => { const pendingTx = await wallet.transferToContract( contract.id, 500, - provider.getBaseAssetId(), + await provider.getBaseAssetId(), txParams ); await pendingTx.waitForResult(); diff --git a/packages/fuel-gauge/src/predicate-conditional-inputs.test.ts b/packages/fuel-gauge/src/predicate-conditional-inputs.test.ts index c4a8b535128..5e514ebd30c 100644 --- a/packages/fuel-gauge/src/predicate-conditional-inputs.test.ts +++ b/packages/fuel-gauge/src/predicate-conditional-inputs.test.ts @@ -35,7 +35,11 @@ describe('PredicateConditionalInputs', () => { await tx1.waitForResult(); // transfer base asset to Alice so she can pay the fees - const tx2 = await adminWallet.transfer(aliceWallet.address, 200_000, provider.getBaseAssetId()); + const tx2 = await adminWallet.transfer( + aliceWallet.address, + 200_000, + await provider.getBaseAssetId() + ); await tx2.waitForResult(); @@ -43,7 +47,9 @@ describe('PredicateConditionalInputs', () => { // fetch predicate resources to spend const predicateResoruces = await predicate.getResourcesToSpend([[amountToTransfer, ASSET_A]]); - const aliceResources = await aliceWallet.getResourcesToSpend([[1, provider.getBaseAssetId()]]); + const aliceResources = await aliceWallet.getResourcesToSpend([ + [1, await provider.getBaseAssetId()], + ]); request .addResources(aliceResources) @@ -110,7 +116,11 @@ describe('PredicateConditionalInputs', () => { await tx1.waitForResult(); // transfer base asset to predicate so it can pay the fees - const tx2 = await adminWallet.transfer(predicate.address, 200_000, provider.getBaseAssetId()); + const tx2 = await adminWallet.transfer( + predicate.address, + 200_000, + await provider.getBaseAssetId() + ); await tx2.waitForResult(); diff --git a/packages/fuel-gauge/src/predicate/predicate-arguments.test.ts b/packages/fuel-gauge/src/predicate/predicate-arguments.test.ts index d9c6d2f8ee9..3127258fd70 100644 --- a/packages/fuel-gauge/src/predicate/predicate-arguments.test.ts +++ b/packages/fuel-gauge/src/predicate/predicate-arguments.test.ts @@ -42,7 +42,7 @@ describe('Predicate', () => { const tx = await predicate.transfer( receiver.address, amountToReceiver, - provider.getBaseAssetId(), + await provider.getBaseAssetId(), { gasLimit: 1000, } @@ -72,7 +72,9 @@ describe('Predicate', () => { const receiver = Wallet.generate({ provider }); await expect( - predicate.transfer(receiver.address, 50, provider.getBaseAssetId(), { gasLimit: 1000 }) + predicate.transfer(receiver.address, 50, await provider.getBaseAssetId(), { + gasLimit: 1000, + }) ).rejects.toThrow(/Invalid b256/); }); @@ -96,7 +98,7 @@ describe('Predicate', () => { const tx = await predicate.transfer( receiver.address, amountToReceiver, - provider.getBaseAssetId(), + await provider.getBaseAssetId(), { gasLimit: 1000, } @@ -126,7 +128,7 @@ describe('Predicate', () => { expect(initialReceiverBalance.toHex()).toEqual(toHex(0)); await expect( - predicate.transfer(receiver.address, amountToPredicate, provider.getBaseAssetId(), { + predicate.transfer(receiver.address, amountToPredicate, await provider.getBaseAssetId(), { gasLimit: 1000, }) ).rejects.toThrow(/PredicateVerificationFailed/); @@ -152,7 +154,7 @@ describe('Predicate', () => { const fundTx = await fundingWallet.transfer( predicateInstanceForBalance.address, 100_000_000, - provider.getBaseAssetId() + await provider.getBaseAssetId() ); await fundTx.waitForResult(); @@ -164,7 +166,7 @@ describe('Predicate', () => { const tx = await predicate.transfer( receiver.address, amountToReceiver, - provider.getBaseAssetId(), + await provider.getBaseAssetId(), { gasLimit: 1000, } @@ -194,7 +196,9 @@ describe('Predicate', () => { await fundPredicate(fundingWallet, predicate, amountToPredicate); await expect( - predicate.transfer(receiver.address, 50, provider.getBaseAssetId(), { gasLimit: 1000 }) + predicate.transfer(receiver.address, 50, await provider.getBaseAssetId(), { + gasLimit: 1000, + }) ).rejects.toThrow(/PredicateVerificationFailed/); }); @@ -217,7 +221,7 @@ describe('Predicate', () => { const tx = await predicate.transfer( receiver.address, amountToReceiver, - provider.getBaseAssetId(), + await provider.getBaseAssetId(), { gasLimit: 1000, } @@ -247,7 +251,7 @@ describe('Predicate', () => { const tx = await predicate.transfer( receiver.address, amountToReceiver, - provider.getBaseAssetId(), + await provider.getBaseAssetId(), { gasLimit: 1000, } @@ -277,7 +281,7 @@ describe('Predicate', () => { const tx = await predicate.transfer( receiver.address, amountToReceiver, - provider.getBaseAssetId(), + await provider.getBaseAssetId(), { gasLimit: 1000, } @@ -304,7 +308,9 @@ describe('Predicate', () => { const receiver = Wallet.generate({ provider }); await expect( - predicate.transfer(receiver.address, 50, provider.getBaseAssetId(), { gasLimit: 1000 }) + predicate.transfer(receiver.address, 50, await provider.getBaseAssetId(), { + gasLimit: 1000, + }) ).rejects.toThrow(/PredicateVerificationFailed/); }); }); diff --git a/packages/fuel-gauge/src/predicate/predicate-configurables.test.ts b/packages/fuel-gauge/src/predicate/predicate-configurables.test.ts index 582f757e1a2..6b46e7a4bd8 100644 --- a/packages/fuel-gauge/src/predicate/predicate-configurables.test.ts +++ b/packages/fuel-gauge/src/predicate/predicate-configurables.test.ts @@ -40,12 +40,12 @@ describe('Predicate', () => { provider: wallet.provider, }); - await assertBalance(destination, 0, provider.getBaseAssetId()); + await assertBalance(destination, 0, await provider.getBaseAssetId()); const tx = await predicate.transfer( destination.address, amountToTransfer, - provider.getBaseAssetId(), + await provider.getBaseAssetId(), { gasLimit: 1000, } @@ -53,7 +53,7 @@ describe('Predicate', () => { await tx.waitForResult(); - await assertBalance(destination, amountToTransfer, provider.getBaseAssetId()); + await assertBalance(destination, amountToTransfer, await provider.getBaseAssetId()); }); it('calls a predicate with configurables where first param is equal', async () => { @@ -79,7 +79,7 @@ describe('Predicate', () => { provider: wallet.provider, }); - await assertBalance(destination, 0, provider.getBaseAssetId()); + await assertBalance(destination, 0, await provider.getBaseAssetId()); // transfer funds to predicate await fundPredicate(wallet, predicate, amountToPredicate); @@ -88,7 +88,7 @@ describe('Predicate', () => { const tx = await predicate.transfer( destination.address, amountToTransfer, - provider.getBaseAssetId(), + await provider.getBaseAssetId(), { gasLimit: 1000, } @@ -96,7 +96,7 @@ describe('Predicate', () => { await tx.waitForResult(); - await assertBalance(destination, amountToTransfer, provider.getBaseAssetId()); + await assertBalance(destination, amountToTransfer, await provider.getBaseAssetId()); }); it('calls a predicate with configurables where second param is equal', async () => { @@ -122,7 +122,7 @@ describe('Predicate', () => { provider: wallet.provider, }); - await assertBalance(destination, 0, provider.getBaseAssetId()); + await assertBalance(destination, 0, await provider.getBaseAssetId()); // transfer funds to predicate await fundPredicate(wallet, predicate, amountToPredicate); @@ -131,7 +131,7 @@ describe('Predicate', () => { const tx = await predicate.transfer( destination.address, amountToTransfer, - provider.getBaseAssetId(), + await provider.getBaseAssetId(), { gasLimit: 1000, } @@ -139,7 +139,7 @@ describe('Predicate', () => { await tx.waitForResult(); - await assertBalance(destination, amountToTransfer, provider.getBaseAssetId()); + await assertBalance(destination, amountToTransfer, await provider.getBaseAssetId()); }); it('calls a predicate with configurables where both params are equal', async () => { @@ -169,14 +169,14 @@ describe('Predicate', () => { provider: wallet.provider, }); - await assertBalance(destination, 0, provider.getBaseAssetId()); + await assertBalance(destination, 0, await provider.getBaseAssetId()); await fundPredicate(wallet, predicate, amountToPredicate); const tx = await predicate.transfer( destination.address, amountToTransfer, - provider.getBaseAssetId(), + await provider.getBaseAssetId(), { gasLimit: 1000, } @@ -184,7 +184,7 @@ describe('Predicate', () => { await tx.waitForResult(); - await assertBalance(destination, amountToTransfer, provider.getBaseAssetId()); + await assertBalance(destination, amountToTransfer, await provider.getBaseAssetId()); }); it('calls a predicate with partial configurables being set', async () => { @@ -211,14 +211,14 @@ describe('Predicate', () => { provider: wallet.provider, }); - await assertBalance(destination, 0, provider.getBaseAssetId()); + await assertBalance(destination, 0, await provider.getBaseAssetId()); await fundPredicate(wallet, predicate, amountToPredicate); const tx = await predicate.transfer( destination.address, amountToTransfer, - provider.getBaseAssetId(), + await provider.getBaseAssetId(), { gasLimit: 1000, } @@ -226,7 +226,7 @@ describe('Predicate', () => { await tx.waitForResult(); - await assertBalance(destination, amountToTransfer, provider.getBaseAssetId()); + await assertBalance(destination, amountToTransfer, await provider.getBaseAssetId()); }); it('throws when configurable data is not set', async () => { @@ -248,7 +248,9 @@ describe('Predicate', () => { await fundPredicate(wallet, predicate, amountToPredicate); await expect( - predicate.transfer(destination.address, 300, provider.getBaseAssetId(), { gasLimit: 1000 }) + predicate.transfer(destination.address, 300, await provider.getBaseAssetId(), { + gasLimit: 1000, + }) ).rejects.toThrow(/PredicateVerificationFailed/); }); diff --git a/packages/fuel-gauge/src/predicate/predicate-estimations.test.ts b/packages/fuel-gauge/src/predicate/predicate-estimations.test.ts index f37a0d06943..8653af9cda4 100644 --- a/packages/fuel-gauge/src/predicate/predicate-estimations.test.ts +++ b/packages/fuel-gauge/src/predicate/predicate-estimations.test.ts @@ -55,7 +55,7 @@ describe('Predicate', () => { // Get resources from the predicate struct const ressources = await predicateStruct.getResourcesToSpend([ { - assetId: provider.getBaseAssetId(), + assetId: await provider.getBaseAssetId(), amount: bn(10_000), }, ]); @@ -140,7 +140,9 @@ describe('Predicate', () => { await fundPredicate(wallet, predicateTrue, fundingAmount); - const resources = await predicateTrue.getResourcesToSpend([[1, provider.getBaseAssetId()]]); + const resources = await predicateTrue.getResourcesToSpend([ + [1, await provider.getBaseAssetId()], + ]); tx.addResources(resources); const spy = vi.spyOn(provider.operations, 'estimatePredicates'); @@ -172,7 +174,7 @@ describe('Predicate', () => { const tx = new ScriptTransactionRequest(); const trueResources = await predicateTrue.getResourcesToSpend([ - [1, provider.getBaseAssetId()], + [1, await provider.getBaseAssetId()], ]); tx.addResources(trueResources); @@ -181,7 +183,7 @@ describe('Predicate', () => { await provider.estimatePredicates(tx); const structResources = await predicateStruct.getResourcesToSpend([ - [1, provider.getBaseAssetId()], + [1, await provider.getBaseAssetId()], ]); tx.addResources(structResources); @@ -224,7 +226,7 @@ describe('Predicate', () => { const response = await predicateValidateTransfer.transfer( receiverWallet.address.toB256(), 1, - provider.getBaseAssetId() + await provider.getBaseAssetId() ); const { isStatusSuccess } = await response.waitForResult(); @@ -257,7 +259,7 @@ describe('Predicate', () => { const transactionRequest = new ScriptTransactionRequest(); const resources = await predicateStruct.getResourcesToSpend([ - [fundingAmount, provider.getBaseAssetId()], + [fundingAmount, await provider.getBaseAssetId()], ]); resources.forEach((resource) => { expect(resource.predicateData).toBeDefined(); @@ -291,7 +293,7 @@ describe('Predicate', () => { const transactionRequest = new ScriptTransactionRequest(); const resources = await provider.getResourcesToSpend(predicateStruct.address, [ - [fundingAmount, provider.getBaseAssetId()], + [fundingAmount, await provider.getBaseAssetId()], ]); resources.forEach((resource) => { diff --git a/packages/fuel-gauge/src/predicate/predicate-evaluations.test.ts b/packages/fuel-gauge/src/predicate/predicate-evaluations.test.ts index eab569adbc2..e8c78b4d8ca 100644 --- a/packages/fuel-gauge/src/predicate/predicate-evaluations.test.ts +++ b/packages/fuel-gauge/src/predicate/predicate-evaluations.test.ts @@ -31,7 +31,7 @@ describe('Predicate', () => { const tx = await predicate.transfer( receiver.address, amountToReceiver, - provider.getBaseAssetId(), + await provider.getBaseAssetId(), { gasLimit: 1000, } @@ -58,7 +58,7 @@ describe('Predicate', () => { await fundPredicate(wallet, predicate, 200_000); await expect( - predicate.transfer(receiver.address, 50, provider.getBaseAssetId(), { + predicate.transfer(receiver.address, 50, await provider.getBaseAssetId(), { gasLimit: 1000, }) ).rejects.toThrow('PredicateVerificationFailed'); diff --git a/packages/fuel-gauge/src/predicate/predicate-general.test.ts b/packages/fuel-gauge/src/predicate/predicate-general.test.ts index ae764d1a28b..2052d796222 100644 --- a/packages/fuel-gauge/src/predicate/predicate-general.test.ts +++ b/packages/fuel-gauge/src/predicate/predicate-general.test.ts @@ -20,7 +20,7 @@ describe('Predicate', () => { const amountToTransferBaseAsset = bn(1000); const fakeCoinsConfig: FakeResources[] = [ - { amount: amount1, assetId: provider.getBaseAssetId() }, + { amount: amount1, assetId: await provider.getBaseAssetId() }, { amount: amount2, assetId: ASSET_A }, { amount: amount3, assetId: ASSET_B }, ]; @@ -51,7 +51,7 @@ describe('Predicate', () => { request.addCoinOutput( Address.fromRandom(), amountToTransferBaseAsset, - provider.getBaseAssetId() + await provider.getBaseAssetId() ); request.addCoinOutput(Address.fromRandom(), amount2, ASSET_A); request.addCoinOutput(Address.fromRandom(), amount3, ASSET_B); diff --git a/packages/fuel-gauge/src/predicate/predicate-input-data.test.ts b/packages/fuel-gauge/src/predicate/predicate-input-data.test.ts index 6e80bc22a35..4a17553ea00 100644 --- a/packages/fuel-gauge/src/predicate/predicate-input-data.test.ts +++ b/packages/fuel-gauge/src/predicate/predicate-input-data.test.ts @@ -29,7 +29,7 @@ describe('Predicate', () => { const receiver = Wallet.generate({ provider }); await expect( - predicate.transfer(receiver.address, amountToReceiver, provider.getBaseAssetId(), { + predicate.transfer(receiver.address, amountToReceiver, await provider.getBaseAssetId(), { gasLimit: 1000, }) ).rejects.toThrow(/PredicateVerificationFailed/i); diff --git a/packages/fuel-gauge/src/predicate/predicate-invalidations.test.ts b/packages/fuel-gauge/src/predicate/predicate-invalidations.test.ts index a1fb59388e0..aba65b1be2a 100644 --- a/packages/fuel-gauge/src/predicate/predicate-invalidations.test.ts +++ b/packages/fuel-gauge/src/predicate/predicate-invalidations.test.ts @@ -34,7 +34,7 @@ describe('Predicate', () => { predicate.transfer( receiver.address, await predicate.getBalance(), - provider.getBaseAssetId(), + await provider.getBaseAssetId(), { gasLimit: 100_000_000, } @@ -65,7 +65,7 @@ describe('Predicate', () => { // fuel-client we should change with the proper error message await expect( - predicate.transfer(receiver.address, 1000, provider.getBaseAssetId(), { + predicate.transfer(receiver.address, 1000, await provider.getBaseAssetId(), { gasLimit: 0, }) ).rejects.toThrow(/Gas limit '0' is lower than the required:./i); diff --git a/packages/fuel-gauge/src/predicate/predicate-populate-witness.test.ts b/packages/fuel-gauge/src/predicate/predicate-populate-witness.test.ts index 827ab20aa8d..cc18eeb4d83 100644 --- a/packages/fuel-gauge/src/predicate/predicate-populate-witness.test.ts +++ b/packages/fuel-gauge/src/predicate/predicate-populate-witness.test.ts @@ -37,7 +37,7 @@ describe('Predicate', () => { wallets: [wallet], } = launched; - const quantity: CoinQuantityLike[] = [[500, provider.getBaseAssetId()]]; + const quantity: CoinQuantityLike[] = [[500, await provider.getBaseAssetId()]]; const predicateAssertNumber = new Predicate<[number]>({ abi: PredicateAssertNumber.abi, @@ -50,7 +50,7 @@ describe('Predicate', () => { let transactionRequest = new ScriptTransactionRequest(); const receiver = Wallet.generate({ provider }); - transactionRequest.addCoinOutput(receiver.address, 100, provider.getBaseAssetId()); + transactionRequest.addCoinOutput(receiver.address, 100, await provider.getBaseAssetId()); const predicateAssertNumberWrongResources = await provider.getResourcesToSpend( predicateAssertNumber.address, @@ -87,12 +87,12 @@ describe('Predicate', () => { wallets: [fundingWallet, wallet1], } = launched; - const quantity: CoinQuantityLike[] = [[500, provider.getBaseAssetId()]]; + const quantity: CoinQuantityLike[] = [[500, await provider.getBaseAssetId()]]; const receiver = Wallet.generate({ provider }); let transactionRequest = new ScriptTransactionRequest({ gasLimit: 2000, maxFee: bn(0) }); - transactionRequest.addCoinOutput(receiver.address, 100, provider.getBaseAssetId()); + transactionRequest.addCoinOutput(receiver.address, 100, await provider.getBaseAssetId()); const predicateAssertNumber = new Predicate<[number]>({ abi: PredicateAssertNumber.abi, @@ -147,7 +147,7 @@ describe('Predicate', () => { wallets: [fundingWallet, wallet1, wallet2], } = launched; - const quantity: CoinQuantityLike[] = [[500, provider.getBaseAssetId()]]; + const quantity: CoinQuantityLike[] = [[500, await provider.getBaseAssetId()]]; const predicateAssertNumber = new Predicate<[number]>({ abi: PredicateAssertNumber.abi, @@ -161,7 +161,7 @@ describe('Predicate', () => { const receiver = Wallet.generate({ provider }); let transactionRequest = new ScriptTransactionRequest({ gasLimit: 2000, maxFee: bn(0) }); - transactionRequest.addCoinOutput(receiver.address, 100, provider.getBaseAssetId()); + transactionRequest.addCoinOutput(receiver.address, 100, await provider.getBaseAssetId()); const resources1 = await wallet1.getResourcesToSpend(quantity); const resources2 = await wallet2.getResourcesToSpend(quantity); @@ -219,7 +219,7 @@ describe('Predicate', () => { wallets: [fundingWallet, wallet1, wallet2, wallet3], } = launched; - const quantity: CoinQuantityLike[] = [[500, provider.getBaseAssetId()]]; + const quantity: CoinQuantityLike[] = [[500, await provider.getBaseAssetId()]]; let transactionRequest = new ScriptTransactionRequest({ gasLimit: 3000, maxFee: bn(0) }); @@ -265,7 +265,7 @@ describe('Predicate', () => { const receiver = Wallet.generate({ provider }); - transactionRequest.addCoinOutput(receiver.address, 100, provider.getBaseAssetId()); + transactionRequest.addCoinOutput(receiver.address, 100, await provider.getBaseAssetId()); transactionRequest.addResources([ ...predicateAssertNumberWrongResources, // witnessIndex 0 but will generate a placeholder witness @@ -314,7 +314,7 @@ describe('Predicate', () => { wallets: [fundingWallet, wallet1, wallet2], } = launched; - const quantity: CoinQuantityLike[] = [[500, provider.getBaseAssetId()]]; + const quantity: CoinQuantityLike[] = [[500, await provider.getBaseAssetId()]]; let transactionRequest = new ScriptTransactionRequest({ gasLimit: 2000, maxFee: bn(0) }); @@ -350,7 +350,7 @@ describe('Predicate', () => { const receiver = Wallet.generate({ provider }); - transactionRequest.addCoinOutput(receiver.address, 100, provider.getBaseAssetId()); + transactionRequest.addCoinOutput(receiver.address, 100, await provider.getBaseAssetId()); transactionRequest.addResources([ ...resources1, // witnessIndex 0 @@ -396,7 +396,7 @@ describe('Predicate', () => { wallets: [fundingWallet, wallet1, wallet2, wallet3], } = launched; - const quantity: CoinQuantityLike[] = [[500, provider.getBaseAssetId()]]; + const quantity: CoinQuantityLike[] = [[500, await provider.getBaseAssetId()]]; let transactionRequest = new ScriptTransactionRequest({ gasLimit: 2000, maxFee: bn(0) }); @@ -438,7 +438,7 @@ describe('Predicate', () => { const receiver = Wallet.generate({ provider }); - transactionRequest.addCoinOutput(receiver.address, 100, provider.getBaseAssetId()); + transactionRequest.addCoinOutput(receiver.address, 100, await provider.getBaseAssetId()); transactionRequest.addResources([ ...resources1, // witnessIndex 0 diff --git a/packages/fuel-gauge/src/predicate/predicate-with-contract.test.ts b/packages/fuel-gauge/src/predicate/predicate-with-contract.test.ts index 89cc08ed1d9..70bc1cae50c 100644 --- a/packages/fuel-gauge/src/predicate/predicate-with-contract.test.ts +++ b/packages/fuel-gauge/src/predicate/predicate-with-contract.test.ts @@ -33,7 +33,7 @@ describe('Predicate', () => { const { waitForResult } = await contractPredicate.functions .return_context_amount() .callParams({ - forward: [500, provider.getBaseAssetId()], + forward: [500, await provider.getBaseAssetId()], }) .call(); @@ -87,7 +87,7 @@ describe('Predicate', () => { const tx = await predicate.transfer( receiver.address, amountToReceiver, - provider.getBaseAssetId() + await provider.getBaseAssetId() ); const { isStatusSuccess } = await tx.waitForResult(); expect(isStatusSuccess).toBeTruthy(); diff --git a/packages/fuel-gauge/src/predicate/predicate-with-script.test.ts b/packages/fuel-gauge/src/predicate/predicate-with-script.test.ts index 10b9e5d72a1..76080a18834 100644 --- a/packages/fuel-gauge/src/predicate/predicate-with-script.test.ts +++ b/packages/fuel-gauge/src/predicate/predicate-with-script.test.ts @@ -62,7 +62,7 @@ describe('Predicate', () => { const tx = await predicate.transfer( receiver.address, amountToReceiver, - provider.getBaseAssetId(), + await provider.getBaseAssetId(), { gasLimit: 1000, } diff --git a/packages/fuel-gauge/src/predicate/utils/predicate/fundPredicate.ts b/packages/fuel-gauge/src/predicate/utils/predicate/fundPredicate.ts index 8d092e444a0..38adad6f0c5 100644 --- a/packages/fuel-gauge/src/predicate/utils/predicate/fundPredicate.ts +++ b/packages/fuel-gauge/src/predicate/utils/predicate/fundPredicate.ts @@ -7,7 +7,7 @@ export const fundPredicate = async ( amountToPredicate: BigNumberish, utxosAmount: number = 1 ): Promise => { - const baseAssetId = wallet.provider.getBaseAssetId(); + const baseAssetId = await wallet.provider.getBaseAssetId(); const request = new ScriptTransactionRequest(); for (let i = 0; i < utxosAmount; i++) { diff --git a/packages/fuel-gauge/src/raw-slice.test.ts b/packages/fuel-gauge/src/raw-slice.test.ts index dc589c921db..1964495b166 100644 --- a/packages/fuel-gauge/src/raw-slice.test.ts +++ b/packages/fuel-gauge/src/raw-slice.test.ts @@ -101,7 +101,7 @@ describe('Raw Slice Tests', () => { const setupTx = await wallet.transfer( predicate.address, amountToPredicate, - provider.getBaseAssetId(), + await provider.getBaseAssetId(), { gasLimit: 10_000, } @@ -113,7 +113,7 @@ describe('Raw Slice Tests', () => { const tx = await predicate.transfer( receiver.address, amountToReceiver, - provider.getBaseAssetId(), + await provider.getBaseAssetId(), { gasLimit: 10_000, } diff --git a/packages/fuel-gauge/src/std-lib-string.test.ts b/packages/fuel-gauge/src/std-lib-string.test.ts index b6d919d7eb0..9b37ef5ec45 100644 --- a/packages/fuel-gauge/src/std-lib-string.test.ts +++ b/packages/fuel-gauge/src/std-lib-string.test.ts @@ -61,7 +61,7 @@ describe('std-lib-string Tests', () => { const setupTx = await wallet.transfer( predicate.address, amountToPredicate, - provider.getBaseAssetId(), + await provider.getBaseAssetId(), { gasLimit: 10_000, } @@ -72,7 +72,7 @@ describe('std-lib-string Tests', () => { const tx = await predicate.transfer( receiver.address, amountToReceiver, - provider.getBaseAssetId(), + await provider.getBaseAssetId(), { gasLimit: 10_000, } diff --git a/packages/fuel-gauge/src/str-slice.test.ts b/packages/fuel-gauge/src/str-slice.test.ts index 4803da4b2cd..0d505efd452 100644 --- a/packages/fuel-gauge/src/str-slice.test.ts +++ b/packages/fuel-gauge/src/str-slice.test.ts @@ -42,7 +42,7 @@ describe('str slice', () => { provider, data: predicateData, }); - const baseAssetId = provider.getBaseAssetId(); + const baseAssetId = await provider.getBaseAssetId(); const amountToPredicate = 250_000; const amountToReceiver = 50_000; diff --git a/packages/fuel-gauge/src/token-test-contract.test.ts b/packages/fuel-gauge/src/token-test-contract.test.ts index 5a930e59060..4baef1dd0ef 100644 --- a/packages/fuel-gauge/src/token-test-contract.test.ts +++ b/packages/fuel-gauge/src/token-test-contract.test.ts @@ -193,7 +193,7 @@ describe('TokenTestContract', () => { const addressParameter = { bits: userWallet.address, }; - const assetId: AssetId = { bits: provider.getBaseAssetId() }; + const assetId: AssetId = { bits: await provider.getBaseAssetId() }; await expectToThrowFuelError( // eslint-disable-next-line @typescript-eslint/ban-ts-comment diff --git a/packages/fuel-gauge/src/transaction-response.test.ts b/packages/fuel-gauge/src/transaction-response.test.ts index a9763a3112a..0b7842ae6bc 100644 --- a/packages/fuel-gauge/src/transaction-response.test.ts +++ b/packages/fuel-gauge/src/transaction-response.test.ts @@ -86,7 +86,7 @@ describe('TransactionResponse', () => { const { id: transactionId } = await adminWallet.transfer( destination.address, 100, - provider.getBaseAssetId(), + await provider.getBaseAssetId(), { gasLimit: 10_000 } ); @@ -123,7 +123,7 @@ describe('TransactionResponse', () => { const { id: transactionId } = await adminWallet.transfer( destination.address, 100, - provider.getBaseAssetId() + await provider.getBaseAssetId() ); const response = await TransactionResponse.create(transactionId, provider); @@ -186,7 +186,7 @@ describe('TransactionResponse', () => { const { id: transactionId } = await genesisWallet.transfer( destination.address, 100, - provider.getBaseAssetId(), + await provider.getBaseAssetId(), { gasLimit: 10_000 } ); const response = await TransactionResponse.create(transactionId, provider); @@ -237,7 +237,7 @@ describe('TransactionResponse', () => { const request = new ScriptTransactionRequest(); - request.addCoinOutput(Wallet.generate(), 100, provider.getBaseAssetId()); + request.addCoinOutput(Wallet.generate(), 100, await provider.getBaseAssetId()); const txCost = await genesisWallet.getTransactionCost(request); @@ -289,7 +289,7 @@ describe('TransactionResponse', () => { const request = new ScriptTransactionRequest(); - request.addCoinOutput(Wallet.generate(), 100, provider.getBaseAssetId()); + request.addCoinOutput(Wallet.generate(), 100, await provider.getBaseAssetId()); const txCost = await genesisWallet.getTransactionCost(request, { signatureCallback: (tx) => tx.addAccountWitnesses(genesisWallet), diff --git a/packages/fuel-gauge/src/transaction-summary.test.ts b/packages/fuel-gauge/src/transaction-summary.test.ts index ca8d53e9acd..fe40905b4cb 100644 --- a/packages/fuel-gauge/src/transaction-summary.test.ts +++ b/packages/fuel-gauge/src/transaction-summary.test.ts @@ -94,7 +94,7 @@ describe('TransactionSummary', () => { wallets: [sender, destination], } = launched; - const tx = await sender.transfer(destination.address, 1000, provider.getBaseAssetId()); + const tx = await sender.transfer(destination.address, 1000, await provider.getBaseAssetId()); const submittedTxResult = await tx.waitForResult(); const laterFetchedResult = await getTransactionSummary({ @@ -131,13 +131,17 @@ describe('TransactionSummary', () => { const amountToTransfer = 100; - const tx1 = await sender.transfer(sender.address, amountToTransfer, provider.getBaseAssetId()); + const tx1 = await sender.transfer( + sender.address, + amountToTransfer, + await provider.getBaseAssetId() + ); const txResult1 = await tx1.waitForResult(); const tx2 = await sender.transfer( destination.address, amountToTransfer * 2, - provider.getBaseAssetId() + await provider.getBaseAssetId() ); const txResult2 = await tx2.waitForResult(); @@ -341,7 +345,7 @@ describe('TransactionSummary', () => { const amount = 1233; - const tx1 = await wallet.transfer(recipient.address, amount, provider.getBaseAssetId()); + const tx1 = await wallet.transfer(recipient.address, amount, await provider.getBaseAssetId()); const { operations } = await tx1.waitForResult(); @@ -355,7 +359,7 @@ describe('TransactionSummary', () => { recipients: [ { address: recipient.address, - quantities: [{ amount, assetId: provider.getBaseAssetId() }], + quantities: [{ amount, assetId: await provider.getBaseAssetId() }], }, ], }); @@ -379,7 +383,7 @@ describe('TransactionSummary', () => { wallets: [majorWallet], } = launched; - const baseAssetId = provider.getBaseAssetId(); + const baseAssetId = await provider.getBaseAssetId(); const recipient = Wallet.generate({ provider }); const minorWallet = Wallet.generate({ provider }); @@ -387,7 +391,7 @@ describe('TransactionSummary', () => { const submitted = await majorWallet.transfer( minorWallet.address, minorAmount, - provider.getBaseAssetId() + await provider.getBaseAssetId() ); await submitted.waitForResult(); @@ -401,10 +405,14 @@ describe('TransactionSummary', () => { request.addResources([...majorResources, ...minorResources]); // Add transfer to recipient - request.addCoinOutput(recipient.address, transferAmount, provider.getBaseAssetId()); + request.addCoinOutput(recipient.address, transferAmount, await provider.getBaseAssetId()); // Add transfer to self - request.addCoinOutput(majorWallet.address, transferBackAmount, provider.getBaseAssetId()); + request.addCoinOutput( + majorWallet.address, + transferBackAmount, + await provider.getBaseAssetId() + ); // Explicitly setting the Output Change address to the recipient const index = request.outputs.findIndex((output) => output.type === OutputType.Change); @@ -424,11 +432,11 @@ describe('TransactionSummary', () => { recipients: [ { address: recipient.address, - quantities: [{ amount: transferAmount, assetId: provider.getBaseAssetId() }], + quantities: [{ amount: transferAmount, assetId: await provider.getBaseAssetId() }], }, { address: majorWallet.address, - quantities: [{ amount: transferBackAmount, assetId: provider.getBaseAssetId() }], + quantities: [{ amount: transferBackAmount, assetId: await provider.getBaseAssetId() }], }, ], }); @@ -544,13 +552,13 @@ describe('TransactionSummary', () => { quantities: [ { amount: 543, assetId: ASSET_A }, { amount: 40, assetId: ASSET_B }, - { amount: 123, assetId: provider.getBaseAssetId() }, + { amount: 123, assetId: await provider.getBaseAssetId() }, ], }; const transferData2 = { address: Wallet.generate({ provider }).address, quantities: [ - { amount: 12, assetId: provider.getBaseAssetId() }, + { amount: 12, assetId: await provider.getBaseAssetId() }, { amount: 612, assetId: ASSET_B }, ], }; @@ -682,7 +690,7 @@ describe('TransactionSummary', () => { quantities: [ { amount: 500, assetId: ASSET_A }, { amount: 700, assetId: ASSET_B }, - { amount: 100, assetId: provider.getBaseAssetId() }, + { amount: 100, assetId: await provider.getBaseAssetId() }, ], }; @@ -756,7 +764,7 @@ describe('TransactionSummary', () => { quantities: [ { amount: 500, assetId: ASSET_A }, { amount: 700, assetId: ASSET_B }, - { amount: 100, assetId: provider.getBaseAssetId() }, + { amount: 100, assetId: await provider.getBaseAssetId() }, ], }; @@ -812,7 +820,8 @@ describe('TransactionSummary', () => { const amount = 100; - const tx1 = await wallet.transferToContract(contract.id, amount); + const baseAssetId = await provider.getBaseAssetId(); + const tx1 = await wallet.transferToContract(contract.id, amount, baseAssetId); const { operations } = await tx1.waitForResult(); @@ -824,7 +833,10 @@ describe('TransactionSummary', () => { fromType: AddressType.account, toType: AddressType.contract, recipients: [ - { address: contract.id, quantities: [{ amount, assetId: provider.getBaseAssetId() }] }, + { + address: contract.id, + quantities: [{ amount, assetId: await provider.getBaseAssetId() }], + }, ], }); }); @@ -856,7 +868,7 @@ describe('TransactionSummary', () => { expect(operations[0].to?.chain).toEqual(ChainName.ethereum); expect(operations[0].assetsSent).toHaveLength(1); expect(operations[0].assetsSent?.[0].amount).toEqual(bn(amountToWithdraw)); - expect(operations[0].assetsSent?.[0].assetId).toEqual(provider.getBaseAssetId()); + expect(operations[0].assetsSent?.[0].assetId).toEqual(await provider.getBaseAssetId()); }); it('Should return contract created operations', async () => { diff --git a/packages/fuel-gauge/src/transaction-upgrade.test.ts b/packages/fuel-gauge/src/transaction-upgrade.test.ts index 73a7c56d050..45f01927108 100644 --- a/packages/fuel-gauge/src/transaction-upgrade.test.ts +++ b/packages/fuel-gauge/src/transaction-upgrade.test.ts @@ -47,7 +47,7 @@ const setupTestNode = async () => { snapshotConfig, }, }); - privileged.provider = await Provider.create(provider.url); + privileged.provider = new Provider(provider.url); return { provider, privileged, wallets, cleanup, [Symbol.dispose]: cleanup }; }; @@ -101,7 +101,7 @@ describe('Transaction upgrade consensus', () => { using launched = await setupTestNode(); const { privileged, provider } = launched; - const mainProvider = await Provider.create(provider.url); + const mainProvider = new Provider(provider.url); const { chain: { consensusParameters: consensusBeforeUpgrade }, diff --git a/packages/fuel-gauge/src/transaction.test.ts b/packages/fuel-gauge/src/transaction.test.ts index 3befa770c10..0a5efb5179b 100644 --- a/packages/fuel-gauge/src/transaction.test.ts +++ b/packages/fuel-gauge/src/transaction.test.ts @@ -55,7 +55,7 @@ describe('Transaction', () => { wallets: [fundedWallet], } = launched; - const baseAssetId = provider.getBaseAssetId(); + const baseAssetId = await provider.getBaseAssetId(); const { messages: [message], diff --git a/packages/fuel-gauge/src/vector-types.test.ts b/packages/fuel-gauge/src/vector-types.test.ts index 0c349870559..e641c876938 100644 --- a/packages/fuel-gauge/src/vector-types.test.ts +++ b/packages/fuel-gauge/src/vector-types.test.ts @@ -174,7 +174,7 @@ describe('Vector Types Validation', () => { const setupTx = await wallet.transfer( predicate.address, amountToPredicate, - provider.getBaseAssetId(), + await provider.getBaseAssetId(), { gasLimit: 10_000, } @@ -186,7 +186,7 @@ describe('Vector Types Validation', () => { const tx = await predicate.transfer( receiver.address, amountToReceiver, - provider.getBaseAssetId(), + await provider.getBaseAssetId(), { gasLimit: 10_000, } diff --git a/packages/fuels/src/cli/commands/deploy/createWallet.ts b/packages/fuels/src/cli/commands/deploy/createWallet.ts index a05f1f8558e..75615823a8d 100644 --- a/packages/fuels/src/cli/commands/deploy/createWallet.ts +++ b/packages/fuels/src/cli/commands/deploy/createWallet.ts @@ -16,7 +16,8 @@ export async function createWallet(providerUrl: string, privateKey?: string) { } try { - const provider = await Provider.create(providerUrl); + const provider = new Provider(providerUrl); + await provider.init(); // can probably be removed return Wallet.fromPrivateKey(pvtKey, provider); } catch (e) { diff --git a/packages/fuels/src/setup-launch-node-server.test.ts b/packages/fuels/src/setup-launch-node-server.test.ts index 92479b00e54..7f7677c2576 100644 --- a/packages/fuels/src/setup-launch-node-server.test.ts +++ b/packages/fuels/src/setup-launch-node-server.test.ts @@ -90,7 +90,7 @@ describe( const url = await (await fetch(launched.serverUrl)).text(); // fetches node-related data // would fail if fuel-core node is not running on url - await Provider.create(url); + await new Provider(url).init(); }); test('the /cleanup endpoint kills the node', async () => { diff --git a/packages/program/src/functions/base-invocation-scope.ts b/packages/program/src/functions/base-invocation-scope.ts index e578954d9a0..fc133f34a92 100644 --- a/packages/program/src/functions/base-invocation-scope.ts +++ b/packages/program/src/functions/base-invocation-scope.ts @@ -93,7 +93,7 @@ export class BaseInvocationScope { if (!consensusParams) { throw new FuelError( FuelError.CODES.CHAIN_INFO_CACHE_EMPTY, - 'Provider chain info cache is empty. Please make sure to initialize the `Provider` properly by running `await Provider.create()``' + 'Provider chain info cache is empty. Please make sure to initialize the `Provider` properly by running `new Provider()``' ); } return this.functionInvocationScopes.map((funcScope) => createContractCall(funcScope)); @@ -102,13 +102,13 @@ export class BaseInvocationScope { /** * Updates the script request with the current contract calls. */ - protected updateScriptRequest() { + protected async updateScriptRequest() { const provider = this.getProvider(); const { consensusParameters: { txParameters: { maxInputs }, }, - } = provider.getChain(); + } = await provider.getChain(); const contractCallScript = getContractCallScript(this.functionInvocationScopes, maxInputs); this.transactionRequest.setScript(contractCallScript, this.calls); } @@ -198,7 +198,7 @@ export class BaseInvocationScope { await asm.initWasm(); // Update request scripts before call - this.updateScriptRequest(); + await this.updateScriptRequest(); // Update required coins before call this.updateRequiredCoins(); @@ -318,11 +318,11 @@ export class BaseInvocationScope { */ addTransfer(transferParams: TransferParams) { const { amount, destination, assetId } = transferParams; - const baseAssetId = this.getProvider().getBaseAssetId(); + // const baseAssetId = await this.getProvider().getBaseAssetId(); this.transactionRequest = this.transactionRequest.addCoinOutput( Address.fromAddressOrString(destination), amount, - assetId || baseAssetId + assetId ); return this; @@ -335,12 +335,11 @@ export class BaseInvocationScope { * @returns The current instance of the class. */ addBatchTransfer(transferParams: TransferParams[]) { - const baseAssetId = this.getProvider().getBaseAssetId(); transferParams.forEach(({ destination, amount, assetId }) => { this.transactionRequest = this.transactionRequest.addCoinOutput( Address.fromAddressOrString(destination), amount, - assetId || baseAssetId + assetId ); }); diff --git a/packages/recipes/src/types/Src14OwnedProxy.ts b/packages/recipes/src/types/Src14OwnedProxy.ts index dcfab7009a8..aab3c9532ae 100644 --- a/packages/recipes/src/types/Src14OwnedProxy.ts +++ b/packages/recipes/src/types/Src14OwnedProxy.ts @@ -5,7 +5,7 @@ /* eslint-disable @typescript-eslint/consistent-type-imports */ /* - Fuels version: 0.97.0 + Fuels version: 0.97.2 */ import { Contract, type InvokeFunction } from '@fuel-ts/program'; diff --git a/packages/recipes/src/types/Src14OwnedProxyFactory.ts b/packages/recipes/src/types/Src14OwnedProxyFactory.ts index b0789cb3f5a..30762b7a0e9 100644 --- a/packages/recipes/src/types/Src14OwnedProxyFactory.ts +++ b/packages/recipes/src/types/Src14OwnedProxyFactory.ts @@ -5,7 +5,7 @@ /* eslint-disable @typescript-eslint/consistent-type-imports */ /* - Fuels version: 0.97.0 + Fuels version: 0.97.2 */ import { ContractFactory, type DeployContractOptions } from '@fuel-ts/contract'; diff --git a/packages/recipes/src/types/common.d.ts b/packages/recipes/src/types/common.d.ts index d7ca20eaa69..ef3dec5e95c 100644 --- a/packages/recipes/src/types/common.d.ts +++ b/packages/recipes/src/types/common.d.ts @@ -5,7 +5,7 @@ /* eslint-disable @typescript-eslint/consistent-type-imports */ /* - Fuels version: 0.97.0 + Fuels version: 0.97.2 */ /** diff --git a/packages/recipes/src/types/index.ts b/packages/recipes/src/types/index.ts index 22dd3591167..15dc6b12ae3 100644 --- a/packages/recipes/src/types/index.ts +++ b/packages/recipes/src/types/index.ts @@ -5,7 +5,7 @@ /* eslint-disable @typescript-eslint/consistent-type-imports */ /* - Fuels version: 0.97.0 + Fuels version: 0.97.2 */ export { Src14OwnedProxy } from './Src14OwnedProxy'; diff --git a/packages/script/src/script-invocation-scope.ts b/packages/script/src/script-invocation-scope.ts index e40d07dc9ae..d2b880e2881 100644 --- a/packages/script/src/script-invocation-scope.ts +++ b/packages/script/src/script-invocation-scope.ts @@ -10,23 +10,23 @@ export class ScriptInvocationScope< > extends FunctionInvocationScope { scriptRequest!: ScriptRequest; - protected override updateScriptRequest() { + protected override async updateScriptRequest() { if (!this.scriptRequest) { - this.buildScriptRequest(); + await this.buildScriptRequest(); } this.transactionRequest.setScript(this.scriptRequest, this.args); } - private buildScriptRequest() { + private async buildScriptRequest() { const programBytes = (this.program as AbstractScript).bytes; - const chainInfoCache = (this.program.provider as Provider).getChain(); + const chainInfoCache = await (this.program.provider as Provider).getChain(); // TODO: Remove this error since it is already handled on Provider class if (!chainInfoCache) { throw new FuelError( FuelError.CODES.CHAIN_INFO_CACHE_EMPTY, - 'Provider chain info cache is empty. Please make sure to initialize the `Provider` properly by running `await Provider.create()`' + 'Provider chain info cache is empty. Please make sure to initialize the `Provider` properly by running `new Provider()`' ); } diff --git a/templates/nextjs/src/app/layout.tsx b/templates/nextjs/src/app/layout.tsx index 235c91c3047..195a7973214 100644 --- a/templates/nextjs/src/app/layout.tsx +++ b/templates/nextjs/src/app/layout.tsx @@ -16,7 +16,7 @@ const queryClient = new QueryClient(); const connectors = defaultConnectors({ devMode: true, - burnerWalletConfig: { fuelProvider: Provider.create(providerUrl) }, + burnerWalletConfig: { fuelProvider: new Provider(providerUrl) }, }); interface RootLayoutProps { diff --git a/templates/vite/src/main.tsx b/templates/vite/src/main.tsx index 4f0e9214b4a..5eedd96e47d 100644 --- a/templates/vite/src/main.tsx +++ b/templates/vite/src/main.tsx @@ -16,7 +16,7 @@ const queryClient = new QueryClient(); const connectors = defaultConnectors({ devMode: true, - burnerWalletConfig: { fuelProvider: Provider.create(providerUrl) }, + burnerWalletConfig: { fuelProvider: new Provider(providerUrl) }, }); createRoot(document.getElementById("root")!).render( From 857c5928bb947875e438ae35d0e5f6df63bd29ce Mon Sep 17 00:00:00 2001 From: Anderson Arboleya Date: Sat, 28 Dec 2024 07:30:41 -0300 Subject: [PATCH 02/29] Disabling side-effects warning for docs --- apps/docs/.eslintrc.cjs | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/docs/.eslintrc.cjs b/apps/docs/.eslintrc.cjs index 44ab8e996bf..c7ba193004c 100644 --- a/apps/docs/.eslintrc.cjs +++ b/apps/docs/.eslintrc.cjs @@ -2,6 +2,7 @@ module.exports = { extends: ["../../.eslintrc.js"], rules: { "no-console": "off", + "no-new": "off", "tsdoc/syntax": "off", }, }; From b46d8aee5338805b5a837a05b4d4b86aa5f21242 Mon Sep 17 00:00:00 2001 From: Anderson Arboleya Date: Sat, 28 Dec 2024 09:12:37 -0300 Subject: [PATCH 03/29] What was that? --- packages/program/src/functions/base-invocation-scope.ts | 9 --------- 1 file changed, 9 deletions(-) diff --git a/packages/program/src/functions/base-invocation-scope.ts b/packages/program/src/functions/base-invocation-scope.ts index fc133f34a92..7e7ae1f0ebf 100644 --- a/packages/program/src/functions/base-invocation-scope.ts +++ b/packages/program/src/functions/base-invocation-scope.ts @@ -87,15 +87,6 @@ export class BaseInvocationScope { * @returns An array of contract calls. */ protected get calls() { - const provider = this.getProvider(); - const consensusParams = provider.getChain(); - // TODO: Remove this error since it is already handled on Provider class - if (!consensusParams) { - throw new FuelError( - FuelError.CODES.CHAIN_INFO_CACHE_EMPTY, - 'Provider chain info cache is empty. Please make sure to initialize the `Provider` properly by running `new Provider()``' - ); - } return this.functionInvocationScopes.map((funcScope) => createContractCall(funcScope)); } From 73e6ba41a1a4baa023f710b246a0b6538b308bb0 Mon Sep 17 00:00:00 2001 From: Anderson Arboleya Date: Wed, 1 Jan 2025 06:38:06 -0300 Subject: [PATCH 04/29] Rolling back original method as deprecated --- packages/account/src/providers/provider.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/account/src/providers/provider.ts b/packages/account/src/providers/provider.ts index 4b3c25a800b..201c4dad7bf 100644 --- a/packages/account/src/providers/provider.ts +++ b/packages/account/src/providers/provider.ts @@ -520,6 +520,18 @@ export default class Provider { }; } + /** + * Creates a new instance of the Provider class. This is the recommended way to initialize a Provider. + * @deprecated Use `new Provider(...)` instead. + * + * @param url - GraphQL endpoint of the Fuel node + * @param options - Additional options for the provider + * @returns A promise that resolves to a Provider instance. + */ + static async create(url: string, options: ProviderOptions = {}): Promise { + return new Provider(url, options).init(); + } + /** * Initialize Provider async stuff */ From fab02a108328b7c8f74e3d71ef841d5a3aaeedc6 Mon Sep 17 00:00:00 2001 From: Anderson Arboleya Date: Wed, 1 Jan 2025 06:38:24 -0300 Subject: [PATCH 05/29] DRY doc's snippets --- .../contracts/snippets/cost-estimation.ts | 8 ++++--- .../cookbook/snippets/combining-utxos.ts | 23 ++++++------------- .../snippets/custom-contract-calls.ts | 10 ++++---- .../signing-transactions/predicate.ts | 16 ++++--------- .../cookbook/snippets/splitting-utxos.ts | 15 ++++-------- .../configurables/configurable-default.ts | 18 +++++---------- .../configurables/configurable-set-data.ts | 18 +++++---------- .../cookbook/failure-returns-false.ts | 10 ++++---- .../predicates/snippets/cookbook/pre-stage.ts | 6 +++-- .../snippets/cookbook/transferring-assets.ts | 6 +++-- .../snippets/methods/create-transfer.ts | 6 +++-- .../predicates/snippets/methods/transfer.ts | 6 +++-- .../snippets/transfers/batch-transfer.ts | 8 ++++--- .../wallet-transferring/create-transfer-2.ts | 4 ++-- .../wallet-transferring/create-transfer.ts | 4 ++-- 15 files changed, 68 insertions(+), 90 deletions(-) diff --git a/apps/docs/src/guide/contracts/snippets/cost-estimation.ts b/apps/docs/src/guide/contracts/snippets/cost-estimation.ts index a30ce4c29d7..eab93bb6acd 100644 --- a/apps/docs/src/guide/contracts/snippets/cost-estimation.ts +++ b/apps/docs/src/guide/contracts/snippets/cost-estimation.ts @@ -4,6 +4,8 @@ import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../env'; import { ReturnContextFactory } from '../../../typegend'; const provider = new Provider(LOCAL_NETWORK_URL); +const baseAssetId = await provider.getBaseAssetId(); + const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const deploy = await ReturnContextFactory.deploy(wallet); @@ -13,7 +15,7 @@ const { contract } = await deploy.waitForResult(); const cost = await contract.functions .return_context_amount() .callParams({ - forward: [100, await provider.getBaseAssetId()], + forward: [100, baseAssetId], }) .getTransactionCost(); @@ -23,10 +25,10 @@ console.log('costs', cost); // #region cost-estimation-2 const scope = contract.multiCall([ contract.functions.return_context_amount().callParams({ - forward: [100, await provider.getBaseAssetId()], + forward: [100, baseAssetId], }), contract.functions.return_context_amount().callParams({ - forward: [300, await provider.getBaseAssetId()], + forward: [300, baseAssetId], }), ]); diff --git a/apps/docs/src/guide/cookbook/snippets/combining-utxos.ts b/apps/docs/src/guide/cookbook/snippets/combining-utxos.ts index 45489043e7d..481b928a54c 100644 --- a/apps/docs/src/guide/cookbook/snippets/combining-utxos.ts +++ b/apps/docs/src/guide/cookbook/snippets/combining-utxos.ts @@ -4,6 +4,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../env'; const provider = new Provider(LOCAL_NETWORK_URL); +const baseAssetId = await provider.getBaseAssetId(); const fundingWallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const wallet = Wallet.generate({ provider }); @@ -14,46 +15,36 @@ for (let i = 0; i < 10; i++) { const initTx = await fundingWallet.transfer( wallet.address, 1000, - await provider.getBaseAssetId() + baseAssetId ); await initTx.waitForResult(); } // We can fetch the coins to see how many UTXOs we have, and confirm it is 10. -const { coins: initialCoins } = await wallet.getCoins( - await provider.getBaseAssetId() -); +const { coins: initialCoins } = await wallet.getCoins(baseAssetId); console.log('Initial Coins Length', initialCoins.length); // 10 // But we can also confirm the total balance of the base asset for this account is 10_000. -const initialBalance = await wallet.getBalance(await provider.getBaseAssetId()); +const initialBalance = await wallet.getBalance(baseAssetId); console.log('Initial Balance', initialBalance.toNumber()); // 10_000 // Now we can combine the UTXOs into a single UTXO by performing a single transfer for the // majority of the balance. Of course, we will still need some funds for the transaction fees. -const combineTx = await wallet.transfer( - wallet.address, - 9500, - await provider.getBaseAssetId() -); +const combineTx = await wallet.transfer(wallet.address, 9500, baseAssetId); await combineTx.wait(); // Now we can perform the same validations and see we have less UTXOs. // We have 2 in this instance, as we have performed the transfer in the base asset: // a UTXO for our transfer, and another for what is left after paying the fees. -const { coins: combinedCoins } = await wallet.getCoins( - await provider.getBaseAssetId() -); +const { coins: combinedCoins } = await wallet.getCoins(baseAssetId); console.log('Combined Coins Length', combinedCoins.length); // 2 // And we can also confirm the final balance of the base asset for this account is 9_998, // so the cost of combining is also minimal. -const combinedBalance = await wallet.getBalance( - await provider.getBaseAssetId() -); +const combinedBalance = await wallet.getBalance(baseAssetId); console.log('Combined Balance', combinedBalance.toNumber()); // 9_998 // #endregion combining-utxos diff --git a/apps/docs/src/guide/cookbook/snippets/custom-contract-calls.ts b/apps/docs/src/guide/cookbook/snippets/custom-contract-calls.ts index 2a4ac74153e..7ff77327933 100644 --- a/apps/docs/src/guide/cookbook/snippets/custom-contract-calls.ts +++ b/apps/docs/src/guide/cookbook/snippets/custom-contract-calls.ts @@ -5,6 +5,8 @@ import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../env'; import { CounterFactory } from '../../../typegend'; const provider = new Provider(LOCAL_NETWORK_URL); +const baseAssetId = await provider.getBaseAssetId(); + const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const deploy = await CounterFactory.deploy(wallet); const { contract } = await deploy.waitForResult(); @@ -20,7 +22,7 @@ const scope = contractInstance.functions .addTransfer({ amount: amountToRecipient, destination: receiverWallet.address, - assetId: await provider.getBaseAssetId(), + assetId: baseAssetId, }); // Build a transaction request from the invocation scope @@ -29,7 +31,7 @@ const transactionRequest = await scope.getTransactionRequest(); transactionRequest.addCoinOutput( receiverWallet.address, amountToRecipient, - await provider.getBaseAssetId() + baseAssetId ); const txCost = await wallet.getTransactionCost(transactionRequest); @@ -54,8 +56,6 @@ console.log('value', value); // // #endregion custom-transactions-contract-calls -const receiverBalance = await receiverWallet.getBalance( - await provider.getBaseAssetId() -); +const receiverBalance = await receiverWallet.getBalance(baseAssetId); console.log('balance', receiverBalance.toNumber()); diff --git a/apps/docs/src/guide/cookbook/snippets/signing-transactions/predicate.ts b/apps/docs/src/guide/cookbook/snippets/signing-transactions/predicate.ts index cf29391ed86..81150f1b488 100644 --- a/apps/docs/src/guide/cookbook/snippets/signing-transactions/predicate.ts +++ b/apps/docs/src/guide/cookbook/snippets/signing-transactions/predicate.ts @@ -24,25 +24,19 @@ const predicate = new Predicate<[string]>({ provider, data: [signer.address.toB256()], }); -const tx = await sender.transfer( - predicate.address, - 200_000, - await provider.getBaseAssetId() -); +const baseAssetId = await provider.getBaseAssetId(); + +const tx = await sender.transfer(predicate.address, 200_000, baseAssetId); await tx.waitForResult(); // Create the transaction request const request = new ScriptTransactionRequest(); -request.addCoinOutput( - receiver.address, - amountToReceiver, - await provider.getBaseAssetId() -); +request.addCoinOutput(receiver.address, amountToReceiver, baseAssetId); // Get the predicate resources and add them and predicate data to the request const resources = await predicate.getResourcesToSpend([ { - assetId: await provider.getBaseAssetId(), + assetId: baseAssetId, amount: amountToReceiver, }, ]); diff --git a/apps/docs/src/guide/cookbook/snippets/splitting-utxos.ts b/apps/docs/src/guide/cookbook/snippets/splitting-utxos.ts index 0c2d1a2cbfc..c4bd5f6ed32 100644 --- a/apps/docs/src/guide/cookbook/snippets/splitting-utxos.ts +++ b/apps/docs/src/guide/cookbook/snippets/splitting-utxos.ts @@ -4,6 +4,7 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../env'; const provider = new Provider(LOCAL_NETWORK_URL); +const baseAssetId = await provider.getBaseAssetId(); // This is the wallet that will fund the sending wallet const fundingWallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); @@ -16,14 +17,12 @@ const destinationWallet = Wallet.generate({ provider }); const fundingTx = await fundingWallet.transfer( wallet.address, 1000, - await provider.getBaseAssetId() + baseAssetId ); await fundingTx.waitForResult(); // We can fetch the coins to see how many UTXOs we have and confirm it is 1 -const { coins: initialCoins } = await wallet.getCoins( - await provider.getBaseAssetId() -); +const { coins: initialCoins } = await wallet.getCoins(baseAssetId); console.log('Initial Coins Length', initialCoins.length); // 1 @@ -31,17 +30,13 @@ console.log('Initial Coins Length', initialCoins.length); // Including the address to send the funds to and the assetId we want to send const splitTxns = new Array(5).fill({ amount: 200, - assetId: await provider.getBaseAssetId(), + assetId: baseAssetId, destination: destinationWallet.address, }); // We will also need add some funds to the wallet to cover the fee // We could have also spent less than 200 for each UTXO, but this is just an example -const fundTx = await fundingWallet.transfer( - wallet.address, - 500, - await provider.getBaseAssetId() -); +const fundTx = await fundingWallet.transfer(wallet.address, 500, baseAssetId); await fundTx.waitForResult(); console.log('Split UTXOs', splitTxns); diff --git a/apps/docs/src/guide/predicates/snippets/configurables/configurable-default.ts b/apps/docs/src/guide/predicates/snippets/configurables/configurable-default.ts index 99cbfebdc21..c676faef36a 100644 --- a/apps/docs/src/guide/predicates/snippets/configurables/configurable-default.ts +++ b/apps/docs/src/guide/predicates/snippets/configurables/configurable-default.ts @@ -5,6 +5,7 @@ import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { WhitelistedAddressPredicate } from '../../../../typegend/predicates/WhitelistedAddressPredicate'; const provider = new Provider(LOCAL_NETWORK_URL); +const baseAssetId = await provider.getBaseAssetId(); const sender = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const recipient = Wallet.generate({ provider }); @@ -16,14 +17,9 @@ const predicate = new WhitelistedAddressPredicate({ }); // Transferring funds to the predicate -const tx1 = await sender.transfer( - predicate.address, - 200_000, - await provider.getBaseAssetId(), - { - gasLimit: 1000, - } -); +const tx1 = await sender.transfer(predicate.address, 200_000, baseAssetId, { + gasLimit: 1000, +}); await tx1.waitForResult(); @@ -33,7 +29,7 @@ const amountToTransfer = 100; const tx2 = await predicate.transfer( recipient.address, amountToTransfer, - await provider.getBaseAssetId(), + baseAssetId, { gasLimit: 1000, } @@ -42,9 +38,7 @@ const tx2 = await predicate.transfer( await tx2.waitForResult(); // #endregion full -const destinationBalance = await recipient.getBalance( - await provider.getBaseAssetId() -); +const destinationBalance = await recipient.getBalance(baseAssetId); console.log( 'Destination balance should equal amount to transfer', diff --git a/apps/docs/src/guide/predicates/snippets/configurables/configurable-set-data.ts b/apps/docs/src/guide/predicates/snippets/configurables/configurable-set-data.ts index c7fd2c2e598..68194dff320 100644 --- a/apps/docs/src/guide/predicates/snippets/configurables/configurable-set-data.ts +++ b/apps/docs/src/guide/predicates/snippets/configurables/configurable-set-data.ts @@ -9,6 +9,7 @@ import { import { WhitelistedAddressPredicate } from '../../../../typegend/predicates/WhitelistedAddressPredicate'; const provider = new Provider(LOCAL_NETWORK_URL); +const baseAssetId = await provider.getBaseAssetId(); const whitelisted = Wallet.fromAddress(WALLET_ADDRESS, provider); const sender = Wallet.fromPrivateKey(WALLET_PVT_KEY_2, provider); @@ -24,14 +25,9 @@ const predicate = new WhitelistedAddressPredicate({ }); // Transferring funds to the predicate -const tx1 = await sender.transfer( - predicate.address, - 200_000, - await provider.getBaseAssetId(), - { - gasLimit: 1000, - } -); +const tx1 = await sender.transfer(predicate.address, 200_000, baseAssetId, { + gasLimit: 1000, +}); await tx1.waitForResult(); @@ -41,7 +37,7 @@ const amountToTransfer = 100; const tx2 = await predicate.transfer( recipient.address, amountToTransfer, - await provider.getBaseAssetId(), + baseAssetId, { gasLimit: 1000, } @@ -50,9 +46,7 @@ const tx2 = await predicate.transfer( await tx2.waitForResult(); // #endregion full -const destinationBalance = await recipient.getBalance( - await provider.getBaseAssetId() -); +const destinationBalance = await recipient.getBalance(baseAssetId); console.log( 'Destination balance should equal amount to transfer', diff --git a/apps/docs/src/guide/predicates/snippets/cookbook/failure-returns-false.ts b/apps/docs/src/guide/predicates/snippets/cookbook/failure-returns-false.ts index f193dc277e0..a0bacf5b7b2 100644 --- a/apps/docs/src/guide/predicates/snippets/cookbook/failure-returns-false.ts +++ b/apps/docs/src/guide/predicates/snippets/cookbook/failure-returns-false.ts @@ -5,6 +5,8 @@ import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { SimplePredicate } from '../../../../typegend'; const provider = new Provider(LOCAL_NETWORK_URL); +const baseAssetId = await provider.getBaseAssetId(); + const sender = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const receiver = Wallet.generate({ provider }); @@ -18,7 +20,7 @@ const amountToPredicate = 10_000_000; const tx = await sender.transfer( predicate.address, amountToPredicate, - await provider.getBaseAssetId(), + baseAssetId, { gasLimit: 1_000, } @@ -28,11 +30,7 @@ console.log('Transfer to predicate should be successful', isStatusSuccess); const amountOfCoins = 100; const { error } = await safeExec(async () => - predicate.transfer( - receiver.address, - amountOfCoins, - await provider.getBaseAssetId() - ) + predicate.transfer(receiver.address, amountOfCoins, baseAssetId) ); // #region send-and-spend-funds-from-predicates-7 diff --git a/apps/docs/src/guide/predicates/snippets/cookbook/pre-stage.ts b/apps/docs/src/guide/predicates/snippets/cookbook/pre-stage.ts index e3a5a178754..a296ace9362 100644 --- a/apps/docs/src/guide/predicates/snippets/cookbook/pre-stage.ts +++ b/apps/docs/src/guide/predicates/snippets/cookbook/pre-stage.ts @@ -4,6 +4,8 @@ import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { SimplePredicate } from '../../../../typegend'; const provider = new Provider(LOCAL_NETWORK_URL); +const baseAssetId = await provider.getBaseAssetId(); + const sender = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const receiver = Wallet.generate({ provider }); @@ -19,7 +21,7 @@ const amountToPredicate = 10_000_000; const tx = await sender.transfer( predicate.address, amountToPredicate, - await provider.getBaseAssetId(), + baseAssetId, { gasLimit: 1_000, } @@ -34,7 +36,7 @@ const amountToReceiver = 200; const transactionRequest = await predicate.createTransfer( receiver.address, amountToReceiver, - await provider.getBaseAssetId(), + baseAssetId, { gasLimit: 1000, } diff --git a/apps/docs/src/guide/predicates/snippets/cookbook/transferring-assets.ts b/apps/docs/src/guide/predicates/snippets/cookbook/transferring-assets.ts index 389bf320bc3..f8cba9c00f5 100644 --- a/apps/docs/src/guide/predicates/snippets/cookbook/transferring-assets.ts +++ b/apps/docs/src/guide/predicates/snippets/cookbook/transferring-assets.ts @@ -5,6 +5,8 @@ import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { SimplePredicate } from '../../../../typegend'; const provider = new Provider(LOCAL_NETWORK_URL); +const baseAssetId = await provider.getBaseAssetId(); + const sender = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const receiver = Wallet.generate({ provider }); @@ -26,7 +28,7 @@ const amountToPredicate = 10_000_000; const fundPredicateTx = await sender.transfer( predicate.address, amountToPredicate, - await provider.getBaseAssetId(), + await baseAssetId, { gasLimit: 1000, } @@ -49,7 +51,7 @@ const amountToReceiver = 200; const transferFromPredicateTx = await predicate.transfer( receiver.address, amountToReceiver, - await provider.getBaseAssetId() + await baseAssetId ); // Wait for the transaction diff --git a/apps/docs/src/guide/predicates/snippets/methods/create-transfer.ts b/apps/docs/src/guide/predicates/snippets/methods/create-transfer.ts index 1a36968e604..8e8ee8fa88b 100644 --- a/apps/docs/src/guide/predicates/snippets/methods/create-transfer.ts +++ b/apps/docs/src/guide/predicates/snippets/methods/create-transfer.ts @@ -5,6 +5,8 @@ import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { ReturnTruePredicate } from '../../../../typegend'; const provider = new Provider(LOCAL_NETWORK_URL); +const baseAssetId = await provider.getBaseAssetId(); + const funder = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const predicate = new ReturnTruePredicate({ @@ -15,7 +17,7 @@ const predicate = new ReturnTruePredicate({ const fundPredicate = await funder.transfer( predicate.address, 100_000_000, - await provider.getBaseAssetId() + baseAssetId ); await fundPredicate.waitForResult(); @@ -25,7 +27,7 @@ const amountToReceiver = 1000; const transactionRequest = await predicate.createTransfer( receiver.address, amountToReceiver, - await provider.getBaseAssetId(), + baseAssetId, { gasLimit: 1000, } diff --git a/apps/docs/src/guide/predicates/snippets/methods/transfer.ts b/apps/docs/src/guide/predicates/snippets/methods/transfer.ts index 9adfff36def..e45860ac457 100644 --- a/apps/docs/src/guide/predicates/snippets/methods/transfer.ts +++ b/apps/docs/src/guide/predicates/snippets/methods/transfer.ts @@ -5,6 +5,8 @@ import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; import { ReturnTruePredicate } from '../../../../typegend'; const provider = new Provider(LOCAL_NETWORK_URL); +const baseAssetId = await provider.getBaseAssetId(); + const funder = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const predicate = new ReturnTruePredicate({ @@ -14,7 +16,7 @@ const predicate = new ReturnTruePredicate({ const fundPredicate = await funder.transfer( predicate.address, 100_000_000, - await provider.getBaseAssetId() + baseAssetId ); await fundPredicate.waitForResult(); @@ -24,7 +26,7 @@ const amountToReceiver = 1000; const transferPredicateCoins = await predicate.transfer( receiver.address, amountToReceiver, - await provider.getBaseAssetId(), + baseAssetId, { gasLimit: 1000, } diff --git a/apps/docs/src/guide/wallets/snippets/transfers/batch-transfer.ts b/apps/docs/src/guide/wallets/snippets/transfers/batch-transfer.ts index 4a1be23ee5e..579bb48706f 100644 --- a/apps/docs/src/guide/wallets/snippets/transfers/batch-transfer.ts +++ b/apps/docs/src/guide/wallets/snippets/transfers/batch-transfer.ts @@ -5,6 +5,8 @@ import { Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env'; const provider = new Provider(LOCAL_NETWORK_URL); +const baseAssetId = await provider.getBaseAssetId(); + const sender = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const recipient1 = Wallet.generate({ provider }); @@ -15,18 +17,18 @@ const someOtherAssetId = const transfersToMake: TransferParams[] = [ { amount: 100, + assetId: baseAssetId, destination: recipient1.address, - assetId: await provider.getBaseAssetId(), }, { amount: 200, + assetId: baseAssetId, destination: recipient2.address, - assetId: await provider.getBaseAssetId(), }, { amount: 300, - destination: recipient2.address, assetId: someOtherAssetId, + destination: recipient2.address, }, ]; diff --git a/apps/docs/src/guide/wallets/snippets/wallet-transferring/create-transfer-2.ts b/apps/docs/src/guide/wallets/snippets/wallet-transferring/create-transfer-2.ts index 1fb79b2a19a..53f2787e793 100644 --- a/apps/docs/src/guide/wallets/snippets/wallet-transferring/create-transfer-2.ts +++ b/apps/docs/src/guide/wallets/snippets/wallet-transferring/create-transfer-2.ts @@ -12,12 +12,12 @@ const sender = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const destination = Wallet.fromPrivateKey(WALLET_PVT_KEY_2, provider); const amountToTransfer = 200; -const assetId = await provider.getBaseAssetId(); +const baseAssetId = await provider.getBaseAssetId(); const transactionRequest = await sender.createTransfer( destination.address, amountToTransfer, - assetId + baseAssetId ); const chainId = await provider.getChainId(); diff --git a/apps/docs/src/guide/wallets/snippets/wallet-transferring/create-transfer.ts b/apps/docs/src/guide/wallets/snippets/wallet-transferring/create-transfer.ts index e6c12889ed1..b67a5c3c158 100644 --- a/apps/docs/src/guide/wallets/snippets/wallet-transferring/create-transfer.ts +++ b/apps/docs/src/guide/wallets/snippets/wallet-transferring/create-transfer.ts @@ -12,12 +12,12 @@ const sender = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); const destination = Wallet.fromPrivateKey(WALLET_PVT_KEY_2, provider); const amountToTransfer = 200; -const assetId = await provider.getBaseAssetId(); +const baseAssetId = await provider.getBaseAssetId(); const transactionRequest = await sender.createTransfer( destination.address, amountToTransfer, - assetId + baseAssetId ); const chainId = await provider.getChainId(); From daf858b98d8ce24fe297a4d851c29908437b0b68 Mon Sep 17 00:00:00 2001 From: Anderson Arboleya Date: Wed, 1 Jan 2025 06:40:35 -0300 Subject: [PATCH 06/29] Adding changeset --- .changeset/old-laws-film.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .changeset/old-laws-film.md diff --git a/.changeset/old-laws-film.md b/.changeset/old-laws-film.md new file mode 100644 index 00000000000..4d4a81cbe3e --- /dev/null +++ b/.changeset/old-laws-film.md @@ -0,0 +1,10 @@ +--- +"@fuel-ts/contract": patch +"@fuel-ts/account": patch +"@fuel-ts/program": patch +"@fuel-ts/recipes": patch +"@fuel-ts/script": patch +"fuels": patch +--- + +feat: make `provider` initialization `sync` again From 6c7a394c0057078a1753becc3e0844df90a178fd Mon Sep 17 00:00:00 2001 From: Anderson Arboleya Date: Wed, 1 Jan 2025 07:03:12 -0300 Subject: [PATCH 07/29] Removing test exclusivity --- packages/fuel-gauge/src/contract.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/fuel-gauge/src/contract.test.ts b/packages/fuel-gauge/src/contract.test.ts index 419a7ed00cd..1f7d38cc9a0 100644 --- a/packages/fuel-gauge/src/contract.test.ts +++ b/packages/fuel-gauge/src/contract.test.ts @@ -65,7 +65,7 @@ describe('Contract', () => { expect(contract.provider).toEqual(provider); }); - it.only('should executes a contract call just nice', async () => { + it('should executes a contract call just fine', async () => { using contract = await setupTestContract(); const numberToSend = 1336; From c689561149c4dd8d98264863e1ad371d920e8263 Mon Sep 17 00:00:00 2001 From: Anderson Arboleya Date: Wed, 1 Jan 2025 07:38:50 -0300 Subject: [PATCH 08/29] Fixing test assertion --- packages/fuel-gauge/src/e2e-script.test.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/fuel-gauge/src/e2e-script.test.ts b/packages/fuel-gauge/src/e2e-script.test.ts index aabbe7a76c9..aba126d22fd 100644 --- a/packages/fuel-gauge/src/e2e-script.test.ts +++ b/packages/fuel-gauge/src/e2e-script.test.ts @@ -168,7 +168,7 @@ describe.each(selectedNetworks)('Live Script Test', (selectedNetwork) => { }); }); - it(`should have correct assets`, () => { + it(`should have correct assets`, async () => { if (shouldSkip) { return; } @@ -224,8 +224,9 @@ describe.each(selectedNetworks)('Live Script Test', (selectedNetwork) => { ]; const totalAssets = 27; + const chainId = await provider.getChainId(); - expect(CHAIN_IDS.fuel[selectedNetwork]).toEqual(provider.getChainId()); + expect(CHAIN_IDS.fuel[selectedNetwork]).toEqual(chainId); // Ensure contains base asset expect(rawAssets).containSubset(expectedRawBaseAsset); From 2fdc3920aa28d709d00e445f61cfbe7c57ed173e Mon Sep 17 00:00:00 2001 From: Anderson Arboleya Date: Wed, 1 Jan 2025 09:48:02 -0300 Subject: [PATCH 09/29] Update apps/docs/src/guide/predicates/snippets/cookbook/transferring-assets.ts Co-authored-by: Peter Smith --- .../guide/predicates/snippets/cookbook/transferring-assets.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/docs/src/guide/predicates/snippets/cookbook/transferring-assets.ts b/apps/docs/src/guide/predicates/snippets/cookbook/transferring-assets.ts index f8cba9c00f5..a8b83dffb64 100644 --- a/apps/docs/src/guide/predicates/snippets/cookbook/transferring-assets.ts +++ b/apps/docs/src/guide/predicates/snippets/cookbook/transferring-assets.ts @@ -28,7 +28,7 @@ const amountToPredicate = 10_000_000; const fundPredicateTx = await sender.transfer( predicate.address, amountToPredicate, - await baseAssetId, + baseAssetId, { gasLimit: 1000, } From 72ddab16a99b3ef2f9428880ca8f556ce8997674 Mon Sep 17 00:00:00 2001 From: Anderson Arboleya Date: Wed, 1 Jan 2025 09:48:38 -0300 Subject: [PATCH 10/29] Update apps/docs/src/guide/transactions/snippets/transaction.ts Co-authored-by: Peter Smith --- apps/docs/src/guide/transactions/snippets/transaction.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/docs/src/guide/transactions/snippets/transaction.ts b/apps/docs/src/guide/transactions/snippets/transaction.ts index 683556a2b45..1a429f759c0 100644 --- a/apps/docs/src/guide/transactions/snippets/transaction.ts +++ b/apps/docs/src/guide/transactions/snippets/transaction.ts @@ -15,7 +15,7 @@ const receiver = Wallet.fromPrivateKey(WALLET_PVT_KEY_2, provider); const tx = await sender.transfer(receiver.address, 100, assetId); await tx.waitForResult(); -const newBalance = await receiver.getBalance(await provider.getBaseAssetId()); +const newBalance = await receiver.getBalance(assetId); // 100 // #endregion transactions-1 console.log('balance', newBalance.toNumber()); From 073f864a5e83908cf00534b0266afb263e45147d Mon Sep 17 00:00:00 2001 From: Anderson Arboleya Date: Wed, 1 Jan 2025 09:48:51 -0300 Subject: [PATCH 11/29] Update apps/docs/src/guide/predicates/snippets/cookbook/transferring-assets.ts Co-authored-by: Peter Smith --- .../guide/predicates/snippets/cookbook/transferring-assets.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/docs/src/guide/predicates/snippets/cookbook/transferring-assets.ts b/apps/docs/src/guide/predicates/snippets/cookbook/transferring-assets.ts index a8b83dffb64..398185453d2 100644 --- a/apps/docs/src/guide/predicates/snippets/cookbook/transferring-assets.ts +++ b/apps/docs/src/guide/predicates/snippets/cookbook/transferring-assets.ts @@ -51,7 +51,7 @@ const amountToReceiver = 200; const transferFromPredicateTx = await predicate.transfer( receiver.address, amountToReceiver, - await baseAssetId + baseAssetId ); // Wait for the transaction From bdbb1a99be4b7207f0ec3099a48346882e53ce3e Mon Sep 17 00:00:00 2001 From: Anderson Arboleya Date: Wed, 1 Jan 2025 09:49:08 -0300 Subject: [PATCH 12/29] Update packages/fuel-gauge/src/transaction-summary.test.ts Co-authored-by: Peter Smith --- packages/fuel-gauge/src/transaction-summary.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/fuel-gauge/src/transaction-summary.test.ts b/packages/fuel-gauge/src/transaction-summary.test.ts index fe40905b4cb..db46531e27e 100644 --- a/packages/fuel-gauge/src/transaction-summary.test.ts +++ b/packages/fuel-gauge/src/transaction-summary.test.ts @@ -835,7 +835,7 @@ describe('TransactionSummary', () => { recipients: [ { address: contract.id, - quantities: [{ amount, assetId: await provider.getBaseAssetId() }], + quantities: [{ amount, assetId: baseAssetId }], }, ], }); From b3f76a05d130575de77129e4be7a475b116e5c99 Mon Sep 17 00:00:00 2001 From: Anderson Arboleya Date: Wed, 1 Jan 2025 09:49:21 -0300 Subject: [PATCH 13/29] Update packages/fuel-gauge/src/transaction-summary.test.ts Co-authored-by: Peter Smith --- packages/fuel-gauge/src/transaction-summary.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/fuel-gauge/src/transaction-summary.test.ts b/packages/fuel-gauge/src/transaction-summary.test.ts index db46531e27e..6e0863aede2 100644 --- a/packages/fuel-gauge/src/transaction-summary.test.ts +++ b/packages/fuel-gauge/src/transaction-summary.test.ts @@ -868,7 +868,7 @@ describe('TransactionSummary', () => { expect(operations[0].to?.chain).toEqual(ChainName.ethereum); expect(operations[0].assetsSent).toHaveLength(1); expect(operations[0].assetsSent?.[0].amount).toEqual(bn(amountToWithdraw)); - expect(operations[0].assetsSent?.[0].assetId).toEqual(await provider.getBaseAssetId()); + expect(operations[0].assetsSent?.[0].assetId).toEqual(baseAssetId); }); it('Should return contract created operations', async () => { From 83cef548844b73a9f4bd14e9f867f1c01f91ce54 Mon Sep 17 00:00:00 2001 From: Anderson Arboleya Date: Wed, 1 Jan 2025 09:50:12 -0300 Subject: [PATCH 14/29] Update packages/account/src/account.ts Co-authored-by: Peter Smith --- packages/account/src/account.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/account/src/account.ts b/packages/account/src/account.ts index 3f48d1911c5..3f1ca13fb30 100644 --- a/packages/account/src/account.ts +++ b/packages/account/src/account.ts @@ -440,7 +440,7 @@ export class Account extends AbstractAccount { async transferToContract( contractId: string | AbstractAddress, amount: BigNumberish, - assetId: BytesLike, + assetId?: BytesLike, txParams: TxParamsType = {} ): Promise { return this.batchTransferToContracts([{ amount, assetId, contractId }], txParams); From 9ef9907bb6e425bac9c80714736313dde589754f Mon Sep 17 00:00:00 2001 From: Anderson Arboleya Date: Wed, 1 Jan 2025 09:50:24 -0300 Subject: [PATCH 15/29] Update packages/program/src/functions/base-invocation-scope.ts Co-authored-by: Peter Smith --- packages/program/src/functions/base-invocation-scope.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/program/src/functions/base-invocation-scope.ts b/packages/program/src/functions/base-invocation-scope.ts index 7e7ae1f0ebf..1f61c16ec0d 100644 --- a/packages/program/src/functions/base-invocation-scope.ts +++ b/packages/program/src/functions/base-invocation-scope.ts @@ -309,7 +309,6 @@ export class BaseInvocationScope { */ addTransfer(transferParams: TransferParams) { const { amount, destination, assetId } = transferParams; - // const baseAssetId = await this.getProvider().getBaseAssetId(); this.transactionRequest = this.transactionRequest.addCoinOutput( Address.fromAddressOrString(destination), amount, From c77301fa809d56d00d3571f962bbe7afcac04e9a Mon Sep 17 00:00:00 2001 From: Anderson Arboleya Date: Wed, 1 Jan 2025 09:50:36 -0300 Subject: [PATCH 16/29] Update .changeset/old-laws-film.md Co-authored-by: Peter Smith --- .changeset/old-laws-film.md | 1 + 1 file changed, 1 insertion(+) diff --git a/.changeset/old-laws-film.md b/.changeset/old-laws-film.md index 4d4a81cbe3e..ba6b7d9e529 100644 --- a/.changeset/old-laws-film.md +++ b/.changeset/old-laws-film.md @@ -5,6 +5,7 @@ "@fuel-ts/recipes": patch "@fuel-ts/script": patch "fuels": patch +"create-fuels": patch --- feat: make `provider` initialization `sync` again From 5d96eb6748e4210029bcbca0490172de81487e05 Mon Sep 17 00:00:00 2001 From: Anderson Arboleya Date: Wed, 1 Jan 2025 10:50:04 -0300 Subject: [PATCH 17/29] Fixing type --- packages/account/src/account.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/account/src/account.ts b/packages/account/src/account.ts index 3f1ca13fb30..3f48d1911c5 100644 --- a/packages/account/src/account.ts +++ b/packages/account/src/account.ts @@ -440,7 +440,7 @@ export class Account extends AbstractAccount { async transferToContract( contractId: string | AbstractAddress, amount: BigNumberish, - assetId?: BytesLike, + assetId: BytesLike, txParams: TxParamsType = {} ): Promise { return this.batchTransferToContracts([{ amount, assetId, contractId }], txParams); From a951687cc80a62ad7c0c76bc493ff72088f64cfb Mon Sep 17 00:00:00 2001 From: Anderson Arboleya Date: Wed, 1 Jan 2025 10:57:49 -0300 Subject: [PATCH 18/29] Removing obsolete test --- .../account/src/providers/provider.test.ts | 23 ------------------- 1 file changed, 23 deletions(-) diff --git a/packages/account/src/providers/provider.test.ts b/packages/account/src/providers/provider.test.ts index 9378e2d464a..cf20f316843 100644 --- a/packages/account/src/providers/provider.test.ts +++ b/packages/account/src/providers/provider.test.ts @@ -1140,29 +1140,6 @@ describe('Provider', () => { expect(gasConfig.maxGasPerTx).toBeDefined(); }); - it.skip('should throws when using getChain or getNode and without cached data', async () => { - using launched = await setupTestProviderAndWallets(); - const { provider } = launched; - - Provider.clearChainAndNodeCaches(); - - await expectToThrowFuelError( - async () => provider.getChain(), - new FuelError( - ErrorCode.CHAIN_INFO_CACHE_EMPTY, - 'Chain info cache is empty. Make sure you have called `Provider.create` to initialize the provider.' - ) - ); - - await expectToThrowFuelError( - () => provider.getNode(), - new FuelError( - ErrorCode.NODE_INFO_CACHE_EMPTY, - 'Node info cache is empty. Make sure you have called `Provider.create` to initialize the provider.' - ) - ); - }); - it('warns on difference between major client version and supported major version', async () => { const { FUEL_CORE } = versions; const [major, minor, patch] = FUEL_CORE.split('.'); From ca6f05fb24a933615d79f949e349185b30626511 Mon Sep 17 00:00:00 2001 From: Anderson Arboleya Date: Wed, 1 Jan 2025 11:49:06 -0300 Subject: [PATCH 19/29] Adding missing declaration --- packages/fuel-gauge/src/transaction-summary.test.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/fuel-gauge/src/transaction-summary.test.ts b/packages/fuel-gauge/src/transaction-summary.test.ts index 6e0863aede2..18cc6c09832 100644 --- a/packages/fuel-gauge/src/transaction-summary.test.ts +++ b/packages/fuel-gauge/src/transaction-summary.test.ts @@ -849,6 +849,8 @@ describe('TransactionSummary', () => { wallets: [sender], } = launched; + const baseAssetId = await provider.getBaseAssetId(); + const recipient = Address.fromB256( '0x00000000000000000000000047ba61eec8e5e65247d717ff236f504cf3b0a263' ); From cde60c38974834d1fa55e23dc21920e726d05405 Mon Sep 17 00:00:00 2001 From: Anderson Arboleya Date: Thu, 2 Jan 2025 06:46:26 -0300 Subject: [PATCH 20/29] Refactoring messy method --- packages/account/src/providers/provider.ts | 51 ++++++++++------------ 1 file changed, 22 insertions(+), 29 deletions(-) diff --git a/packages/account/src/providers/provider.ts b/packages/account/src/providers/provider.ts index 201c4dad7bf..4ee4d326178 100644 --- a/packages/account/src/providers/provider.ts +++ b/packages/account/src/providers/provider.ts @@ -605,43 +605,36 @@ export default class Provider { * @returns A promise that resolves to the Chain and NodeInfo. */ async fetchChainAndNodeInfo(ignoreCache: boolean = false) { - let nodeInfo: NodeInfo; - let chain: ChainInfo; + let nodeInfo = Provider.nodeInfoCache[this.urlWithoutAuth]; + let chain = Provider.chainInfoCache[this.urlWithoutAuth]; - try { - nodeInfo = Provider.nodeInfoCache[this.urlWithoutAuth]; - chain = Provider.chainInfoCache[this.urlWithoutAuth]; + // if we have cache, return it + const cashIsPresent = !nodeInfo || !chain; + if (!ignoreCache && cashIsPresent) { + return { nodeInfo, chain }; + } - const noCache = !nodeInfo || !chain; + // otherwise, fetch data, save to cache, and return it + const data = await this.operations.getChainAndNodeInfo(); - if (ignoreCache || noCache) { - throw new Error(`Jumps to the catch block and re-fetch`); - } - } catch (_err) { - const data = await this.operations.getChainAndNodeInfo(); - - nodeInfo = { - maxDepth: bn(data.nodeInfo.maxDepth), - maxTx: bn(data.nodeInfo.maxTx), - nodeVersion: data.nodeInfo.nodeVersion, - utxoValidation: data.nodeInfo.utxoValidation, - vmBacktrace: data.nodeInfo.vmBacktrace, - }; + nodeInfo = { + maxDepth: bn(data.nodeInfo.maxDepth), + maxTx: bn(data.nodeInfo.maxTx), + nodeVersion: data.nodeInfo.nodeVersion, + utxoValidation: data.nodeInfo.utxoValidation, + vmBacktrace: data.nodeInfo.vmBacktrace, + }; - Provider.ensureClientVersionIsSupported(nodeInfo); + chain = processGqlChain(data.chain); - chain = processGqlChain(data.chain); + Provider.chainInfoCache[this.urlWithoutAuth] = chain; + Provider.nodeInfoCache[this.urlWithoutAuth] = nodeInfo; - Provider.chainInfoCache[this.urlWithoutAuth] = chain; - Provider.nodeInfoCache[this.urlWithoutAuth] = nodeInfo; + this.consensusParametersTimestamp = Date.now(); - this.consensusParametersTimestamp = Date.now(); - } + Provider.ensureClientVersionIsSupported(nodeInfo); - return { - chain, - nodeInfo, - }; + return { chain, nodeInfo }; } /** From 878ad8f93cb41435c25c91966cfe628fc3b1e151 Mon Sep 17 00:00:00 2001 From: Anderson Arboleya Date: Thu, 2 Jan 2025 07:00:19 -0300 Subject: [PATCH 21/29] Update packages/account/src/providers/provider.ts --- packages/account/src/providers/provider.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/account/src/providers/provider.ts b/packages/account/src/providers/provider.ts index 4ee4d326178..4f599eccd9b 100644 --- a/packages/account/src/providers/provider.ts +++ b/packages/account/src/providers/provider.ts @@ -609,8 +609,8 @@ export default class Provider { let chain = Provider.chainInfoCache[this.urlWithoutAuth]; // if we have cache, return it - const cashIsPresent = !nodeInfo || !chain; - if (!ignoreCache && cashIsPresent) { + const cacheIsPresent = !nodeInfo || !chain; + if (!ignoreCache && cacheIsPresent) { return { nodeInfo, chain }; } From 4b12dfd6f0c755371747f885e2397999a050ecd6 Mon Sep 17 00:00:00 2001 From: Anderson Arboleya Date: Thu, 2 Jan 2025 07:16:27 -0300 Subject: [PATCH 22/29] Adjusting changeset - PR introduces breaking changes --- .changeset/old-laws-film.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/old-laws-film.md b/.changeset/old-laws-film.md index ba6b7d9e529..0467251dbd1 100644 --- a/.changeset/old-laws-film.md +++ b/.changeset/old-laws-film.md @@ -8,4 +8,4 @@ "create-fuels": patch --- -feat: make `provider` initialization `sync` again +feat!: make `provider` initialization `sync` again From e3aedae6bd2faae1f3ac096e3d40fd606ff552d8 Mon Sep 17 00:00:00 2001 From: Anderson Arboleya Date: Thu, 2 Jan 2025 07:31:43 -0300 Subject: [PATCH 23/29] Revert "Update packages/account/src/providers/provider.ts" This reverts commit 878ad8f93cb41435c25c91966cfe628fc3b1e151. --- packages/account/src/providers/provider.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/account/src/providers/provider.ts b/packages/account/src/providers/provider.ts index 4f599eccd9b..4ee4d326178 100644 --- a/packages/account/src/providers/provider.ts +++ b/packages/account/src/providers/provider.ts @@ -609,8 +609,8 @@ export default class Provider { let chain = Provider.chainInfoCache[this.urlWithoutAuth]; // if we have cache, return it - const cacheIsPresent = !nodeInfo || !chain; - if (!ignoreCache && cacheIsPresent) { + const cashIsPresent = !nodeInfo || !chain; + if (!ignoreCache && cashIsPresent) { return { nodeInfo, chain }; } From 3053a4960217f7c13238c5f2294d1226cadd8e5f Mon Sep 17 00:00:00 2001 From: Anderson Arboleya Date: Thu, 2 Jan 2025 07:31:46 -0300 Subject: [PATCH 24/29] Revert "Refactoring messy method" This reverts commit cde60c38974834d1fa55e23dc21920e726d05405. --- packages/account/src/providers/provider.ts | 51 ++++++++++++---------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/packages/account/src/providers/provider.ts b/packages/account/src/providers/provider.ts index 4ee4d326178..201c4dad7bf 100644 --- a/packages/account/src/providers/provider.ts +++ b/packages/account/src/providers/provider.ts @@ -605,36 +605,43 @@ export default class Provider { * @returns A promise that resolves to the Chain and NodeInfo. */ async fetchChainAndNodeInfo(ignoreCache: boolean = false) { - let nodeInfo = Provider.nodeInfoCache[this.urlWithoutAuth]; - let chain = Provider.chainInfoCache[this.urlWithoutAuth]; + let nodeInfo: NodeInfo; + let chain: ChainInfo; - // if we have cache, return it - const cashIsPresent = !nodeInfo || !chain; - if (!ignoreCache && cashIsPresent) { - return { nodeInfo, chain }; - } + try { + nodeInfo = Provider.nodeInfoCache[this.urlWithoutAuth]; + chain = Provider.chainInfoCache[this.urlWithoutAuth]; - // otherwise, fetch data, save to cache, and return it - const data = await this.operations.getChainAndNodeInfo(); + const noCache = !nodeInfo || !chain; - nodeInfo = { - maxDepth: bn(data.nodeInfo.maxDepth), - maxTx: bn(data.nodeInfo.maxTx), - nodeVersion: data.nodeInfo.nodeVersion, - utxoValidation: data.nodeInfo.utxoValidation, - vmBacktrace: data.nodeInfo.vmBacktrace, - }; + if (ignoreCache || noCache) { + throw new Error(`Jumps to the catch block and re-fetch`); + } + } catch (_err) { + const data = await this.operations.getChainAndNodeInfo(); + + nodeInfo = { + maxDepth: bn(data.nodeInfo.maxDepth), + maxTx: bn(data.nodeInfo.maxTx), + nodeVersion: data.nodeInfo.nodeVersion, + utxoValidation: data.nodeInfo.utxoValidation, + vmBacktrace: data.nodeInfo.vmBacktrace, + }; - chain = processGqlChain(data.chain); + Provider.ensureClientVersionIsSupported(nodeInfo); - Provider.chainInfoCache[this.urlWithoutAuth] = chain; - Provider.nodeInfoCache[this.urlWithoutAuth] = nodeInfo; + chain = processGqlChain(data.chain); - this.consensusParametersTimestamp = Date.now(); + Provider.chainInfoCache[this.urlWithoutAuth] = chain; + Provider.nodeInfoCache[this.urlWithoutAuth] = nodeInfo; - Provider.ensureClientVersionIsSupported(nodeInfo); + this.consensusParametersTimestamp = Date.now(); + } - return { chain, nodeInfo }; + return { + chain, + nodeInfo, + }; } /** From 706d6b4736b592922fd42a0bca919333b2d82d38 Mon Sep 17 00:00:00 2001 From: Anderson Arboleya Date: Thu, 2 Jan 2025 07:35:06 -0300 Subject: [PATCH 25/29] Fixing changeset, it's a minor bump now --- .changeset/old-laws-film.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.changeset/old-laws-film.md b/.changeset/old-laws-film.md index 0467251dbd1..3ac9f9e64c6 100644 --- a/.changeset/old-laws-film.md +++ b/.changeset/old-laws-film.md @@ -1,11 +1,11 @@ --- -"@fuel-ts/contract": patch -"@fuel-ts/account": patch -"@fuel-ts/program": patch -"@fuel-ts/recipes": patch -"@fuel-ts/script": patch -"fuels": patch -"create-fuels": patch +"@fuel-ts/contract": minor +"@fuel-ts/account": minor +"@fuel-ts/program": minor +"@fuel-ts/recipes": minor +"@fuel-ts/script": minor +"fuels": minor +"create-fuels": minor --- feat!: make `provider` initialization `sync` again From 0a71af8382eedf9d686397654e920790371ddd7a Mon Sep 17 00:00:00 2001 From: Anderson Arboleya Date: Thu, 2 Jan 2025 07:47:02 -0300 Subject: [PATCH 26/29] Update .changeset/old-laws-film.md --- .changeset/old-laws-film.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/old-laws-film.md b/.changeset/old-laws-film.md index 3ac9f9e64c6..e53b47c828f 100644 --- a/.changeset/old-laws-film.md +++ b/.changeset/old-laws-film.md @@ -8,4 +8,4 @@ "create-fuels": minor --- -feat!: make `provider` initialization `sync` again +feat!: making `provider` initialization `sync` again From 7c9770871ad83841fb6bf56910de45e9effce903 Mon Sep 17 00:00:00 2001 From: Anderson Arboleya Date: Thu, 2 Jan 2025 14:54:25 -0300 Subject: [PATCH 27/29] Fixing remaining problematic parts --- .../predicates/snippets/cookbook/failure-returns-false.ts | 2 +- packages/account/src/account.ts | 3 +-- .../fuel-gauge/src/predicate/utils/predicate/fundAccount.ts | 2 +- packages/program/src/functions/base-invocation-scope.ts | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/apps/docs/src/guide/predicates/snippets/cookbook/failure-returns-false.ts b/apps/docs/src/guide/predicates/snippets/cookbook/failure-returns-false.ts index a0bacf5b7b2..c0584da4803 100644 --- a/apps/docs/src/guide/predicates/snippets/cookbook/failure-returns-false.ts +++ b/apps/docs/src/guide/predicates/snippets/cookbook/failure-returns-false.ts @@ -29,7 +29,7 @@ const { isStatusSuccess } = await tx.waitForResult(); console.log('Transfer to predicate should be successful', isStatusSuccess); const amountOfCoins = 100; -const { error } = await safeExec(async () => +const { error } = await safeExec(() => predicate.transfer(receiver.address, amountOfCoins, baseAssetId) ); diff --git a/packages/account/src/account.ts b/packages/account/src/account.ts index 3f48d1911c5..546c5c00c3a 100644 --- a/packages/account/src/account.ts +++ b/packages/account/src/account.ts @@ -417,12 +417,11 @@ export class Account extends AbstractAccount { * @returns The updated script transaction request. */ addBatchTransfer(request: ScriptTransactionRequest, transferParams: TransferParams[]) { - const baseAssetId = this.provider.getBaseAssetId(); transferParams.forEach(({ destination, amount, assetId }) => { this.addTransfer(request, { destination, amount, - assetId: assetId ?? baseAssetId, + assetId, }); }); return request; diff --git a/packages/fuel-gauge/src/predicate/utils/predicate/fundAccount.ts b/packages/fuel-gauge/src/predicate/utils/predicate/fundAccount.ts index 26587ab0de7..17a98622210 100644 --- a/packages/fuel-gauge/src/predicate/utils/predicate/fundAccount.ts +++ b/packages/fuel-gauge/src/predicate/utils/predicate/fundAccount.ts @@ -7,7 +7,7 @@ export const fundAccount = async ( amount: BigNumberish, utxosAmount: number = 1 ): Promise => { - const baseAssetId = fundedAccount.provider.getBaseAssetId(); + const baseAssetId = await fundedAccount.provider.getBaseAssetId(); const request = new ScriptTransactionRequest(); for (let i = 0; i < utxosAmount; i++) { diff --git a/packages/program/src/functions/base-invocation-scope.ts b/packages/program/src/functions/base-invocation-scope.ts index 1f61c16ec0d..5a5bf4ccce9 100644 --- a/packages/program/src/functions/base-invocation-scope.ts +++ b/packages/program/src/functions/base-invocation-scope.ts @@ -337,7 +337,7 @@ export class BaseInvocationScope { } addSigners(signers: Account | Account[]) { - this.addSignersCallback = async (transactionRequest) => + this.addSignersCallback = (transactionRequest) => transactionRequest.addAccountWitnesses(signers); return this; From 36de628680626a10102eee4cea3616437cd5e3ab Mon Sep 17 00:00:00 2001 From: Anderson Arboleya Date: Thu, 2 Jan 2025 15:21:04 -0300 Subject: [PATCH 28/29] Fixing broken tests --- .../predicate/predicate-duplication.test.ts | 68 ++++++++----------- 1 file changed, 28 insertions(+), 40 deletions(-) diff --git a/packages/fuel-gauge/src/predicate/predicate-duplication.test.ts b/packages/fuel-gauge/src/predicate/predicate-duplication.test.ts index 54cec443091..07cd15a05d5 100644 --- a/packages/fuel-gauge/src/predicate/predicate-duplication.test.ts +++ b/packages/fuel-gauge/src/predicate/predicate-duplication.test.ts @@ -187,6 +187,8 @@ describe('Predicate.fromInstance', () => { wallets: [wallet], } = launched; + const baseAssetId = await provider.getBaseAssetId(); + const basePredicate = new PredicateWithConfigurable({ provider: wallet.provider, data: [defaultValues.FEE, defaultValues.ADDRESS], @@ -203,20 +205,15 @@ describe('Predicate.fromInstance', () => { provider: wallet.provider, }); - await assertBalance(destination, 0, provider.getBaseAssetId()); + await assertBalance(destination, 0, baseAssetId); - const tx = await predicate.transfer( - destination.address, - amountToTransfer, - provider.getBaseAssetId(), - { - gasLimit: 1000, - } - ); + const tx = await predicate.transfer(destination.address, amountToTransfer, baseAssetId, { + gasLimit: 1000, + }); await tx.waitForResult(); - await assertBalance(destination, amountToTransfer, provider.getBaseAssetId()); + await assertBalance(destination, amountToTransfer, baseAssetId); }); it('can transfer funds using duplicated predicate with different data and same configurable constants', async () => { @@ -227,6 +224,8 @@ describe('Predicate.fromInstance', () => { wallets: [wallet], } = launched; + const baseAssetId = await provider.getBaseAssetId(); + const basePredicate = new PredicateWithConfigurable({ provider: wallet.provider, data: [13, '0x48966232edb5997574be45f94c665aedb41a1663f5b0528e765f355086eebf96'], @@ -245,20 +244,15 @@ describe('Predicate.fromInstance', () => { provider: wallet.provider, }); - await assertBalance(destination, 0, provider.getBaseAssetId()); + await assertBalance(destination, 0, baseAssetId); - const tx = await predicate.transfer( - destination.address, - amountToTransfer, - provider.getBaseAssetId(), - { - gasLimit: 1000, - } - ); + const tx = await predicate.transfer(destination.address, amountToTransfer, baseAssetId, { + gasLimit: 1000, + }); await tx.waitForResult(); - await assertBalance(destination, amountToTransfer, provider.getBaseAssetId()); + await assertBalance(destination, amountToTransfer, baseAssetId); }); it('can transfer funds using duplicated predicate with same data and different configurable constants', async () => { @@ -269,6 +263,8 @@ describe('Predicate.fromInstance', () => { wallets: [wallet], } = launched; + const baseAssetId = await provider.getBaseAssetId(); + const basePredicate = new PredicateWithConfigurable({ provider: wallet.provider, data: [defaultValues.FEE, defaultValues.ADDRESS], @@ -288,20 +284,15 @@ describe('Predicate.fromInstance', () => { provider: wallet.provider, }); - await assertBalance(destination, 0, provider.getBaseAssetId()); + await assertBalance(destination, 0, baseAssetId); - const tx = await predicate.transfer( - destination.address, - amountToTransfer, - provider.getBaseAssetId(), - { - gasLimit: 1000, - } - ); + const tx = await predicate.transfer(destination.address, amountToTransfer, baseAssetId, { + gasLimit: 1000, + }); await tx.waitForResult(); - await assertBalance(destination, amountToTransfer, provider.getBaseAssetId()); + await assertBalance(destination, amountToTransfer, baseAssetId); }); it('can transfer funds using duplicated predicate with different data and configurable constants', async () => { @@ -312,6 +303,8 @@ describe('Predicate.fromInstance', () => { wallets: [wallet], } = launched; + const baseAssetId = await provider.getBaseAssetId(); + const basePredicate = new PredicateWithConfigurable({ provider: wallet.provider, data: [13, '0x48966232edb5997574be45f94c665aedb41a1663f5b0528e765f355086eebf96'], @@ -334,19 +327,14 @@ describe('Predicate.fromInstance', () => { provider: wallet.provider, }); - await assertBalance(destination, 0, provider.getBaseAssetId()); + await assertBalance(destination, 0, baseAssetId); - const tx = await predicate.transfer( - destination.address, - amountToTransfer, - provider.getBaseAssetId(), - { - gasLimit: 1000, - } - ); + const tx = await predicate.transfer(destination.address, amountToTransfer, baseAssetId, { + gasLimit: 1000, + }); await tx.waitForResult(); - await assertBalance(destination, amountToTransfer, provider.getBaseAssetId()); + await assertBalance(destination, amountToTransfer, baseAssetId); }); }); From 1cf6aa53d2afe16c727d91d7d6f38cc3deb95686 Mon Sep 17 00:00:00 2001 From: Peter Smith Date: Mon, 6 Jan 2025 13:24:43 +0000 Subject: [PATCH 29/29] chore: fixing broken test --- packages/fuel-gauge/src/funding-transaction.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/fuel-gauge/src/funding-transaction.test.ts b/packages/fuel-gauge/src/funding-transaction.test.ts index b5a61232df3..8d9d9329865 100644 --- a/packages/fuel-gauge/src/funding-transaction.test.ts +++ b/packages/fuel-gauge/src/funding-transaction.test.ts @@ -534,7 +534,7 @@ describe('Funding Transactions', () => { const request = new ScriptTransactionRequest().addCoinOutput( receiver.address, 1000, - provider.getBaseAssetId() + await provider.getBaseAssetId() ); expect(request.inputs.length).toBe(0);