Skip to main content

Iban

Converts Ethereum addresses to IBAN or BBAN addresses and vice versa. For using Iban package, first install Web3 package using: npm i web3 or yarn add web3 based on your package manager, after that ENS features can be used.


import { Web3 } from 'web3';
const web3 = new Web3('https://mainnet.infura.io/v3/<YOURPROJID>');

const iban = new web3.eth.Iban("XE81ETHXREGGAVOFYORK");
console.log(iban.checksum());

For using individual package install web3-eth-iban packages using: npm i web3-eth-iban or yarn add web3-eth-iban.

import {Iban} from 'web3-eth-iban';

const iban = new Iban("XE81ETHXREGGAVOFYORK");
console.log(iban.checksum());

Index

Constructors

constructor

  • new Iban(iban: string): Iban
  • Construct a direct or indirect IBAN that has conversion methods and validity checks. If the provided string was not of either the length of a direct IBAN (34 or 35), nor the length of an indirect IBAN (20), an Error will be thrown ('Invalid IBAN was provided').

    @example
    const iban = new web3.eth.Iban("XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS");
    > Iban { _iban: 'XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS' }

    Parameters

    • iban: string

      a Direct or an Indirect IBAN

    Returns Iban

    • Iban instance

Properties

toAddress

toAddress: () => string

This method should be used to create the equivalent ethereum address for the early provided Direct IBAN address. If the provided string was not a direct IBAN (has the length of 34 or 35), an Error will be thrown: ('Iban is indirect and cannot be converted. Must be length of 34 or 35'). Note: this is also available as a static method.

@returns

the equivalent ethereum address

@example
const iban = new web3.eth.Iban("XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS");
iban.toAddress();
> "0x00c5496aEe77C1bA1f0854206A26DdA82a81D6D8"

Type declaration

    • (): string
    • Returns string

statictoAddress

toAddress: (iban: string) => string

This method should be used to create an ethereum address from a Direct IBAN address. If the provided string was not a direct IBAN (has the length of 34 or 35), an Error will be thrown: ('Iban is indirect and cannot be converted. Must be length of 34 or 35'). Note: this is also available as a method at an Iban instance.

@returns

the equivalent ethereum address

@example
web3.eth.Iban.toAddress("XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS");
> "0x00c5496aEe77C1bA1f0854206A26DdA82a81D6D8"

Type declaration

    • (iban: string): string
    • Parameters

      • iban: string

        a Direct IBAN address

      Returns string

Methods

checksum

  • checksum(): string
  • Returns the IBAN checksum of the early provided IBAN

    @example
    const iban = new web3.eth.Iban("XE81ETHXREGGAVOFYORK");
    iban.checksum();
    > "81"

    Returns string

client

  • client(): string
  • Should be called to get client identifier within institution

    @example
    const iban = new web3.eth.Iban("XE81ETHXREGGAVOFYORK");
    iban.client();
    > 'GAVOFYORK'

    Returns string

    the client of the IBAN instance.

institution

  • institution(): string
  • Returns institution identifier from the early provided IBAN

    @example
    const iban = new web3.eth.Iban("XE81ETHXREGGAVOFYORK");
    iban.institution();
    > 'XREG'

    Returns string

isDirect

  • isDirect(): boolean
  • An instance method that checks if iban number is Direct. It actually check the length of the provided variable and, only if it is 34 or 35, it returns true. Note: this is also available as a static method.

    @example
    const iban = new web3.eth.Iban("XE81ETHXREGGAVOFYORK");
    iban.isDirect();
    > false

    Returns boolean

    • true if the provided iban is a Direct IBAN, and false otherwise.

isIndirect

  • isIndirect(): boolean
  • check if iban number if indirect It actually check the length of the provided variable and, only if it is 20, it returns true. Note: this is also available as a static method.

    @example
    const iban = new web3.eth.Iban("XE81ETHXREGGAVOFYORK");
    iban.isIndirect();
    > true

    Returns boolean

    • true if the provided iban is an Indirect IBAN, and false otherwise.

