Address Object
Address could be represented in multiple forms: friendly and raw. Friendly one can have different flags set: bounceable and testOnly.
In general you should always have bounceable flag set and testOnly is set depending on if you are working with production or test network.
Library always strips out this flags and doesn't store them internally, this flags are always provided/resolved only during parsing or serialization.
Fields
workChain- address' worchain -0or-1hash- address' hash -32 byte buffer
Parsing friendly address
You should always use this parser when processing input from a user.
import { Address } from 'ton';const friendlyParsed = Address.parseFriendly('kQAs9VlT6S776tq3unJcP5Ogsj-ELLunLXuOb1EKcOQi47nL');console.log(friendly.isBounceable); // falseconsole.log(friendly.isTestOnly); // trueconsole.log(friendly.address); // Address itselfParsing RAW address
import { Address } from 'ton';const address = Address.parseRaw(Buffer.from('2cf55953e92efbeadab7ba725c3f93a0b23f842cbba72d7b8e6f510a70e422e3', 'hex'));console.log(address.toFriendly()); // Address itselfParsing RAW or Friendly address
This is a helper method that is useful for tests. This parser always ignore bounceable and testOnly flags;
import { Address } from 'ton';const address = Address.parse('kQAs9VlT6S776tq3unJcP5Ogsj-ELLunLXuOb1EKcOQi47nL');console.log(address.toFriendly()); // Address itselfAddress to friendly string
import { Address } from 'ton';const address = Address.parse('kQAs9VlT6S776tq3unJcP5Ogsj-ELLunLXuOb1EKcOQi47nL');console.log(address.toFriendly()); // Bounceable production addressconsole.log(address.toFriendly({ testOnly: true })); // Bounceable test addressconsole.log(address.toFriendly({ bounceable: true })); // Non-Bounceable production addressAddress to RAW string
import { Address } from 'ton';const address = Address.parse('kQAs9VlT6S776tq3unJcP5Ogsj-ELLunLXuOb1EKcOQi47nL');console.log(address.toString()); // RAW representation of an addressTest equality
Regardles of how you parse address you can always compare address to each other:
import { Address } from 'ton';const address1 = Address.parseFriendly('kQAs9VlT6S776tq3unJcP5Ogsj-ELLunLXuOb1EKcOQi47nL').address;const address2 = Address.parseRaw(Buffer.from('2cf55953e92efbeadab7ba725c3f93a0b23f842cbba72d7b8e6f510a70e422e3', 'hex'));console.log(address1.equals(address2)); // true