ethers.js/docs.wrm/api/utils/address.wrm

84 lines
3.4 KiB
Plaintext
Raw Normal View History

2020-01-10 09:01:00 +03:00
_section: Addresses @<addresses>
Explain addresses,formats and checksumming here.
2019-12-14 06:05:10 +03:00
Also see: [constants.AddressZero](constants)
2020-01-10 09:01:00 +03:00
_subsection: Address Formats @<address-formats>
2020-02-01 11:39:21 +03:00
_heading: Address @<address>
2020-05-08 10:24:40 +03:00
An **Address** is a [[DataHexString]] of 20 bytes (40 nibbles), with optional
2020-02-01 11:39:21 +03:00
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.
2020-01-10 09:01:00 +03:00
_heading: ICAP Address @<address-icap>
2020-02-01 11:39:21 +03:00
The **ICAP Address Format** was an early attempt to introduce a checksum
into Ethereum addresses using the popular banking industry's
2020-02-02 15:58:29 +03:00
[IBAN](link-wiki-iban)
2020-02-01 11:39:21 +03:00
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 [getIcapAddress](utils-getIcapAddress).
2020-01-10 09:01:00 +03:00
2020-05-08 10:24:40 +03:00
_subsection: Converting and Verifying @<utils--address>
2020-01-10 09:01:00 +03:00
2020-02-25 22:57:11 +03:00
_property: ethers.utils.getAddress(address) => string<[[address]]> @<utils-getAddress> @SRC<address>
2019-12-14 06:05:10 +03:00
Returns //address// as a Checksum Address.
2020-05-08 10:24:40 +03:00
If //address// is an invalid 40-nibble [[HexString]] or if it contains mixed case and
the checksum is invalid, an InvalidArgument Error is thrown.
2019-12-14 06:05:10 +03:00
The value of //address// may be any supported address format.
_property: ethers.utils.getIcapAddress(address) => string<[IcapAddress](address-icap)> @<utils-getIcapAddress> @SRC<address>
Returns //address// as an [ICAP address](link-icap).
Supports the same restrictions as [utils.getAddress](utils-getAddress).
2019-12-14 06:05:10 +03:00
2020-02-25 22:57:11 +03:00
_property: ethers.utils.isAddress(address) => boolean @<utils-isAddress> @SRC<address>
2019-12-14 06:05:10 +03:00
Returns true if //address// is valid (in any supported format).
2020-05-08 10:24:40 +03:00
_subsection: Derivation @<utils--address-derivation>
_property: ethers.utils.computeAddress(publicOrPrivateKey) => string<[[address]]> @<utils-computeAddress> @SRC<transactions>
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.
_property: ethers.utils.recoverAddress(digest, signature) => string<[[address]]> @<utils-recoverAddress> @SRC<transactions>
Use [[link-wiki-ecrecover]] to determine the address that signed //digest// to
which generated //signature//.
_subsection: Contracts Addresses @<utils--contract-addresses>
_property: ethers.utils.getContractAddress(transaction) => string<[[address]]> @<utils-getContractAddress> @SRC<address>
2019-12-14 06:05:10 +03:00
Returns the contract address that would result if //transaction// was
used to deploy a contract.
2020-01-10 09:01:00 +03:00
2020-02-25 22:57:11 +03:00
_property: ethers.utils.getCreate2Address(from, salt, initCodeHash) => string<[[address]]> @<utils-getCreate2Address> @SRC<address>
2020-01-10 09:01:00 +03:00
Returns the contract address that would result from the given
2020-02-02 15:58:29 +03:00
[CREATE2](link-eip-1014) call.