Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Wallet

Wallet

The wallet is the primary way you will interact with the SDK.

Hierarchy

  • Wallet

Index

Constructors

constructor

  • Instantiating

    import Wallet from '@logosnetwork/logos-webwallet-sdk'
    const wallet = new Wallet({
        password: null,
        seed: null,
        deterministicKeyIndex: 0,
        currentAccountAddress: null,
        accounts: {},
        tokenAccounts: {},
        walletID: null,
        batchSends: true,
        fullSync: true,
        lazyErrors: false,
        tokenSync: false,
        validateSync: true,
        ws: false,
        mqtt: defaultMQTT,
        rpc: defaultRPC
    })

    All wallet options are optional defaults are shown in the example above

    Wallet Option Description
    password Password is used to encrypt and decrypt the wallet data
    seed Seed is the deterministic entropy that we will use to generate key pairs from
    deterministicKeyIndex index of where you wish to start generating key paris from
    currentAccountAddress the current selected account address
    accounts AccountMap of all the logos accounts in the Wallet
    tokenAccounts TokenAccountMap of all the token accounts in the Wallet
    walletID identifier of this wallet instance
    batchSends when batchsends is true the SDK automatically combines send transactions to reduce overall amount of transactions
    fullSync when fullSync is true the SDK will load the full history of the TokenAccounts and Accounts in the system. This is recommend to be true when working with tokens.
    lazyErrors when lazyErrors is true the SDK will not throw errors for transactions that have insufficient funds and will queue the transactions until the account has the funds to complete the action.
    tokenSync when tokenSync is true the SDK will load and sync the TokenAccounts that have interacted with the LogosAccounts.
    validateSync when validateSync is true the SDK will check all signatures of all the requests in the account chains. This is recommended to be true but when syncing an account with a long history this can be computationally heavy.
    ws when ws is true connect to local logos node websocket. You should only use mqtt or ws not both! mqtt will take priority over WS the MQTT setup uses less resources at the current time.
    mqtt address of your mqtt server 'wss://pla.bs:8443' is the default server. Check out the logos backend repo to run your own backend mqtt.
    rpc Node information where you are sending requests to. See RPCOptions. Do not use the ip address of a delegate node, it won't work and also delegates shouldn't have RPC enabled...

    Parameters

    • Default value options: WalletOptions = {password: null,seed: null,deterministicKeyIndex: 0,currentAccountAddress: null,accounts: {},tokenAccounts: {},walletID: null,batchSends: true,fullSync: true,lazyErrors: false,tokenSync: false,validateSync: true,ws: false,p2pPropagation: false,mqtt: defaultMQTT,rpc: defaultRPC,version: 1}

    Returns Wallet

Properties

Private _accounts

_accounts: object

Type declaration

Private _batchSends

_batchSends: boolean

Private _currentAccountAddress

_currentAccountAddress: string

Private _delegates

_delegates: string[]

Private _deterministicKeyIndex

_deterministicKeyIndex: number

Private _fullSync

_fullSync: boolean

Private _iterations

_iterations: number

Private _lazyErrors

_lazyErrors: boolean

Private _mqtt

_mqtt: string

Private _mqttClient

_mqttClient: MqttClient

Private _p2pPropagation

_p2pPropagation: boolean

Private _password

_password: string

Private _rpc

_rpc: RPCOptions | false

Private _seed

_seed: string

Private _tokenAccounts

_tokenAccounts: object

Type declaration

Private _tokenSync

_tokenSync: boolean

Private _validateSync

_validateSync: boolean

Private _walletID

_walletID: string

Private _ws

_ws: boolean

Private _wsClient

_wsClient: ReconnectingWebSocket

Private _wsConnected

_wsConnected: boolean

Accessors

account

accounts

balance

  • get balance(): string

batchSends

  • get batchSends(): boolean
  • set batchSends(val: boolean): void

currentAccountAddress

  • get currentAccountAddress(): string
  • set currentAccountAddress(address: string): void
  • The current account address

    Example

    const currentAccountAddress = wallet.currentAccountAddress

    Returns string

  • The current account address

    Example

    wallet.currentAccountAddress = 'lgs_3e3j5tkog48pnny9dmfzj1r16pg8t1e76dz5tmac6iq689wyjfpiij4txtdo'

    Parameters

    • address: string

    Returns void

delegates

  • get delegates(): string[]
  • set delegates(delegates: string[]): void
  • The current delegates of the network

    Example

    const delegates = wallet.delegates

    Returns string[]

  • The current delegates of the network

    Example

    wallet.delegates = ['3.215.28.211'] // Should be 32 length but I cba

    Parameters

    • delegates: string[]

    Returns void

