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 = new Address(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 = new Address(wallet.publicKey);

Icon LinkFrom an EVM Address

To create an Address Icon Link from an EVM address, use the following code snippet:

import { Address } from 'fuels';
 
const evmAddress = '0x675b68aa4d9c2d3bb3f0397048e62e6b7192079c';
 
const address = new Address(evmAddress);

Icon LinkFrom an existing Address

To create an Address Icon Link from an existing Address Icon Link instance, use the following code snippet:

import { Address } from 'fuels';
 
const address = Address.fromRandom();
 
const addressClone = new Address(address);

Icon LinkUtility functions

Icon Linkequals

As you may already notice, the equals function can compare addresses instances:

import { Address } from 'fuels';
 
const address = Address.fromRandom();
 
const address1 = new Address(address.toString());
const address2 = new Address(address.toB256());
 
console.log('equals', address1.equals(address2));
// true

Icon LinktoChecksum

To convert an address to a checksum address, use the toChecksum function:

import { Address } from 'fuels';
 
const b256 =
  '0xbebd3baab326f895289ecbd4210cf886ce41952316441ae4cac35f00f0e882a6';
 
const address = new Address(b256);
 
console.log('checksum', address.toChecksum());
// true