Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: making provider initialization sync again #3514

Open
wants to merge 33 commits into
base: master
Choose a base branch
from

Conversation

arboleya
Copy link
Member

@arboleya arboleya commented Jan 1, 2025

Release notes

In this release, we:

  • Made Provider constructor public and sync again

Summary

The first implementation got it backward, but now things are back in place:

  • Constructor is sync and public again
  • Methods that need remote data are async (like they should)

Oneliners help to show why async initialization isn't good — look at the awkward parenthesis we must use to isolate the call before other methods (the actual async ones) can be chained.

// before
(await Provider.create(NETWORK_URL)).getChainId();

// after
await new Provider(NETWORK_URL).getChainId();

Breaking Changes

1. Provider Instantiation

  • Going from async to sync
// before
const provider = await Provider.create(NETWORK_URL);
// after
const provider = new Provider(NETWORK_URL);

2. Provider methods

  • The following methods are now async
// before
provider.getNode();
provider.getChain();
provider.getChainId();
provider.getBaseAssetId();
provider.getGasConfig();
provider.validateTransaction();
// after
await provider.getNode();
await provider.getChain();
await provider.getChainId();
await provider.getBaseAssetId();
await provider.getGasConfig();
await provider.validateTransaction();

3. TransferParams and ContractTransferParams

export type TransferParams = {
  destination: string | AbstractAddress;
  amount: BigNumberish;
-  assetId?: BytesLike;
+  assetId: BytesLike;
};

export type ContractTransferParams = {
  contractId: string | AbstractAddress;
  amount: BigNumberish;
-  assetId?: BytesLike;
+  assetId: BytesLike;
};

4. Transaction Response

  • The constructor now requires a chainId
// before
new TransactionResponse('0x..', provider);
// after
new TransactionResponse('0x..', provider, chainId);

Checklist

  • All changes are covered by tests (or not applicable)
  • All changes are documented (or not applicable)
  • I reviewed the entire PR myself (preferably, on GH UI)
  • I described all Breaking Changes (or there's none)

@arboleya arboleya added the feat Issue is a feature label Jan 1, 2025
@arboleya arboleya self-assigned this Jan 1, 2025
Copy link

vercel bot commented Jan 1, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
fuels-template ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 2, 2025 6:59pm
ts-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 2, 2025 6:59pm
ts-docs-api ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 2, 2025 6:59pm

@arboleya arboleya marked this pull request as draft January 1, 2025 11:48
nedsalk
nedsalk previously approved these changes Jan 2, 2025
Copy link
Contributor

@nedsalk nedsalk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

Copy link
Contributor

github-actions bot commented Jan 2, 2025

Coverage Report:

Lines Branches Functions Statements
77.79%(+0.01%) 70.55%(+0.15%) 75.33%(-0.05%) 77.75%(+0.01%)
Changed Files:
Ok File (✨=New File) Lines Branches Functions Statements
🔴 packages/account/src/account.ts 78.23%
(-0.59%)
63.88%
(+0.37%)
80%
(+0%)
78.03%
(-0.58%)
🔴 packages/account/src/providers/provider.ts 68.55%
(-0.47%)
56.56%
(-0.58%)
70.21%
(-0.75%)
68.28%
(-0.45%)
🔴 packages/account/src/providers/transaction-response/transaction-response.ts 76.4%
(-0.87%)
65.45%
(+0%)
93.75%
(+0%)
76.4%
(-0.87%)
🔴 packages/create-fuels/src/lib/getPackageManager.ts 100%
(+0%)
88.88%
(+8.88%)
100%
(+0%)
100%
(+0%)
🔴 packages/fuels/src/cli/commands/deploy/createWallet.ts 92.3%
(+0.64%)
75%
(+0%)
100%
(+0%)
92.3%
(+0.64%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat Issue is a feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make Provider initialization sync again
4 participants