fullSync

  • get fullSync(): boolean
  • set fullSync(val: boolean): void
  • Full Sync - syncs the entire send and recieve chains This is recommend to be true when using an untrusted RPC node In the future this will be safe when we have BLS sig validation of Request Blocks

    Example

    const isFullSyncing = wallet.fullSync

    Returns boolean

  • Full Sync - syncs the entire send and recieve chains This is recommend to be true when using an untrusted RPC node In the future this will be safe when we have BLS sig validation of Request Blocks

    Example

    wallet.fullSync = true

    Parameters

    • val: boolean

    Returns void

lazyErrors

  • get lazyErrors(): boolean
  • set lazyErrors(val: boolean): void
  • Lazy Errors allows you to add request that are not valid for the current pending balances to the pending chain

    Example

    const delayingErros = wallet.lazyErrors

    Returns boolean

  • Lazy Errors allows you to add request that are not valid for the current pending balances to the pending chain

    Example

    wallet.lazyErrors = false

    Parameters

    • val: boolean

    Returns void

mqtt

  • get mqtt(): string
  • set mqtt(val: string): void
  • The mqtt host for listening to confirmations from Logos consensus

    Example

    const mqttWsAddress = wallet.mqtt

    Returns string

  • The mqtt host for listening to confirmations from Logos consensus

    Example

    wallet.mqtt = 'wss://pla.bs:8443'

    Parameters

    • val: string

    Returns void

p2pPropagation

  • get p2pPropagation(): boolean
  • set p2pPropagation(val: boolean): void
  • When p2pPropagation is true public to local logos node instead of delegates

    Example

    const usingP2pPropagation = wallet.p2pPropagation

    Returns boolean

  • When p2pPropagation is true public to local logos node instead of delegates

    Example

    wallet.p2pPropagation = true

    Parameters

    • val: boolean

    Returns void

password

  • get password(): string
  • set password(password: string): void
  • The password of the wallet in the future we will remove the ability to store the password and request it in realtime so it is in memory for less time

    Example

    const password = wallet.password

    Returns string

  • The password of the wallet in the future we will remove the ability to store the password and request it in realtime so it is in memory for less time

    Example

    wallet.password = 'password'

    Parameters

    • password: string

    Returns void

pendingRequests

rpc

rpcClient

  • get rpcClient(): Logos

seed

  • get seed(): string
  • set seed(hexSeed: string): void
  • Return the seed of the wallet in the future we will remove the ability to access the seed unless you pass a password

    Example

    const seed = wallet.seed

    Returns string

  • Return the seed of the wallet in the future we will remove the ability to access the seed unless you pass a password

    Example

    wallet.seed = '6A4C54C619A784891D5DBCA1FCC5FA08D6B910B49A51BEA13C3DC913BB45AF13'

    Parameters

    • hexSeed: string

    Returns void

synced

  • get synced(): boolean
  • Return boolean if all the accounts in the wallet are synced

    Example

    const isWalletSynced = wallet.synced

    Returns boolean

tokenAccounts

tokenSync

  • get tokenSync(): boolean
  • set tokenSync(val: boolean): void
  • Sync Tokens - Syncs all associated token's of the accounts on the account sync instead of on use

    Example

    const areTokensSyncing = wallet.tokenSync

    Returns boolean

  • Sync Tokens - Syncs all associated token's of the accounts on the account sync instead of on use

    Example

    wallet.tokenSync = false

    Parameters

    • val: boolean

    Returns void

validateSync

  • get validateSync(): boolean
  • set validateSync(val: boolean): void
  • Validate Sync if this option is true the SDK will generate hashes of each requests based on the content data and verify signatures This should always be true when using a untrusted RPC node

    Example

    const isValidatingSignatures = wallet.validateSync

    Returns boolean

  • Validate Sync if this option is true the SDK will generate hashes of each requests based on the content data and verify signatures This should always be true when using a untrusted RPC node

    Example

    wallet.validateSync = false

    Parameters

    • val: boolean

    Returns void

walletID

  • get walletID(): string
  • set walletID(id: string): void
  • The id of the wallet

    Example

    const walletID = wallet.walletID

    Returns string

  • The id of the wallet

    Example

    wallet.walletID = '2c0a4be6b9ccda9158ed96f0dd596f72dad66015e8444c64e2ea0b9c7e553ec6'

    Parameters

    • id: string

    Returns void

ws

  • get ws(): boolean
  • set ws(val: boolean): void
  • When ws is true connect to local logos node websocket If mqtt is set then logos node websocket will not be used

    Example

    const usingLogosWebsocket = wallet.ws

    Returns boolean

  • When ws is true connect to local logos node websocket If mqtt is set then logos node websocket will not be used

    Example

    wallet.ws = true

    Parameters

    • val: boolean

    Returns void

Methods

addAccount

