Hethers
  • Documentation
  • Getting Started
  • Application Programming Interface
    • Providers
      • Provider
        • Accounts Methods
        • Logs Methods
        • Network Status Methods
        • Transactions Methods
        • Event Emitter Methods
        • Base Provider
        • HederaProvider
      • Types
    • Contract Interaction
      • Contract
      • ContractFactory
      • Example: ERC-20 Contract
    • Utilities
      • Accounts
      • Addresses
      • Application Binary Interface
        • AbiCoder
        • ABI Formats
        • Fragments
        • Interface
      • BigNumber
      • Byte Manipulation
      • Constants
      • Display Logic and Input
      • Encoding Utilities
      • FixedNumber
      • Hashing Algorithms
      • HD Wallet
      • Logging
      • Property Utilities
      • Signing Key
      • Strings
      • Transactions
      • Web Utilities
      • Wordlists
    • Signers
  • Contributing
  • Other Resources
Powered by GitBook
On this page
  • Address Formats
  • Address
  • ICAP Address
  • Converting and Verifying
  • Derivation
  • Contract Addresses
  1. Application Programming Interface
  2. Utilities

Addresses

PreviousAccountsNextApplication Binary Interface

Last updated 2 years ago

Address Formats

Address

An Address is a of 20 bytes (40 nibbles), with optional mixed case.

If the case is mixed, it is a Checksum Address, which uses a specific pattern of uppercase and lowercase letters within a given address to reduce the risk of errors introduced from typing an address or cut and paste issues.

All functions that return an Address will return a Checksum Address.

ICAP Address

The ICAP Address Format was an early attempt to introduce a checksum into Ethereum addresses using the popular banking industry's format with the country code specified as XE.

Due to the way IBAN encodes address, only addresses that fit into 30 base-36 characters are actually compatible, so the format was adapted to support 31 base-36 characters which is large enough for a full Ethereum address, however the preferred method was to select a private key whose address has a 0 as the first byte, which allows the address to be formatted as a fully compatibly standard IBAN address with 30 base-36 characters.

In general this format is no longer widely supported anymore, however any function that accepts an address can receive an ICAP address, and it will be converted internally.

To convert an address into the ICAP format, see .

Converting and Verifying

hethers.utils.getAddress( address ) ⇒ string<>

Returns address as a Checksum Address.

If address is an invalid 40-nibble or if it contains mixed case and the checksum is invalid, an Error is thrown.

The value of address may be any supported address format.

// Injects the checksum (via upper-casing specific letters)
hethers.utils.getAddress("0x8ba1f109551bd432803012645ac136ddd64dba72");
// '0x8ba1f109551bD432803012645Ac136ddd64DBA72'

// Converts and injects the checksum
hethers.utils.getAddress("XE65GB6LDNXYOFTX0NSV3FUWKOWIXAMJK36");
// '0x8ba1f109551bD432803012645Ac136ddd64DBA72'

// Throws if a checksummed address is provided, but a
// letter is the wrong case
// ------------v (should be lower-case)
hethers.utils.getAddress("0x8Ba1f109551bD432803012645Ac136ddd64DBA72")
// [Error: bad address checksum] {
//   argument: 'address',
//   code: 'INVALID_ARGUMENT',
//   reason: 'bad address checksum',
//   value: '0x8Ba1f109551bD432803012645Ac136ddd64DBA72'
// }

// Throws if the ICAP/IBAN checksum fails
hethers.utils.getIcapAddress("XE65GB6LDNXYOFTX0NSV3FUWKOWIXAMJK37");
// Error: INVALID_ARGUMENT

// Throws if the address is invalid, in general
hethers.utils.getIcapAddress("I like turtles!");
// Error: INVALID_ARGUMENT

getIcapAddress("0x8ba1f109551bd432803012645ac136ddd64dba72");
// 'XE65GB6LDNXYOFTX0NSV3FUWKOWIXAMJK36'

