Skip to content
This repository was archived by the owner on Aug 11, 2024. It is now read-only.

Latest commit

 

History

History
241 lines (148 loc) · 4.53 KB

Address.md

File metadata and controls

241 lines (148 loc) · 4.53 KB

ton3-core / Address

Class: Address

Smart contract address

Table of contents

Constructors

Accessors

Methods

Properties

Constructors

constructor

new Address(address, options?)

Creates an instance of Address

Next formats can be used as constructor argument:

  • Raw
  • Base64
  • Address

example

import { Address } from 'ton3-core'

const address = new Address('kf/8uRo6OBbQ97jCx2EIuKm8Wmt6Vb15+KsQHFLbKSMiYIny')
const rewrite = { workchain: 0, bounceable: true, testOnly: true }

new Address('-1:fcb91a3a3816d0f7b8c2c76108b8a9bc5a6b7a55bd79f8ab101c52db29232260')
new Address('-1:fcb91a3a3816d0f7b8c2c76108b8a9bc5a6b7a55bd79f8ab101c52db29232260', rewrite)
new Address('kf_8uRo6OBbQ97jCx2EIuKm8Wmt6Vb15-KsQHFLbKSMiYIny')
new Address(address)

Parameters

Name Type
address string | Address
options? AddressRewriteOptions

Accessors

hash

get hash(): Uint8Array

Get parsed Address hash part

example

import { Address, Utils } from 'ton3-core'

const address = new Address('-1:fcb91a3a3816d0f7b8c2c76108b8a9bc5a6b7a55bd79f8ab101c52db29232260')
const hash = address.hash // Uint8Array

console.log(Utils.Helpers.bytesToHex(hash))
// fcb91a3a3816d0f7b8c2c76108b8a9bc5a6b7a55bd79f8ab101c52db29232260

Returns

Uint8Array


workchain

get workchain(): number

Get parsed Address workchain

example

import { Address } from 'ton3-core'

const address = new Address('-1:fcb91a3a3816d0f7b8c2c76108b8a9bc5a6b7a55bd79f8ab101c52db29232260')

console.log(address.workchain)
// -1

Returns

number


bounceable

get bounceable(): boolean

Get parsed Address bounceable flag

example

import { Address } from 'ton3-core'

const address = new Address('-1:fcb91a3a3816d0f7b8c2c76108b8a9bc5a6b7a55bd79f8ab101c52db29232260')

console.log(address.bounceable)
// false

Returns

boolean


testOnly

get testOnly(): boolean

Get parsed Address testOnly flag

example

import { Address } from 'ton3-core'

const address = new Address('-1:fcb91a3a3816d0f7b8c2c76108b8a9bc5a6b7a55bd79f8ab101c52db29232260')

console.log(address.testOnly)
// false

Returns

boolean

Methods

eq

eq(address): boolean

Compare instances of Address for hash and workchain equality

example

import { Address } from 'ton3-core'

const address1 = new Address('-1:fcb91a3a3816d0f7b8c2c76108b8a9bc5a6b7a55bd79f8ab101c52db29232260')
const address2 = new Address('kf_8uRo6OBbQ97jCx2EIuKm8Wmt6Vb15-KsQHFLbKSMiYIny')

console.log(address1.eq(address2))
// true

Parameters

Name Type Description
address Address Instance of another Address

Returns

boolean


toString

toString(type?, options?): string

Get raw or base64 representation of Address

example

import { Address } from 'ton3-core'

const raw = '-1:fcb91a3a3816d0f7b8c2c76108b8a9bc5a6b7a55bd79f8ab101c52db29232260'
const address = new Address(raw, { bounceable: true, testOnly: true })

console.log(address.toString('base64'))
// kf_8uRo6OBbQ97jCx2EIuKm8Wmt6Vb15-KsQHFLbKSMiYIny

console.log(address.toString('base64', { urlSafe: false }))
// kf/8uRo6OBbQ97jCx2EIuKm8Wmt6Vb15+KsQHFLbKSMiYIny

console.log(address.toString('raw', { workchain: 0 }))
// 0:fcb91a3a3816d0f7b8c2c76108b8a9bc5a6b7a55bd79f8ab101c52db29232260

Parameters

Name Type Default value
type AddressType 'base64'
options? AddressStringifyOptions undefined

Returns

string


isValid

Static isValid(address): boolean

Parameters

Name Type
address any

Returns

boolean

Properties

NONE

Static Readonly NONE: any = null

Helper method for writing null addresses to Builder

static