addTokenAccount

  • Adds a tokenAccount to the wallet

    Example

    const tokenAccount = await wallet.createTokenAccount('lgs_3q69z3kf6cq9n9smago3p1ptuyqy9pa3mdykyi9o8f7gnof47qdyxj9gejxd')
    wallet.addTokenAccount(tokenAccount)

    Parameters

    Returns TokenAccount

createAccount

  • Create an account

    You are allowed to create an account using your seed, precalculated account options, or a privateKey

    Parameters

    • Default value options: LogosAccountOptions = null

      the options to populate the account. If you send just private key it will generate the account from that privateKey. If you just send index it will genereate the account from that determinstic seed index.

    • Default value setCurrent: boolean = true

      sets the current account to newly created accounts this is default true

    Returns Promise<LogosAccount>

    Example

    const account = await wallet.createAccount()

createSeed

  • createSeed(overwrite?: boolean): string
  • Generates and sets a random seed for the wallet

    Example

    wallet.createSeed()

    Parameters

    • Default value overwrite: boolean = false

    Returns string

createTokenAccount

  • Create a TokenAccount

    You are allowed to add a tokenAccount using the address

    Example

    const tokenAccount = await wallet.createTokenAccount('lgs_3q69z3kf6cq9n9smago3p1ptuyqy9pa3mdykyi9o8f7gnof47qdyxj9gejxd')

    Parameters

    • address: string
    • Default value issuance: Issuance = null

    Returns Promise<TokenAccount>

Private decrypt

  • decrypt(encryptedWallet: Buffer | string): Buffer | false
  • Decrypts the wallet data

    Parameters

    • encryptedWallet: Buffer | string

    Returns Buffer | false

    The request data or returns false if it is unable to decrypt the data

encrypt

  • encrypt(): string

fetchDelegates

  • fetchDelegates(): Promise<string[]>
  • Fetches the delegates from the server and sets our delegate list

    Returns Promise<string[]>

    returns the list of active delegates ips

    Example

    const delegates = await wallet.fetchDelegates()

Private generateAccountOptionsFromPrivateKey

  • generateAccountOptionsFromPrivateKey(privateKey: string): AccountOptions
  • Generates an account based on the given private key

    Parameters

    • privateKey: string

    Returns AccountOptions

    The minimal account options to create the account

Private generateAccountOptionsFromSeed

  • Generates an account based on the determinstic index of the key

    Parameters

    • index: number

    Returns AccountOptions

    The minimal account options to create the account

getRequest

  • getRequest(hash: string): Request | false
  • Finds the request object of the specified hash of one of our accounts

    Parameters

    • hash: string

      The hash of the request we are looking for the object of

    Returns Request | false

    false if no request object of the specified hash was found

    Example

    wallet.getRequest('E8CA715349FFD12DE7CB76045CAAA52448655F3B34624A1E31514763C81C4795')

load

  • load(encryptedWallet: string): Wallet
  • Constructs the wallet from an encrypted base64 encoded wallet and the password

    Parameters

    • encryptedWallet: string

    Returns Wallet

    wallet data

    Example

    const wallet = wallet.load(encryptedWalletData)

Private loadOptions

Private processRequest

  • processRequest(requestInfo: RpcRequest, address: string, logosAccount?: boolean, tokenAccount?: boolean): void
  • Process Request finds the account if it is in our wallet and update its local ledger

    Parameters

    • requestInfo: RpcRequest

      JSON of the request block

    • address: string

      address we are looking for

    • Default value logosAccount: boolean = true

      update logos accounts

    • Default value tokenAccount: boolean = true

      update token accounts

    Returns void

recalculateWalletBalancesFromChain

  • recalculateWalletBalancesFromChain(): void
  • Updates the balance of all the accounts

    Returns void

    Example

    wallet.recalculateWalletBalancesFromChain()

removeAccount

  • removeAccount(address: string): boolean
  • Removes an account to the wallet

    Example

    wallet.removeAccount('lgs_3e3j5tkog48pnny9dmfzj1r16pg8t1e76dz5tmac6iq689wyjfpiij4txtdo')

    Parameters

    • address: string

    Returns boolean

Private reset

  • reset(): void

Private subscribe

  • subscribe(topic: string): void
  • Subscribe to the mqtt topic

    Parameters

    • topic: string

      topic to subscribe to

    Returns void

sync

  • sync(force?: boolean): Promise<boolean>
  • Scans the accounts to make sure they are synced and if they are not synced it syncs them

    Parameters

    • Default value force: boolean = false

    Returns Promise<boolean>

    Example

    const isWalletSynced = await wallet.sync()

toJSON

Private unsubscribe

  • unsubscribe(topic: string): void
  • Unsubscribe to the mqtt topic

    Parameters

    • topic: string

      topic to unsubscribe to

    Returns void

wsConnect

  • wsConnect(): void

wsDisconnect

  • wsDisconnect(): void

Generated using TypeDoc