Skip to content

Commit

Permalink
chore: capitalize B
Browse files Browse the repository at this point in the history
  • Loading branch information
petertonysmith94 committed Jan 20, 2025
1 parent 8ddc8a6 commit 9c8b76a
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 23 deletions.
4 changes: 2 additions & 2 deletions apps/docs/src/guide/contracts/managing-deployed-contracts.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ If you have already an instantiated and deployed contract in hands you can creat

<<< @./snippets/managing-deployed-contracts.ts#with-contractId{ts:line-numbers}

The previous example assumes that you have a [`Contract`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_program.Contract.html) instance at hand. However, some Fuel tools and Sway use the [`b256`](../types/b256.md) type format, a hex-encoded string-like type, for contract IDs.
The previous example assumes that you have a [`Contract`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_program.Contract.html) instance at hand. However, some Fuel tools and Sway use the [`B256`](../types/b256.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`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_program.Contract.html) remains the same when using a contract ID of type `b256`:
The process of instantiating a [`Contract`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_program.Contract.html) remains the same when using a contract ID of type `B256`:

<<< @./snippets/managing-deployed-contracts.ts#with-b256{ts:line-numbers}
4 changes: 2 additions & 2 deletions apps/docs/src/guide/encoding/working-with-bytes.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ A fixed-length string's size is known at compile time due to the argument declar

<<< @./snippets/working-with-bytes.ts#working-with-bytes-3{ts:line-numbers}

### `b256` / `b512`
### `B256` / `B512`

These are fixed-length byte arrays, with `b256` containing 256 bits and `b512` containing 512 bits. You can use them for address and signature formats.
These are fixed-length byte arrays, with `B256` containing 256 bits and `B512` containing 512 bits. You can use them for address and signature formats.

<<< @./snippets/working-with-bytes.ts#working-with-bytes-4{ts:line-numbers}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ Consider the following predicate:

<<< @/../../docs/sway/simple-predicate/src/main.sw#send-and-spend-funds-from-predicates-1{rust:line-numbers}

This predicate accepts an address of type `b256` and compares it with a hard-coded address of the same type. If both addresses are equal, the predicate returns true, otherwise it will return false.
This predicate accepts an address of type `B256` and compares it with a hard-coded address of the same type. If both addresses are equal, the predicate returns true, otherwise it will return false.

## Interacting with the Predicate Using SDK

Let's use the above predicate to validate our transaction.

Once you've compiled the predicate (`forc build`), you'll obtain two important artifacts: the JSON ABI and the predicate's binary code. These are needed to instantiate a new predicate.

This is where we also pass in the predicate's data. Note that the `main` function in our predicate example requires a parameter called `input_address` of type `b256`. We will pass this parameter to the `Predicate` constructor along with the bytecode and the JSON ABI.
This is where we also pass in the predicate's data. Note that the `main` function in our predicate example requires a parameter called `input_address` of type `B256`. We will pass this parameter to the `Predicate` constructor along with the bytecode and the JSON ABI.

<<< @./snippets/cookbook/transferring-assets.ts#send-and-spend-funds-from-predicates-2{ts:line-numbers}

Expand Down
2 changes: 1 addition & 1 deletion apps/docs/src/guide/types/address.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Address

In Sway, the [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) 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](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) type.
In Sway, the [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) 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](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) type.

## Address Class

Expand Down
12 changes: 6 additions & 6 deletions apps/docs/src/guide/types/b256.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# `B256`

The type `b256` in Fuel represents hashes and holds a 256-bit (32-bytes) value. The TypeScript SDK represents `b256` as a hexlified string value for portability and provides utilities to convert to `Uint8Array` when the [raw bytes](./bytes32.md) are required.
The type `B256` in Fuel represents hashes and holds a 256-bit (32-bytes) value. The TypeScript SDK represents `B256` as a hexlified string value for portability and provides utilities to convert to `Uint8Array` when the [raw bytes](./bytes32.md) are required.

## Generating random `b256` values
## Generating random `B256` values

To generate a random `b256` value, you can use the `getRandomB256()` function:
To generate a random `B256` value, you can use the `getRandomB256()` function:

<<< @./snippets/b256/generating-random-b256.ts#full{ts:line-numbers}

### Converting between `b256` and `Uint8Array`
### Converting between `B256` and `Uint8Array`

To convert between a `b256` hexlified string and a `Uint8Array`, you can use the `arrayify` and `hexlify` functions:
To convert between a `B256` hexlified string and a `Uint8Array`, you can use the `arrayify` and `hexlify` functions:

<<< @./snippets/b256/converting-between-b256-uint8.ts#full{ts:line-numbers}

## Support from `Address` Class

A `b256` value is also supported as part of the [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) class, providing seamless integration with other components of your application. To create an [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) instance from a b256 value, use the `Address.fromB256()` method:
A `B256` value is also supported as part of the [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) class, providing seamless integration with other components of your application. To create an [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) instance from a b256 value, use the `Address.fromB256()` method:

<<< @./snippets/b256/support-from-address-class.ts#full{ts:line-numbers}
14 changes: 7 additions & 7 deletions apps/docs/src/guide/types/b512.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
# B512

In Sway, the `b512` type is commonly used to handle public keys and signatures. This guide will explain how the `b512` type is defined in Sway, how to visualize a `b512` value using the SDK, and how to interact with a contract function that accepts a `b512` parameter.
In Sway, the `B512` type is commonly used to handle public keys and signatures. This guide will explain how the `B512` type is defined in Sway, how to visualize a `B512` value using the SDK, and how to interact with a contract function that accepts a `B512` parameter.

The `b512` type in Sway is a wrapper around two `b256` types, allowing for the representation of 64-byte values. It is defined as a struct:
The `B512` type in Sway is a wrapper around two `B256` types, allowing for the representation of 64-byte values. It is defined as a struct:

<<< @/../../docs/sway/bytecode-input/src/main.sw#b512-1{rs:line-numbers}

## `b512` in the SDK
## `B512` in the SDK

In the SDK, you can visualize a `b512` value by examining a wallet's public key:
In the SDK, you can visualize a `B512` value by examining a wallet's public key:

<<< @./snippets/b512/b512-in-the-sdk.ts#snippet-1{ts:line-numbers}

## Example: Echoing a `b512` Value in a Contract Function
## Example: Echoing a `B512` Value in a Contract Function

Let's consider a contract function that accepts a `b512` parameter and returns the same value:
Let's consider a contract function that accepts a `B512` parameter and returns the same value:

<<< @/../../docs/sway/echo-values/src/main.sw#b512-3{rust:line-numbers}

To call this function and validate the returned value, follow these steps:

<<< @./snippets/b512/echoing-a-b512.ts#snippet-1{ts:line-numbers}

In this example, we generate a wallet, use its public key as the `b512` input, call the `echo_b512` contract function, and expect the returned value to match the original input.
In this example, we generate a wallet, use its public key as the `B512` input, call the `echo_b512` contract function, and expect the returned value to match the original input.
2 changes: 1 addition & 1 deletion apps/docs/src/guide/types/bytes32.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ You can use the `hexlify` function to convert a byte array to a hex string, and

## Working with b256 in Fuel

In Fuel, there is a special type called b256, which is similar to `bytes32`. Like `bytes32`, `b256` is also used to represent hashes and holds a 256-bit value. You can learn more about working with `b256` values in the [B256 documentation](./b256.md).
In Fuel, there is a special type called b256, which is similar to `bytes32`. Like `bytes32`, `B256` is also used to represent hashes and holds a 256-bit value. You can learn more about working with `B256` values in the [B256 documentation](./b256.md).
2 changes: 1 addition & 1 deletion apps/docs/src/guide/utilities/address-conversion.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ Similarly, the Wallet `address` property is also of type [`Address`](https://fue

## Converting an Asset ID

[Asset IDs](../types/asset-id.md) are a wrapped [b256](../types/b256.md) value. The following example shows how to create an [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) from a `b256` type:
[Asset IDs](../types/asset-id.md) are a wrapped [`B256`](../types/b256.md) value. The following example shows how to create an [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) from a `B256` type:

<<< @./snippets/address-conversion/asset-id.ts#conversion-4{ts:line-numbers}
2 changes: 1 addition & 1 deletion apps/docs/sway/bytecode-input/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ abi MyContract {

// #region b512-1
pub struct B512 {
/// The two `b256`s that make up the `B512`.
/// The two `B256`s that make up the `B512`.
bits: [b256; 2],
}
// #endregion b512-1
Expand Down

0 comments on commit 9c8b76a

Please sign in to comment.