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!: made deployContract a non-blocking call #2597

Merged
merged 82 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
1649707
create helper getAccount
Torres-ssf Jun 24, 2024
7051478
create helper prepareDeploy
Torres-ssf Jun 24, 2024
80303b8
made deployContract use prepareDeploy
Torres-ssf Jun 24, 2024
5f6ffdd
implement method deployContractAsync
Torres-ssf Jun 24, 2024
188474f
add test case
Torres-ssf Jun 24, 2024
ea3fd88
improve docs
Torres-ssf Jun 24, 2024
f54f398
Merge branch 'master' into st/feat/make-deploy-contract-async
Torres-ssf Jun 24, 2024
5ea4cec
add changeset
Torres-ssf Jun 24, 2024
1ff12dd
Merge branch 'master' into st/feat/make-deploy-contract-async
Torres-ssf Jun 24, 2024
9fa3296
fix typo
Torres-ssf Jun 24, 2024
5d5a85d
Merge branch 'st/feat/make-deploy-contract-async' of github.com:FuelL…
Torres-ssf Jun 24, 2024
7eabf88
refact deployContract method
Torres-ssf Jun 24, 2024
c23e76e
adjust launch test node types
Torres-ssf Jun 24, 2024
db54c12
adjust test utilities
Torres-ssf Jun 24, 2024
7aecce8
adjust typegen template
Torres-ssf Jun 24, 2024
8ee880e
export type DeployContractResult
Torres-ssf Jun 24, 2024
c727f37
adjusting tests
Torres-ssf Jun 24, 2024
647f906
refact error message
Torres-ssf Jun 24, 2024
6eb8dcb
Merge branch 'master' into st/feat/make-deploy-contract-async
Torres-ssf Jun 24, 2024
7c800e1
update docs
Torres-ssf Jun 24, 2024
5626f9a
fix changeset
Torres-ssf Jun 24, 2024
84a9540
Merge branch 'master' into st/feat/make-deploy-contract-async
Torres-ssf Jun 24, 2024
f8fa58a
Merge branch 'master' into st/feat/make-deploy-contract-async
Torres-ssf Jun 25, 2024
972118c
Merge branch 'master' into st/feat/make-deploy-contract-async
maschad Jun 25, 2024
ffd8aa8
Merge branch 'master' into st/feat/make-deploy-contract-async
arboleya Jun 25, 2024
c41de19
improve doc paragraph
Torres-ssf Jun 26, 2024
0d8cb33
improve doc paragraph
Torres-ssf Jun 26, 2024
26c5dbe
improve doc paragraph
Torres-ssf Jun 26, 2024
f528fac
remove unused import within factory hbs template
Torres-ssf Jun 26, 2024
15968e7
Merge branch 'master' into st/feat/make-deploy-contract-async
Torres-ssf Jun 26, 2024
86508f9
Merge branch 'master' into st/feat/make-deploy-contract-async
Torres-ssf Jun 27, 2024
17b9832
Merge branch 'master' into st/feat/make-deploy-contract-async
Torres-ssf Jun 27, 2024
922ca4a
improve docs
Torres-ssf Jun 27, 2024
b313e3c
Merge branch 'master' into st/feat/make-deploy-contract-async
Torres-ssf Jun 28, 2024
b9c0ed9
Merge branch 'master' into st/feat/make-deploy-contract-async
Torres-ssf Jun 28, 2024
d2e0195
Merge branch 'master' into st/feat/make-deploy-contract-async
Torres-ssf Jun 29, 2024
f0b251d
Merge branch 'master' into st/feat/make-deploy-contract-async
Torres-ssf Jul 3, 2024
33c1a4d
rollback deployContract to its original state
Torres-ssf Jul 3, 2024
144d6db
update deployContract method on typegen template
Torres-ssf Jul 3, 2024
c376740
update deployContract call on test helpers
Torres-ssf Jul 3, 2024
c2e159d
implement method assembleResult on TransactionResponse class
Torres-ssf Jul 3, 2024
c0b06bb
implement method deployContractAsync at ContracFactory class
Torres-ssf Jul 3, 2024
c798c15
conform with type rename
Torres-ssf Jul 3, 2024
5f37384
add deployContractAsync to typegen template
Torres-ssf Jul 3, 2024
c075889
update templates
Torres-ssf Jul 3, 2024
cdf2bf5
update generic name
Torres-ssf Jul 3, 2024
ee68c1b
made tests conform with changes
Torres-ssf Jul 3, 2024
cb04016
Merge branch 'master' into st/feat/make-deploy-contract-async
Torres-ssf Jul 3, 2024
97a10df
fix template fixture
Torres-ssf Jul 3, 2024
4da846e
Merge branch 'st/feat/make-deploy-contract-async' of github.com:FuelL…
Torres-ssf Jul 3, 2024
dc4dfdc
fix templates
Torres-ssf Jul 3, 2024
0fbaee4
edit docs
Torres-ssf Jul 3, 2024
8910dd1
update changeset
Torres-ssf Jul 3, 2024
70baa22
undo change
Torres-ssf Jul 3, 2024
0b7d9b7
fix changeset
Torres-ssf Jul 3, 2024
7a6e74b
remove bang from changeset
Torres-ssf Jul 3, 2024
b12fb6a
Merge branch 'master' into st/feat/make-deploy-contract-async
Torres-ssf Jul 4, 2024
b27fd15
Merge branch 'master' into st/feat/make-deploy-contract-async
Torres-ssf Jul 4, 2024
4df096a
Merge branch 'master' into st/feat/make-deploy-contract-async
Torres-ssf Jul 5, 2024
3db7496
Merge branch 'master' into st/feat/make-deploy-contract-async
Torres-ssf Jul 5, 2024
7a1aef1
Merge branch 'master' into st/feat/make-deploy-contract-async
Torres-ssf Jul 5, 2024
b6d1af7
Merge branch 'master' into st/feat/make-deploy-contract-async
Torres-ssf Jul 5, 2024
94078b1
Merge branch 'master' into st/feat/make-deploy-contract-async
Torres-ssf Jul 5, 2024
54288a8
Update apps/docs-snippets/src/guide/contracts/deploying-contracts.tes…
Torres-ssf Jul 5, 2024
18c5f55
Merge branch 'master' into st/feat/make-deploy-contract-async
Torres-ssf Jul 5, 2024
59b3e17
Merge branch 'master' into st/feat/make-deploy-contract-async
Torres-ssf Jul 5, 2024
5e87a3d
Merge branch 'master' into st/feat/make-deploy-contract-async
danielbate Jul 8, 2024
851f4d1
Merge branch 'master' into st/feat/make-deploy-contract-async
Torres-ssf Jul 8, 2024
930976f
Merge branch 'master' into st/feat/make-deploy-contract-async
Torres-ssf Jul 8, 2024
98e62f7
made deployContract a non blocking call by default
Torres-ssf Jul 9, 2024
bc672f3
adjusting test utilities
Torres-ssf Jul 9, 2024
b5261fc
update deploy contract cli
Torres-ssf Jul 9, 2024
462f4c7
adjusting tests
Torres-ssf Jul 9, 2024
f70eba2
Merge branch 'master' into st/feat/make-deploy-contract-async
Torres-ssf Jul 9, 2024
fb590d7
fix changeset
Torres-ssf Jul 9, 2024
3ffed87
update doc
Torres-ssf Jul 9, 2024
2b44321
add contractId to deployContract response
Torres-ssf Jul 9, 2024
1e061f5
remove problematic assertion
Torres-ssf Jul 9, 2024
e4f1dc6
Merge branch 'master' into st/feat/make-deploy-contract-async
arboleya Jul 9, 2024
1a23a1f
Merge branch 'master' into st/feat/make-deploy-contract-async
Torres-ssf Jul 9, 2024
3557ab7
Merge branch 'master' into st/feat/make-deploy-contract-async
Torres-ssf Jul 10, 2024
ca21b22
fix docs
Torres-ssf Jul 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/tender-eyes-think.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@fuel-ts/abi-typegen": minor
"@fuel-ts/contract": minor
"@fuel-ts/account": minor
"fuels": minor
---

