FuelLabs / fuels-ts

Fuel Network Typescript SDK
https://docs.fuel.network/docs/fuels-ts/
Apache License 2.0
44.21k stars 1.34k forks source link

feat!: made `deployContract` a non-blocking call #2597

Closed Torres-ssf closed 2 months ago

Torres-ssf commented 3 months ago

Release notes

In this release, we:

Summary

This PR refactors the deployContract method to be non-blocking. As a result, the method no longer returns the contract instance directly. Instead, it returns an object containing the transactionId and a waitForResult function. This change improves the flexibility and control over contract deployment but introduces a breaking change that requires updates to existing implementations.

Breaking Changes

The deployContract method no longer returns the contract instance directly. Instead, it returns an object containing the transactionId , the contractId, and a waitForResult function.

// before
const factory = new ContractFactory(contractByteCode, contractAbi, wallet);

const contract = await factory.deployContract();

const { value } = await contract.functions.xyz().call();
// after
const factory = new ContractFactory(contractByteCode, contractAbi, wallet);

const { waitForResult, transactionId, contractId } = await factory.deployContract();

const { contract, transactionResult } = await waitForResult();

const { value } = await contract.functions.xyz().call();

Checklist

fuel-service-user commented 3 months ago

✨ A PR has been created under the rc-2597 tag on fuels-wallet repo. https://github.com/FuelLabs/fuels-wallet/pull/1393

Torres-ssf commented 3 months ago

Do you think it's worthwhile using Typegen consistently in our documentation - over using ContractFactory (example)?

(This can be a separate issue - just posing the question)

@petertonysmith94 Good question. Since both approaches are valid we should have examples for each one. But at the same time, I think that having 2 different approaches can be confusing for new users. What do you think?

danielbate commented 3 months ago

@petertonysmith94 @Torres-ssf just weighing in that I would love to see us favouring Typegen consistently for fuel-gauge and snippets as it's essential for browser testing, and for users sake. I've added it as a requirement to #1820. Then we could have contract factory having it's own doc snippet.

petertonysmith94 commented 3 months ago

@Torres-ssf I think we need to be consistent using one or the other, I'd favour typegen as it provides the best experience for end users.

As @danielbate said - I think a section on using a ContractFactory would be worthwhile, but I reckon it should be isolate document 😄

arboleya commented 3 months ago

@danielbate @petertonysmith94 I lost a bit of context here, but I'd say we should use the fuels CLI instead, which internally will use typegen anyway. This will close the cycle of dogfooding our stuff in our test suites as much as possible.

danielbate commented 3 months ago

I'd say we should use the fuels CLI instead, which internally will use typegen anyway

@arboleya agreed. Right now we are building with the fuels CLI, so like we do in a few places in fuel-gauge, I would like to see us utilising those factories rather than importing the ContractFactory.

github-actions[bot] commented 2 months ago

Coverage Report:

Lines Branches Functions Statements
79.66%(+0.04%) 71.4%(+0%) 77.33%(+0.05%) 79.75%(+0.04%)
Changed Files: | Ok | File (✨=New File) | Lines | Branches | Functions | Statements | | -- | --------------------------------------------------------------------------------------------------------------- | ----------------- | --------------- | ------------------- | ------------------ | | 🔴 | packages/account/src/providers/transaction-response/transaction-response.ts | 72.72%
(+0.5%) | 50%
(+0%) | 88.88%
(+1.38%) | 72.72%
(+0.5%) | | 🔴 | packages/contract/src/contract-factory.ts | 58.62%
(+7.6%) | 46.15%
(+0%) | 54.54%
(+17.04%) | 58.62%
(+7.6%) | | 🔴 | packages/contract/src/test-utils/launch-test-node.ts | 97.5%
(+0.14%) | 96.42%
(+0%) | 100%
(+0%) | 97.56%
(+0.13%) |