Skip to content

Commit

Permalink
Merge branch 'master' into rc/salamander
Browse files Browse the repository at this point in the history
  • Loading branch information
arboleya committed Jan 23, 2024
2 parents 901ae9b + bb60c88 commit 1d27e03
Show file tree
Hide file tree
Showing 55 changed files with 536 additions and 317 deletions.
6 changes: 6 additions & 0 deletions .changeset/beige-actors-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@fuel-ts/forc": patch
"@fuel-ts/fuel-core": patch
---

Fixing installation from git branches
6 changes: 6 additions & 0 deletions .changeset/kind-toes-promise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@fuel-ts/forc": patch
"@fuel-ts/versions": patch
---

Upgrading forc to 0.49.1
2 changes: 2 additions & 0 deletions .changeset/silent-schools-accept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// #region custom-transactions-1
script;

use std::token::force_transfer_to_contract;
use std::asset::force_transfer_to_contract;

fn main(
contract_address: b256,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// #region contract-balance-2
contract;

use std::token::transfer_to_address;
use std::asset::transfer_to_address;

abi TransferToAddress {
#[payable]
Expand Down
7 changes: 6 additions & 1 deletion apps/docs/spell-check-custom-words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -288,4 +288,9 @@ cryptographically
Config
config
configs
WSL
WSL
WalletUnlocked
WalletLocked
AbstractAddress
ContractFactory
ScriptTransactionRequest
2 changes: 1 addition & 1 deletion apps/docs/src/glossary.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ A Provider is a Class that provides an abstraction for a connection to a Fuel no

## Wallet and signer

A `Wallet` is a Class with direct or indirect access to a private key. You can use a `Wallet` to sign messages and transactions to authorize the network to charge your account to perform operations. The terms wallet and signer in the SDK are often used interchangeably, but, technically, a `Signer` enables the signing of transactions and messages; the `Wallet` implements the `Signer` functionality.
A [`Wallet`](./api/Wallet/Wallet.md) is a Class with direct or indirect access to a private key. You can use a [`Wallet`](./api/Wallet/Wallet.md) to sign messages and transactions to authorize the network to charge your account to perform operations. The terms wallet and signer in the SDK are often used interchangeably, but, technically, a `Signer` enables the signing of transactions and messages; the [`Wallet`](./api/Wallet/Wallet.md) implements the `Signer` functionality.
10 changes: 5 additions & 5 deletions apps/docs/src/guide/addresses/conversion.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This guide demonstrates how to convert between address formats and Sway Standard

## From `Bech32` to `b256`

By instantiating an `Address`, we can validate a `Bech32` address and easily convert it to a `b256`:
By instantiating an [`Address`](../../api/Address/Address.md), we can validate a `Bech32` address and easily convert it to a `b256`:

<<< @/../../docs-snippets/src/guide/types/conversion.test.ts#conversion-5{ts:line-numbers}

Expand All @@ -14,7 +14,7 @@ Or, if you'd prefer to use utility functions directly for validation and convers

## From `b256` to `Bech32`

In a similar fashion, we have both class functions on the `Address` and utilities available for `b256` validation and conversion:
In a similar fashion, we have both class functions on the [`Address`](../../api/Address/Address.md) and utilities available for `b256` validation and conversion:

<<< @/../../docs-snippets/src/guide/types/conversion.test.ts#conversion-7{ts:line-numbers}

Expand All @@ -24,18 +24,18 @@ And by using the `isB256` and `toBech32` utilities:

## Converting a Contract ID

The Contract `id` property has the [`AbstractAddress`](../types/address#abstractaddress-class) type. Therefore, it can be converted using the `Address` class functions such as `toAddress` and `toB256`:
The Contract `id` property has the [`AbstractAddress`](../types/address#abstractaddress-class) type. Therefore, it can be converted using the [`Address`](../../api/Address/Address.md) class functions such as `toAddress` and `toB256`:

<<< @/../../docs-snippets/src/guide/types/conversion.test.ts#conversion-2{ts:line-numbers}

## Converting a Wallet Address

Similarly, the Wallet `address` property is also of type [`AbstractAddress`](../types/address#abstractaddress-class) and can therefore use the same `Address` class functions for conversion:
Similarly, the Wallet `address` property is also of type [`AbstractAddress`](../types/address#abstractaddress-class) and can therefore use the same [`Address`](../../api/Address/Address.md) class functions for conversion:

<<< @/../../docs-snippets/src/guide/types/conversion.test.ts#conversion-3{ts:line-numbers}

## Converting an Asset ID

[Asset IDs](../types/asset-id.md) are a wrapped [b256](../types/bits256.md) value. The following example shows how to create an `Address` from a `b256` type:
[Asset IDs](../types/asset-id.md) are a wrapped [b256](../types/bits256.md) value. The following example shows how to create an [`Address`](../../api/Address/Address.md) from a `b256` type:

<<< @/../../docs-snippets/src/guide/types/conversion.test.ts#conversion-4{ts:line-numbers}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Making Calls with Different Wallets or Providers

This guide demonstrates how to make contract calls using different wallets and providers by passing either an `Account` or a `Provider` to the contract on instantiation.
This guide demonstrates how to make contract calls using different wallets and providers by passing either an [`Account`](../../api/Wallet/Account.md) or a [`Provider`](../../api/Providers/Provider.md) to the contract on instantiation.

## Changing Wallets

Expand Down
4 changes: 2 additions & 2 deletions apps/docs/src/guide/contracts/contract-balance.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Contract Balance

When working with contracts, it's crucial to be aware of the available contract balance of an asset while paying for costly operations. This guide will explain the `getBalance` method in the `Contract` class, which allows you to check a contract's available balance.
When working with contracts, it's crucial to be aware of the available contract balance of an asset while paying for costly operations. This guide will explain the `getBalance` method in the [Contract](../../api/Program/Contract.md) class, which allows you to check a contract's available balance.

## The `getBalance` Method

The `Contract` class includes a method called `getBalance` that retrieves the available balance of a specific asset for a contract. This method is particularly useful for determining the remaining balance after sending assets to a contract and executing contract calls.
The [`Contract`](../../api/Program/Contract.md) class includes a method called `getBalance` that retrieves the available balance of a specific asset for a contract. This method is particularly useful for determining the remaining balance after sending assets to a contract and executing contract calls.

<<< @/../../../packages/program/src/contract.ts#contract-balance-1{ts:line-numbers}

Expand Down
2 changes: 1 addition & 1 deletion apps/docs/src/guide/contracts/cost-estimation.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Estimating Contract Call Cost

The `getTransactionCost` function provided by the `provider` allows you to estimate the cost of a specific contract call. The return type, `TransactionCost`, is an object containing relevant information for the estimation:
The `getTransactionCost` function provided by the [Provider](../../api/Providers/Provider.md) allows you to estimate the cost of a specific contract call. The return type, `TransactionCost`, is an object containing relevant information for the estimation:

<<< @/../../../packages/providers/src/provider.ts#cost-estimation-1{ts:line-numbers}

Expand Down
2 changes: 1 addition & 1 deletion apps/docs/src/guide/contracts/deploying-contracts.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Load the contract bytecode and JSON ABI, generated from the Sway source, into th

## 4. Deploying the Contract

Initialize a `ContractFactory` with the bytecode, ABI, and wallet. Deploy the contract and use its methods.
Initialize a [`ContractFactory`](../../api/Contract/ContractFactory.md) with the bytecode, ABI, and wallet. Deploy the contract and use its methods.

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

Expand Down
8 changes: 4 additions & 4 deletions apps/docs/src/guide/contracts/managing-deployed-contracts.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ To interact with a deployed contract using the SDK without redeploying it, you o

## Contract ID

The `contractId` property from the `Contract` class is of type `AbstractAddress`, an abstract class that is exclusively extended by the `Address` class.
The `contractId` property from the [`Contract`](../../api/Program/Contract.md) class is of type [`AbstractAddress`](../../api/Interfaces/AbstractAddress.md), an abstract class that is exclusively extended by the [`Address`](../../api/Address/Address.md) class.

The `Address` class wraps all methods from the `AbstractAddress` class and adds a single property: `bech32Address`. This property is a string encoded in [`Bech32`](../types/bech32.md) format, recognizable by the human-readable prefix `fuel` followed by the separator `1`.
The [`Address`](../../api/Address/Address.md) class wraps all methods from the [`AbstractAddress`](../../api/Interfaces/AbstractAddress.md) class and adds a single property: `bech32Address`. This property is a string encoded in [`Bech32`](../types/bech32.md) format, recognizable by the human-readable prefix `fuel` followed by the separator `1`.

When you log the `contractId` property of an instantiated Contract using `console.log`, the output appears as follows:

Expand All @@ -22,10 +22,10 @@ If you have already an instantiated and deployed contract in hands you can creat

<<< @/../../docs-snippets/src/guide/contracts/managing-deployed-contracts.test.ts#managing-deployed-contracts-1{ts:line-numbers}

The previous example assumes that you have a `Contract` instance at hand. However, some Fuel tools and Sway use the [`b256`](../types/bits256.md) type format, a hex-encoded string-like type, for contract IDs.
The previous example assumes that you have a [`Contract`](../../api/Program/Contract.md) instance at hand. However, some Fuel tools and Sway use the [`b256`](../types/bits256.md) type format, a hex-encoded string-like type, for contract IDs.

You might have this format instead, for example, if you have deployed your contract with `forc deploy`.

The process of instantiating a `Contract` remains the same when using a contract ID of type `b256`:
The process of instantiating a [`Contract`](../../api/Program/Contract.md) remains the same when using a contract ID of type `b256`:

<<< @/../../docs-snippets/src/guide/contracts/managing-deployed-contracts.test.ts#managing-deployed-contracts-2{ts:line-numbers}
4 changes: 2 additions & 2 deletions apps/docs/src/guide/cookbook/custom-transactions.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Custom Transactions

There may be scenarios where you need to build out transactions that involve multiple program types and assets; this can be done by instantiating a `ScriptTransactionRequest`. This class allows you to a append multiple program types and assets to a single transaction.
There may be scenarios where you need to build out transactions that involve multiple program types and assets; this can be done by instantiating a [`ScriptTransactionRequest`](../../api/Providers/ScriptTransactionRequest.md). This class allows you to a append multiple program types and assets to a single transaction.

Consider the following script that transfers multiple assets to a contract:

<<< @/../../docs-snippets/test/fixtures/forc-projects/script-transfer-to-contract/src/main.sw#custom-transactions-1{ts:line-numbers}

This script can be executed by creating a `ScriptTransactionRequest`, appending the resource and contract inputs/outputs and then sending the transaction, as follows:
This script can be executed by creating a [`ScriptTransactionRequest`](../../api/Providers/ScriptTransactionRequest.md), appending the resource and contract inputs/outputs and then sending the transaction, as follows:

<<< @/../../docs-snippets/src/guide/scripts/script-custom-transaction.test.ts#custom-transactions-2{ts:line-numbers}
2 changes: 1 addition & 1 deletion apps/docs/src/guide/predicates/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ After compiling, you will obtain the binary of the predicate and its JSON ABI (A

<<< @/../../docs-snippets/src/guide/predicates/index.test.ts#predicate-index-2{ts:line-numbers}

The created `Predicate` instance, among other things, has three important properties: the predicate `bytes` (byte code), the `chainId`, and the predicate `address`.
The created [`Predicate`](../../api/Predicate/Predicate.md) instance, among other things, has three important properties: the predicate `bytes` (byte code), the `chainId`, and the predicate `address`.

This address, generated from the byte code, corresponds to the Pay-to-Script-Hash (P2SH) address used in Bitcoin.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ With the predicate instantiated, we can transfer funds to its address. This requ

Now that our predicate holds funds, we can use it to validate a transaction.

First, we need to set its data. Note that the `main` function in our predicate example requires a parameter called `input_address` of type `b256`. We achieve this using the `Predicate` class method `setData`.
First, we need to set its data. Note that the `main` function in our predicate example requires a parameter called `input_address` of type `b256`. We achieve this using the [`Predicate`](../../api/Predicate/Predicate.md) class method `setData`.

<<< @/../../docs-snippets/src/guide/predicates/send-and-spend-funds-from-predicates.test.ts#send-and-spend-funds-from-predicates-4{ts:line-numbers}

Expand All @@ -40,7 +40,7 @@ Once the predicate resolves with a return value `true` based on its predefined c

---

In a similar approach, you can use the `createTransfer` method, which returns a `ScriptTransactionRequest`. Then, we can submit this transaction request by calling the `sendTransaction` method.
In a similar approach, you can use the `createTransfer` method, which returns a [`ScriptTransactionRequest`](../../api/Providers/ScriptTransactionRequest.md). Then, we can submit this transaction request by calling the `sendTransaction` method.

This can be useful if you need the transaction ID before actually submitting it to the node.

Expand Down
2 changes: 1 addition & 1 deletion apps/docs/src/guide/providers/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Providers

An instance of the `Provider` class lets you connect to a Fuel node. It provides read-only access to the blockchain state. You can use this provider as-is or through a `Wallet` instance.
An instance of the [`Provider`](../../api/Providers/Provider.md) class lets you connect to a Fuel node. It provides read-only access to the blockchain state. You can use this provider as-is or through a [`Wallet`](../../api/Wallet/Wallet.md) instance.

<<< @/../../../packages/providers/test/provider.test.ts#provider-definition{ts:line-numbers}
22 changes: 11 additions & 11 deletions apps/docs/src/guide/types/address.md
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
# Address

In Sway, the `Address` type serves as a type-safe wrapper around the primitive `b256` type. The SDK takes a different approach and has its own abstraction for the `Address` type.
In Sway, the [`Address`](../../api/Address/Address.md) type serves as a type-safe wrapper around the primitive `b256` type. The SDK takes a different approach and has its own abstraction for the [Address](../../api/Address/Address.md) type.

## `AbstractAddress` Class
## [`AbstractAddress`](../../api/Interfaces/AbstractAddress.md) Class

The SDK defines the `AbstractAddress` class, which provides a set of utility functions for easy manipulation and conversion between address formats.
The SDK defines the [AbstractAddress](../../api/Interfaces/AbstractAddress.md) class, which provides a set of utility functions for easy manipulation and conversion between address formats.

<<< @/../../../packages/interfaces/src/index.ts#address-1{ts:line-numbers}

## Address Class

Besides conforming to the interface of the `AbstractAddress`, the `Address` also defines one property; `bech32Address`, which is of the [`Bech32`](./bech32.md) type.
Besides conforming to the interface of the [`AbstractAddress`](../../api/Interfaces/AbstractAddress.md), the [`Address`](../../api/Address/Address.md) class also defines one property; `bech32Address`, which is of the [`Bech32`](./bech32.md) type.

<<< @/../../../packages/address/src/address.ts#address-2{ts:line-numbers}

## Creating an Address

Thanks to the utility functions provided by the `AbstractAddress` class, there are several ways to create an `Address` instance:
Thanks to the utility functions provided by the [`AbstractAddress`](../../api/Interfaces/AbstractAddress.md) class, there are several ways to create an [`Address`](../../api/Address/Address.md) instance:

### From a `Bech32` Address

To create an `Address` from a `Bech32` address, use the following code snippet:
To create an [`Address`](../../api/Address/Address.md) from a `Bech32` address, use the following code snippet:

<<< @/../../docs-snippets/src/guide/types/address.test.ts#address-2{ts:line-numbers}

### From a Public Key

To create an `Address` from a public key, use the following code snippet:
To create an [`Address`](../../api/Address/Address.md) from a public key, use the following code snippet:

<<< @/../../docs-snippets/src/guide/types/address.test.ts#address-3{ts:line-numbers}

### From a 256-bit Address

To create an `Address` from a 256-bit address, use the following code snippet:
To create an [`Address`](../../api/Address/Address.md) from a 256-bit address, use the following code snippet:

<<< @/../../docs-snippets/src/guide/types/address.test.ts#address-4{ts:line-numbers}

## Utility Functions

The `Address` class also provides some practical utility functions:
The [`Address`](../../api/Address/Address.md) class also provides some practical utility functions:

1. `fromString`: Create a new `Address` from an ambiguous source that may be a `Bech32` or `B256` address:
1. `fromString`: Create a new [`Address`](../../api/Address/Address.md) from an ambiguous source that may be a `Bech32` or `B256` address:

<<< @/../../docs-snippets/src/guide/types/address.test.ts#address-5{ts:line-numbers}

2. `fromDynamicInput`: Create a new `Address` when the address source is unknown:
2. `fromDynamicInput`: Create a new [`Address`](../../api/Address/Address.md) when the address source is unknown:

<<< @/../../docs-snippets/src/guide/types/address.test.ts#address-6{ts:line-numbers}

Expand Down
4 changes: 2 additions & 2 deletions apps/docs/src/guide/types/bech32.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# `Bech32`

The SDK uses the `Bech32` type as the core property of the `Address` class, specifically through the `bech32Address` property.
The SDK uses the `Bech32` type as the core property of the [`Address`](../../api/Address/Address.md) class, specifically through the `bech32Address` property.

Originally designed for Bitcoin, the `Bech32` format offers numerous advantages such as enhanced error detection, simplified integrations, and improved compatibility with future upgrades. Given these benefits, the `Address` class is constructed around the `Bech32` type.
Originally designed for Bitcoin, the `Bech32` format offers numerous advantages such as enhanced error detection, simplified integrations, and improved compatibility with future upgrades. Given these benefits, the [`Address`](../../api/Address/Address.md) class is constructed around the `Bech32` type.

You can read more about the `Bech32` type [here](https://thebitcoinmanual.com/articles/btc-bech32-address/).

Expand Down
2 changes: 1 addition & 1 deletion apps/docs/src/guide/types/bits256.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ To convert between a `b256` hexlified string and a `Uint8Array`, you can use the

## Support from `Address` Class

A `b256` value is also supported as part of the `Address` class, providing seamless integration with other components of your application. To create an `Address` instance from a b256 value, use the `Address.fromB256()` method:
A `b256` value is also supported as part of the [`Address`](../../api/Address/Address.md) class, providing seamless integration with other components of your application. To create an [`Address`](../../api/Address/Address.md) instance from a b256 value, use the `Address.fromB256()` method:

<<< @/../../docs-snippets/src/guide/types/bits256.test.ts#bits256-3{ts:line-numbers}
Loading

0 comments on commit 1d27e03

Please sign in to comment.