Skip to content

Commit

Permalink
feat!: making provider initialization sync again (#3514)
Browse files Browse the repository at this point in the history
  • Loading branch information
arboleya authored Jan 6, 2025
1 parent 10612b2 commit 458b7cf
Show file tree
Hide file tree
Showing 211 changed files with 920 additions and 798 deletions.
11 changes: 11 additions & 0 deletions .changeset/old-laws-film.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"@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!: making `provider` initialization `sync` again
2 changes: 1 addition & 1 deletion apps/create-fuels-counter-guide/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const queryClient = new QueryClient();

const connectors = defaultConnectors({
devMode: true,
fuelProvider: Provider.create(providerUrl),
fuelProvider: new Provider(providerUrl),
});

const networks: Network[] = [{ url: providerUrl, chainId }];
Expand Down
4 changes: 2 additions & 2 deletions apps/demo-typegen/src/demo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions apps/docs/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module.exports = {
extends: ["../../.eslintrc.js"],
rules: {
"no-console": "off",
"no-new": "off",
"tsdoc/syntax": "off",
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -14,7 +14,7 @@ try {
await contract.functions
.return_context_amount()
.callParams({
forward: [10, provider.getBaseAssetId()],
forward: [10, await provider.getBaseAssetId()],
gasLimit: 1,
})
.call();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions apps/docs/src/guide/contracts/snippets/contract-balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ 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);
const { contract } = await waitForDeploy();

const amountToForward = 40;
const amountToTransfer = 10;
const baseAssetId = provider.getBaseAssetId();
const baseAssetId = await provider.getBaseAssetId();

const recipient = Wallet.generate({
provider,
Expand Down
10 changes: 6 additions & 4 deletions apps/docs/src/guide/contracts/snippets/cost-estimation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ 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 baseAssetId = await provider.getBaseAssetId();

const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider);

const deploy = await ReturnContextFactory.deploy(wallet);
Expand All @@ -13,7 +15,7 @@ const { contract } = await deploy.waitForResult();
const cost = await contract.functions
.return_context_amount()
.callParams({
forward: [100, provider.getBaseAssetId()],
forward: [100, baseAssetId],
})
.getTransactionCost();

Expand All @@ -23,10 +25,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, baseAssetId],
}),
contract.functions.return_context_amount().callParams({
forward: [300, provider.getBaseAssetId()],
forward: [300, baseAssetId],
}),
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Original file line number Diff line number Diff line change
Expand Up @@ -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 } =
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/src/guide/contracts/snippets/introduction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/src/guide/contracts/snippets/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/src/guide/contracts/snippets/methods/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/src/guide/contracts/snippets/methods/dry-run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/src/guide/contracts/snippets/methods/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/src/guide/contracts/snippets/methods/simulate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/src/guide/contracts/snippets/proxy-contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 },
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 458b7cf

Please sign in to comment.