feat!: made `deployContract` a non-blocking call
4 changes: 2 additions & 2 deletions apps/create-fuels-counter-guide/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Button } from "@/components/Button";
import toast from "react-hot-toast";
import { useActiveWallet } from "@/hooks/useActiveWallet";
import useAsync from "react-use/lib/useAsync";
import { CURRENT_ENVIRONMENT } from '@/lib'
import { CURRENT_ENVIRONMENT } from '@/lib';

// #region deploying-dapp-to-testnet-frontend-contract-id
const contractId =
Expand All @@ -37,7 +37,7 @@ export default function Home() {
*/
useAsync(async () => {
if (hasContract && wallet) {
const testContract = TestContractAbi__factory.connect(contractId, wallet);
const { contract: testContract } = TestContractAbi__factory.connect(contractId, wallet);
setContract(testContract);
const { value } = await testContract.functions.get_count().get();
setCounter(value.toNumber());
Expand Down
17 changes: 11 additions & 6 deletions apps/demo-bun-fuels/src/bun.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { ContractFactory, Provider, toHex, Wallet, FUEL_NETWORK_URL } from 'fuels';
import { generateTestWallet , safeExec } from 'fuels/test-utils';
import { generateTestWallet, safeExec } from 'fuels/test-utils';

import { SampleAbi__factory } from './sway-programs-api';
import bytecode from './sway-programs-api/contracts/SampleAbi.hex';
Expand All @@ -28,7 +28,8 @@ describe('ExampleContract', () => {

// Deploy
const factory = new ContractFactory(bytecode, SampleAbi__factory.abi, wallet);
const contract = await factory.deployContract();
const { waitForResult } = await factory.deployContract();
const { contract } = await waitForResult();

// Call
const { value } = await contract.functions.return_input(1337).call();
Expand All @@ -47,7 +48,8 @@ describe('ExampleContract', () => {
const wallet = await generateTestWallet(provider, [[500_000, baseAssetId]]);

// Deploy
const contract = await SampleAbi__factory.deployContract(bytecode, wallet);
const { waitForResult } = await SampleAbi__factory.deployContract(bytecode, wallet);
const { contract } = await waitForResult();

// Call
const { value } = await contract.functions.return_input(1337).call();
Expand All @@ -62,7 +64,8 @@ describe('ExampleContract', () => {
const unfundedWallet = Wallet.generate({ provider });

const factory = new ContractFactory(bytecode, SampleAbi__factory.abi, fundedWallet);
const contract = await factory.deployContract();
const { waitForResult } = await factory.deployContract();
const { contract } = await waitForResult();
const contractInstance = SampleAbi__factory.connect(contract.id, unfundedWallet);

const { error } = await safeExec(() =>
Expand All @@ -78,7 +81,8 @@ describe('ExampleContract', () => {
const unfundedWallet = Wallet.generate({ provider });

const factory = new ContractFactory(bytecode, SampleAbi__factory.abi, fundedWallet);
const contract = await factory.deployContract();
const { waitForResult } = await factory.deployContract();
const { contract } = await waitForResult();
const contractInstance = SampleAbi__factory.connect(contract.id, unfundedWallet);

await expect(contractInstance.functions.return_input(1337).dryRun()).resolves.not.toThrow();
Expand All @@ -87,7 +91,8 @@ describe('ExampleContract', () => {
it('should demo how to use generated files just fine', async () => {
const provider = await Provider.create(FUEL_NETWORK_URL);
const wallet = await generateTestWallet(provider, [[500_000, baseAssetId]]);
const depoloyed = await SampleAbi__factory.deployContract(bytecode, wallet);
const { waitForResult } = await SampleAbi__factory.deployContract(bytecode, wallet);
const { contract: depoloyed } = await waitForResult();
const contractsIds = {
sample: depoloyed.id,
};
Expand Down
17 changes: 11 additions & 6 deletions apps/demo-fuels/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { ContractFactory, Provider, toHex, Wallet, FUEL_NETWORK_URL } from 'fuels';
import { generateTestWallet , safeExec } from 'fuels/test-utils';
import { generateTestWallet, safeExec } from 'fuels/test-utils';

import { SampleAbi__factory } from './sway-programs-api';
import bytecode from './sway-programs-api/contracts/SampleAbi.hex';
Expand All @@ -28,7 +28,8 @@ describe('ExampleContract', () => {

// Deploy
const factory = new ContractFactory(bytecode, SampleAbi__factory.abi, wallet);
const contract = await factory.deployContract();
const { waitForResult } = await factory.deployContract();
const { contract } = await waitForResult();

// Call
const { value } = await contract.functions.return_input(1337).call();
Expand All @@ -47,7 +48,8 @@ describe('ExampleContract', () => {
const wallet = await generateTestWallet(provider, [[500_000, baseAssetId]]);

// Deploy
const contract = await SampleAbi__factory.deployContract(bytecode, wallet);
const { waitForResult } = await SampleAbi__factory.deployContract(bytecode, wallet);
const { contract } = await waitForResult();

// Call
const { value } = await contract.functions.return_input(1337).call();
Expand All @@ -62,7 +64,8 @@ describe('ExampleContract', () => {
const unfundedWallet = Wallet.generate({ provider });

const factory = new ContractFactory(bytecode, SampleAbi__factory.abi, fundedWallet);
const contract = await factory.deployContract();
const { waitForResult } = await factory.deployContract();
const { contract } = await waitForResult();
const contractInstance = SampleAbi__factory.connect(contract.id, unfundedWallet);

const { error } = await safeExec(() =>
Expand All @@ -78,7 +81,8 @@ describe('ExampleContract', () => {
const unfundedWallet = Wallet.generate({ provider });

const factory = new ContractFactory(bytecode, SampleAbi__factory.abi, fundedWallet);
const contract = await factory.deployContract();
const { waitForResult } = await factory.deployContract();
const { contract } = await waitForResult();
const contractInstance = SampleAbi__factory.connect(contract.id, unfundedWallet);

await expect(contractInstance.functions.return_input(1337).dryRun()).resolves.not.toThrow();
Expand All @@ -87,7 +91,8 @@ describe('ExampleContract', () => {
it('should demo how to use generated files just fine', async () => {
const provider = await Provider.create(FUEL_NETWORK_URL);
const wallet = await generateTestWallet(provider, [[500_000, baseAssetId]]);
const depoloyed = await SampleAbi__factory.deployContract(bytecode, wallet);
const { waitForResult } = await SampleAbi__factory.deployContract(bytecode, wallet);
const { contract: depoloyed } = await waitForResult();
const contractsIds = {
sample: depoloyed.id,
};
Expand Down
17 changes: 11 additions & 6 deletions apps/demo-typegen/src/demo.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// #region Testing-in-ts-ts
import { ContractFactory, Provider, toHex, Wallet, FUEL_NETWORK_URL, Address } from 'fuels';
import { generateTestWallet , safeExec } from 'fuels/test-utils';
import { generateTestWallet, safeExec } from 'fuels/test-utils';

import storageSlots from '../contract/out/release/demo-contract-storage_slots.json';

Expand All @@ -27,9 +27,10 @@ describe('ExampleContract', () => {
// #region typegen-demo-contract-storage-slots
// #context import storageSlots from './contract/out/debug/demo-contract-storage_slots.json';

const contract = await DemoContractAbi__factory.deployContract(bytecode, wallet, {
const { waitForResult } = await DemoContractAbi__factory.deployContract(bytecode, wallet, {
storageSlots,
});
const { contract } = await waitForResult();
// #endregion typegen-demo-contract-storage-slots

expect(contract.id).toBeTruthy();
Expand All @@ -40,7 +41,8 @@ describe('ExampleContract', () => {

// Deploy
const factory = new ContractFactory(bytecode, DemoContractAbi__factory.abi, wallet);
const contract = await factory.deployContract();
const { waitForResult } = await factory.deployContract();
const { contract } = await waitForResult();
const contractId = contract.id;

// Call
Expand Down Expand Up @@ -68,7 +70,8 @@ describe('ExampleContract', () => {
// #context import bytecode from './types/DemoContractAbi.hex';

// Deploy
const contract = await DemoContractAbi__factory.deployContract(bytecode, wallet);
const { waitForResult } = await DemoContractAbi__factory.deployContract(bytecode, wallet);
const { contract } = await waitForResult();

// #endregion typegen-demo-contract-factory-deploy

Expand All @@ -87,7 +90,8 @@ it('should throw when simulating via contract factory with wallet with no resour
const unfundedWallet = Wallet.generate({ provider });

const factory = new ContractFactory(bytecode, DemoContractAbi__factory.abi, fundedWallet);
const contract = await factory.deployContract();
const { waitForResult } = await factory.deployContract();
const { contract } = await waitForResult();
const contractInstance = DemoContractAbi__factory.connect(contract.id, unfundedWallet);

const { error } = await safeExec(() => contractInstance.functions.return_input(1337).simulate());
Expand All @@ -101,7 +105,8 @@ it('should not throw when dry running via contract factory with wallet with no r
const unfundedWallet = Wallet.generate({ provider });

const factory = new ContractFactory(bytecode, DemoContractAbi__factory.abi, fundedWallet);
const contract = await factory.deployContract();
const { waitForResult } = await factory.deployContract();
const { contract } = await waitForResult();
const contractInstance = DemoContractAbi__factory.connect(contract.id, unfundedWallet);

await expect(contractInstance.functions.return_input(1337).dryRun()).resolves.not.toThrow();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ describe('configurable-constants', () => {

const factory = new ContractFactory(bin, abi, wallet);

const contract = await factory.deployContract({
const { waitForResult } = await factory.deployContract({
configurableConstants,
});

const { contract } = await waitForResult();
// #endregion configurable-constants-2

const { value } = await contract.functions.echo_configurables(true).simulate();
Expand All @@ -68,9 +70,11 @@ describe('configurable-constants', () => {

const factory = new ContractFactory(bin, abi, wallet);

const contract = await factory.deployContract({
const { waitForResult } = await factory.deployContract({
configurableConstants,
});

const { contract } = await waitForResult();
// #endregion configurable-constants-3

const { value } = await contract.functions.echo_configurables(false).simulate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,20 @@ describe(__filename, () => {
// #region contract-setup-3
const factory = new ContractFactory(byteCode, abi, wallet);

const contract = await factory.deployContract();
const { contractId, transactionId, waitForResult } = await factory.deployContract();
// #endregion contract-setup-3

// #region contract-setup-4
const { value } = await contract.functions.echo_u8(15).simulate();
const { contract, transactionResult } = await waitForResult();
// #endregion contract-setup-4

// #region contract-setup-5
const { value } = await contract.functions.echo_u8(15).call();
// #endregion contract-setup-5

expect(transactionId).toBeDefined();
expect(contractId).toBeDefined();
expect(transactionResult.isStatusSuccess).toBeTruthy();
expect(value).toBe(15);
// #endregion contract-setup-4
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,21 @@ describe(__filename, () => {
const tokenArtifacts = getDocsSnippetsForcProject(DocSnippetProjectsEnum.SIMPLE_TOKEN);
const depositorArtifacts = getDocsSnippetsForcProject(DocSnippetProjectsEnum.TOKEN_DEPOSITOR);

simpleToken = await new ContractFactory(
const { waitForResult } = await new ContractFactory(
tokenArtifacts.binHexlified,
tokenArtifacts.abiContents,
wallet
).deployContract();

tokenDepositor = await new ContractFactory(
({ contract: simpleToken } = await waitForResult());

const { waitForResult: waitForResult2 } = await new ContractFactory(
depositorArtifacts.binHexlified,
depositorArtifacts.abiContents,
wallet
).deployContract();

({ contract: tokenDepositor } = await waitForResult2());
});

it('should successfully make call to another contract', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ describe(__filename, () => {
beforeAll(async () => {
wallet = await getTestWallet();
const factory = new ContractFactory(bin, abi, wallet);
contract = await factory.deployContract();

const { waitForResult } = await factory.deployContract();
({ contract } = await waitForResult());
contractId = contract.id;
});

Expand Down
14 changes: 10 additions & 4 deletions apps/docs-snippets/src/guide/contracts/multicalls.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,17 @@ describe(__filename, () => {
wallet
);

echoContract = await factory1.deployContract();
counterContract = await factory2.deployContract({
let { waitForResult } = await factory1.deployContract();
({ contract: echoContract } = await waitForResult());

({ waitForResult } = await factory2.deployContract({
storageSlots: counterArtifacts.storageSlots,
});
contextContract = await factory3.deployContract();
}));

({ contract: counterContract } = await waitForResult());

({ waitForResult } = await factory3.deployContract());
({ contract: contextContract } = await waitForResult());
});

it('should successfully submit multiple calls from the same contract function', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ describe('Custom Transactions from Contract Calls', () => {
senderWallet = await getTestWallet();
receiverWallet = Wallet.generate({ provider: senderWallet.provider });
const factory = new ContractFactory(binHexlified, abiContents, senderWallet);
contract = await factory.deployContract({ storageSlots });
const { waitForResult } = await factory.deployContract({ storageSlots });
({ contract } = await waitForResult());
abi = abiContents;
baseAssetId = senderWallet.provider.getBaseAssetId();
contract = await factory.deployContract({ storageSlots });
});

it('creates a custom transaction from a contract call', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ describe(__filename, () => {
provider = sender.provider;
baseAssetId = provider.getBaseAssetId();
const factory = new ContractFactory(binHexlified, abiContents, sender);
liquidityPoolContract = await factory.deployContract({
const { waitForResult } = await factory.deployContract({
configurableConstants: { TOKEN: { bits: baseAssetId } },
});
({ contract: liquidityPoolContract } = await waitForResult());
});

it('deposit and withdraw cookbook guide', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ describe(__filename, () => {
);
provider = sender.provider;
const factory = new ContractFactory(binHexlified, abiContents, sender);
deployedContract = await factory.deployContract();
const { waitForResult } = await factory.deployContract();
({ contract: deployedContract } = await waitForResult());
});

it('should successfully transfer asset to another account', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ describe(__filename, () => {
];
wallet = await getTestWallet(seedQuantities);
const factory = new ContractFactory(contractBin, contractAbi, wallet);
contract = await factory.deployContract();
const { waitForResult } = await factory.deployContract();
({ contract } = await waitForResult());
});

it('transfer multiple assets to a contract', async () => {
Expand Down
5 changes: 4 additions & 1 deletion apps/docs-snippets/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ export const createAndDeployContractFromProject = async (

const contractFactory = new ContractFactory(binHexlified, abiContents, wallet);

return contractFactory.deployContract({
const { waitForResult } = await contractFactory.deployContract({
storageSlots,
});

const { contract } = await waitForResult();
return contract;
};

export const defaultTxParams = {
Expand Down
8 changes: 6 additions & 2 deletions apps/docs/src/guide/contracts/deploying-contracts.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,18 @@ Load the contract bytecode and JSON ABI, generated from the Sway source, into th

## 4. Deploying the Contract

Initialize a [`ContractFactory`](../../api/Contract/ContractFactory.md) with the bytecode, ABI, and wallet. Deploy the contract and use its methods.
To deploy the contract, instantiate the [`ContractFactory`](../../api/Contract/ContractFactory.md) with the bytecode, ABI, and wallet. Then, call the `deployContract` method. This call resolves as soon as the transaction to deploy the contract is submitted and returns three items: the `contractId`, the `transactionId` and a `waitForResult` function.

<<< @/../../docs-snippets/src/guide/contracts/deploying-contracts.test.ts#contract-setup-3{ts:line-numbers}

The `contract` instance will be returned only after calling `waitForResult` and waiting for it to resolve. To avoid blocking the rest of your code, you can attach this promise to a hook or listener that will use the contract only after it is fully deployed.

<<< @/../../docs-snippets/src/guide/contracts/deploying-contracts.test.ts#contract-setup-4{ts:line-numbers}

## 5. Executing a Contract Call

Now that the contract is deployed, you can interact with it. In the following steps, you'll learn how to execute contract calls.

<<< @/../../docs-snippets/src/guide/contracts/deploying-contracts.test.ts#contract-setup-4{ts:line-numbers}
<<< @/../../docs-snippets/src/guide/contracts/deploying-contracts.test.ts#contract-setup-5{ts:line-numbers}

For a more comprehensive TypeScript-backed Fuel usage, learn how to [generate types from ABI](../fuels-cli/generating-types.md)
Loading
Loading