Icon LinkBits256

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 are required.

Icon LinkGenerating random b256 values

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

import { getRandomB256 } from 'fuels';
 
// randomB256 is a hexlified string representing a 256-bit value
const randomB256: string = getRandomB256();

Icon LinkConverting between b256 and Uint8Array

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

import { arrayify, hexlify, getRandomB256 } from 'fuels';
 
const randomB256: string = getRandomB256();
 
// convert to Uint8Array
const uint8Arr = arrayify(randomB256);
 
// convert back to hexlified string
const hexedB256 = hexlify(uint8Arr);

Icon LinkSupport 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:

import { Address, getRandomB256 } from 'fuels';
 
const randomB256: string = getRandomB256();
 
const address = Address.fromB256(randomB256);
 
expect(address.toB256()).toEqual(randomB256);