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());

Constructors

constructor

new Iban(iban): 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').

Parameters

NameTypeDescription
ibanstringa Direct or an Indirect IBAN

Returns

Iban

  • Iban instance

Example

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

Methods

checksum

checksum(): string

Returns the IBAN checksum of the early provided IBAN

Returns

string

Example

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

client

client(): string

Should be called to get client identifier within institution

Returns

string

the client of the IBAN instance.

Example

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

institution

institution(): string

Returns institution identifier from the early provided IBAN

Returns

string

Example

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

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.

Returns

boolean

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

Example

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

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.

Returns

boolean

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

Example

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

isValid

isValid(): boolean

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

Returns

boolean

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

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

string

the equivalent ethereum address

Example

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

toString

toString(): string

Simply returns the early provided IBAN

Returns

string

Example

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

createIndirect

createIndirect(options): Iban

Should be used to create IBAN object for given institution and identifier

Parameters

NameTypeDescription
optionsIbanOptionsan 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

Example

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

fromAddress

fromAddress(address): Iban

This method should be used to create iban object from an Ethereum address.

Parameters

NameTypeDescription
addressstringan Ethereum address

Returns

Iban

an Iban class instance that holds the equivalent IBAN

Example

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

fromBban

fromBban(bban): Iban

Convert the passed BBAN to an IBAN for this country specification. Please note that "generation of the IBAN shall be the exclusive responsibility of the bank/branch servicing the account". This method implements the preferred algorithm described in http://en.wikipedia.org/wiki/International_Bank_Account_Number#Generating_IBAN_check_digits

Parameters

NameTypeDescription
bbanstringthe BBAN to convert to IBAN

Returns

Iban

an Iban class instance that holds the equivalent IBAN

Example

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

isDirect

isDirect(iban): 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.

Parameters

NameTypeDescription
ibanstringan IBAN to be checked

Returns

boolean

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

Example

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

isIndirect

isIndirect(iban): 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.

Parameters

NameTypeDescription
ibanstringan IBAN to be checked

Returns

boolean

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

Example

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

isValid

isValid(iban): 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.

Parameters

NameTypeDescription
ibanstringa string to be checked if it is in IBAN

Returns

boolean

  • true if it is valid IBAN

Example

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

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

toAddress

toAddress(iban): 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.

Parameters

NameTypeDescription
ibanstringa Direct IBAN address

Returns

string

the equivalent ethereum address

Example

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

toIban

toIban(address): string

This method should be used to create IBAN address from an Ethereum address

Parameters

NameTypeDescription
addressstringan Ethereum address

Returns

string

the equivalent IBAN address

Example

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