-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8ddc8a6
commit 9c8b76a
Showing
9 changed files
with
23 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters