Icon HelpCircleForumIcon Link

⌘K

Icon HelpCircleForumIcon Link

Icon LinkAddress

In Sway, the Address Icon Link 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 Icon Link type.

Icon LinkAddress Class

The Address Icon Link class also provides a set of utility functions for easy manipulation and conversion between address formats along with one property; b256Address, which is of the B256 type.

readonly b256Address: B256Address;

Icon LinkCreating an Address

There are several ways to create an Address Icon Link instance:

Icon LinkFrom a b256 address

To create an Address Icon Link from a 256-bit address, use the following code snippet:

import { Address } from 'fuels';
const b256 =
  '0xbebd3baab326f895289ecbd4210cf886ce41952316441ae4cac35f00f0e882a6';
 
const address = Address.fromB256(b256);
 
console.log('b256', address.toB256());
// 0xbebd3baab326f895289ecbd4210cf886ce41952316441ae4cac35f00f0e882a6

Icon LinkFrom a Public Key

To create an Address Icon Link from a public key, use the following code snippet:

import { Address, Provider, Wallet } from 'fuels';
 
import { LOCAL_NETWORK_URL } from '../../../../env';
 
const provider = new Provider(LOCAL_NETWORK_URL);
 
const wallet = Wallet.generate({ provider });
 
const address = Address.fromPublicKey(wallet.publicKey);

Icon LinkUtility Functions

The Address Icon Link class also provides some practical utility functions:

  1. fromString: Create a new Address Icon Link from an ambiguous source that may be a B256 address:
import { Address } from 'fuels';
 
const address = Address.fromRandom();
 
const addressCloneFromB256 = Address.fromString(address.toB256());
  1. fromDynamicInput: Create a new Address Icon Link when the address source is unknown:
import { Address } from 'fuels';
 
const dataFromInput: string =
  '0xf1e92c42b90934aa6372e30bc568a326f6e66a1a0288595e6e3fbd392a4f3e6e';
 
// If the input string can't be resolved this will throw an error
const address = Address.fromDynamicInput(dataFromInput);
  1. equals: As you may already notice, the equals function can compare addresses instances:
import { Address } from 'fuels';
 
const address = Address.fromRandom();
 
const address1 = Address.fromString(address.toString());
const address2 = Address.fromString(address.toB256());
 
console.log('equals', address1.equals(address2));
// true