isValid

  • isValid(): boolean
  • Should be called to check if the early provided IBAN is correct. Note: this is also available as a static method.

    @example
    const iban = new web3.eth.Iban("XE81ETHXREGGAVOFYORK");
    iban.isValid();
    > true

    const iban = new web3.eth.Iban("XE82ETHXREGGAVOFYORK");
    iban.isValid();
    > false // because the checksum is incorrect

    Returns boolean

toString

  • toString(): string
  • Simply returns the early provided IBAN

    @example
    const iban = new web3.eth.Iban('XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS');
    iban.toString();
    > 'XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS'

    Returns string

staticcreateIndirect

  • createIndirect(options: IbanOptions): Iban
  • Should be used to create IBAN object for given institution and identifier

    @example
    web3.eth.Iban.createIndirect({
    institution: "XREG",
    identifier: "GAVOFYORK"
    });
    > Iban {_iban: "XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS"}

    Parameters

    • options: IbanOptions

      an object holds the institution and the identifier which will be composed to create an Iban object from.

    Returns Iban

    an Iban class instance that holds the equivalent IBAN

staticfromAddress

  • fromAddress(address: string): Iban
  • This method should be used to create iban object from an Ethereum address.

    @example
    web3.eth.Iban.fromAddress("0x00c5496aEe77C1bA1f0854206A26DdA82a81D6D8");
    > Iban {_iban: "XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS"}

    Parameters

    • address: string

      an Ethereum address

    Returns Iban

    an Iban class instance that holds the equivalent IBAN

staticfromBban

  • fromBban(bban: string): Iban
  • Convert the passed BBAN to an IBAN for this country specification. Please note that

    <i>
    "generation of the IBAN shall be the exclusive responsibility of the bank/branch servicing the account"
    </i>
    . This method implements the preferred algorithm described in http://en.wikipedia.org/wiki/International_Bank_Account_Number#Generating_IBAN_check_digits

    @example
    web3.eth.Iban.fromBban('ETHXREGGAVOFYORK');
    > Iban {_iban: "XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS"}

    Parameters

    • bban: string

      the BBAN to convert to IBAN

    Returns Iban

    an Iban class instance that holds the equivalent IBAN

staticisDirect

  • isDirect(iban: string): boolean
  • A static method that checks if an IBAN is Direct. It actually check the length of the provided variable and, only if it is 34 or 35, it returns true. Note: this is also available as a method at an Iban instance.

    @example
    web3.eth.Iban.isDirect("XE81ETHXREGGAVOFYORK");
    > false

    Parameters

    • iban: string

      an IBAN to be checked

    Returns boolean

    • true if the provided iban is a Direct IBAN, and false otherwise.

staticisIndirect

  • isIndirect(iban: string): boolean
  • A static method that checks if an IBAN is Indirect. It actually check the length of the provided variable and, only if it is 20, it returns true. Note: this is also available as a method at an Iban instance.

    @example
    web3.eth.Iban.isIndirect("XE81ETHXREGGAVOFYORK");
    > true

    Parameters

    • iban: string

      an IBAN to be checked

    Returns boolean

    • true if the provided iban is an Indirect IBAN, and false otherwise.

staticisValid

  • isValid(iban: string): boolean
  • This method could be used to check if a given string is valid IBAN object. Note: this is also available as a method at an Iban instance.

    @example
    web3.eth.Iban.isValid("XE81ETHXREGGAVOFYORK");
    > true

    web3.eth.Iban.isValid("XE82ETHXREGGAVOFYORK");
    > false // because the checksum is incorrect

    Parameters

    • iban: string

      a string to be checked if it is in IBAN

    Returns boolean

    • true if it is valid IBAN

statictoIban

  • toIban(address: string): string
  • This method should be used to create IBAN address from an Ethereum address

    @example
    web3.eth.Iban.toIban("0x00c5496aEe77C1bA1f0854206A26DdA82a81D6D8");
    > "XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS"

    Parameters

    • address: string

      an Ethereum address

    Returns string

    the equivalent IBAN address