Icon HelpCircleForumIcon Link

⌘K

Icon HelpCircleForumIcon Link

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';
 
// b256 is a hexlified string representing a 256-bit value
const b256: string = getRandomB256();
 
console.log('b256', b256);
// 0xbebd3baab326f895289ecbd4210cf886ce41952316441ae4cac35f00f0e882a6

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, getRandomB256, hexlify } from 'fuels';
 
const randomB256: string = getRandomB256();
 
// Convert to Uint8Array
const uint8Arr: Uint8Array = arrayify(randomB256);
 
// Convert back to hexlified string
const hexedB256: string = 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 { getRandomB256, Address } from 'fuels';
 
const randomB256: string = getRandomB256();
 
const address = Address.fromB256(randomB256);