getIcapAddress("XE65GB6LDNXYOFTX0NSV3FUWKOWIXAMJK36");
// 'XE65GB6LDNXYOFTX0NSV3FUWKOWIXAMJK36'

hethers.utils.isAddress( address ) ⇒ boolean

Returns true if address is valid (in any supported format).

isAddress("0x8ba1f109551bd432803012645ac136ddd64dba72");
// true

isAddress("XE65GB6LDNXYOFTX0NSV3FUWKOWIXAMJK36");
// true

isAddress("I like turtles.");
// false

Derivation

hethers.utils.computeAlias( publicKey ) ⇒ string

Returns the alias for the provided publicKey. The public key may be compressed or uncompressed.

computeAlias("0x19ceac7a7132ac20b41bebca8f766ab79667fa6591277263f622385764d01ef5");
// '0.0.BHVfad0xeFdKiqt0O1pOpNouw0g4vZ6tEiuRlAW3BllfoW6sD75dxoMWtXEMakFaqEQFdALbkrsbFd1QNi+I0Zw='

Returns the checksum address for the provided ECDSA hash. Converts characters to upper or lower case in the correct locations.

hethers.utils.getChecksumAddress("0x8ba1f109551bD432803012645Ac136ddd64DBA72")
// 0x8ba1f109551bD432803012645Ac136ddd64DBA72

hethers.utils.getAccountFromTransactionId( transactionId ) => string

Extracts the AccountId from the provided transactionId.

getAccountFromTransactionId("0.0.1546615-1641987871-235099329")
// 0.0.1546615

asAccountString("0x0000000000000000000000000000000000000001")
// 0.0.1

hethers.utils.computeAddress( publicOrPrivateKey: string ) => string

Returns the address for publicOrPrivateKey. A public key may be compressed or uncompressed, and a private key will be converted automatically to a public key for the derivation.

NOTE: This method would work properly only with Alias ECDSA accounts. Addresses on ED25519 and non-alias ECDSA accounts can not be computed.

// Public key (uncompressed)
computeAddress("0x04b3c641418e89452cd5202adfd4758f459acb8e364f741fd16cd2db79835d39d2cb8be79be6ac6e1fb9da8013904a077c3909110a122311f470f1dcc390a5aca6")
// "0x67D8d32E9Bf1a9968a5ff53B87d777Aa8EBBEe69"

// Public key (compressed)
computeAddress("0x02b3c641418e89452cd5202adfd4758f459acb8e364f741fd16cd2db79835d39d2")
// "0x67D8d32E9Bf1a9968a5ff53B87d777Aa8EBBEe69"

// Private key
computeAddress("0x105d050185ccb907fba04dd92d8de9e32c18305e097ab41dadda21489a211524")
// "0x67D8d32E9Bf1a9968a5ff53B87d777Aa8EBBEe69"

Contract Addresses

const from = "0x8ba1f109551bD432803012645Ac136ddd64DBA72";
const salt = "0x7c5ea36004851c764c44143b1dcb59679b11c9a68e5f41497f6cf3d480715331";
const initCode = "0x6394198df16000526103ff60206004601c335afa6040516060f3";
const initCodeHash = keccak256(initCode);

getCreate2Address(from, salt, initCodeHash);
// '0x533ae9d683B10C02EbDb05471642F85230071FC3'

hethers.utils.getIcapAddress( address ) ⇒ string<>

Returns address as an . Supports the same restrictions as .

hethers.utils.getChecksumAddress( address ) => string<>

hethers.utils.asAccountString( accountLike: ) => string

Converts the provided to an AccountId string.

hethers.utils.getCreate2Address( from , salt , initCodeHash ) ⇒ string<>

Returns the contract address that would result from the given call.

CREATE2
IcapAddress
ICAP address
getAddress
Address
Address
IBAN
getIcapAddress
Address
DataHexString
HexString
INVALID_ARGUMENT
AccountLike
AccountLike