Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • Wallet

Index

Constructors

constructor

  • example
    const { Wallet } = require('@harmony-js/account');
    const { HttpProvider, Messenger } = require('@harmony-js/network');
    const { ChainType, ChainID } = require('@harmony-js/utils');
    
    // create a custom messenger
    const customMessenger = new Messenger(
      new HttpProvider('http://localhost:9500'),
      ChainType.Harmony, // if you are connected to Harmony's blockchain
      ChainID.HmyLocal, // check if the chainId is correct
    )
    
    const wallet = new Wallet(customMessenger);

    Parameters

    • Default value messenger: Messenger = defaultMessenger

    Returns Wallet

Accessors

accounts

  • get accounts(): string[]
  • get acounts addresses

    example
    const wallet = new Wallet(customMessenger);
    const key_1 = '45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e';
    wallet.addByPrivateKey(key_1);
    
    console.log(wallet.accounts);

    Returns string[]

    accounts addresses

signer

  • get signer(): Account | undefined
  • get the signer of the account, by default, using the first account

    example
    const wallet = new Wallet(customMessenger);
    const key_1 = '45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e';
    wallet.addByPrivateKey(key_1);
    
    console.log(wallet.signer)

    Returns Account | undefined

Methods

addByKeyStore

  • addByKeyStore(keyStore: string, password: string): Promise<Account>
  • Add an account using privateKey

    Parameters

    • keyStore: string

      keystore jsonString to add

    • password: string

      password to decrypt the file

    Returns Promise<Account>

    return added Account

addByMnemonic

  • addByMnemonic(phrase: string, index?: number): Account
  • Add account using Mnemonic phrases

    example
    const mnemonic_1 = 'urge clog right example dish drill card maximum mix bachelor section select';
    const wallet = new Wallet(customMessenger);
    wallet.addByMnemonic(mnemonic_1);
    
    console.log(wallet.accounts);

    Parameters

    • phrase: string

      Mnemonic phrase

    • Default value index: number = 0

      index to hdKey root

    Returns Account

addByPrivateKey

  • addByPrivateKey(privateKey: string): Account
  • Add an account using privateKey

    example
    const wallet = new Wallet(customMessenger);
    const key_1 = '45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e';
    console.log(wallet.addByPrivateKey(key_1));

    Parameters

    • privateKey: string

      privateKey to add

    Returns Account

    return added Account

createAccount

  • createAccount(password?: string, options?: EncryptOptions): Promise<Account>
  • create a new account using Mnemonic

    example
    console.log(wallet.accounts);
    wallet.createAccount();
    wallet.createAccount();
    
    console.log(wallet.accounts);

    Parameters

    • Optional password: string
    • Optional options: EncryptOptions

    Returns Promise<Account>

    {description}

decryptAccount

  • decryptAccount(address: string, password: string): Promise<Account>
  • To decrypt an account that lives in the wallet,if not encrypted, return original, if not found, throw error

    example
    const key_1 = '45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e';
    wallet.addByPrivateKey(key_1);
    wallet.encryptAccount('one103q7qe5t2505lypvltkqtddaef5tzfxwsse4z7', '12345')
    .then(() => {
      wallet.decryptAccount('one103q7qe5t2505lypvltkqtddaef5tzfxwsse4z7', '12345')
      .then((value) =>{
         console.log(value);
      });
    });

    Parameters

    • address: string

      address in accounts

    • password: string

      string that used to encrypt

    Returns Promise<Account>

encryptAccount

  • encryptAccount(address: string, password: string, options?: EncryptOptions): Promise<Account>
  • To encrypt an account that lives in the wallet. if encrypted, returns original one, if not found, throw error

    example
    const key_1 = '45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e';
    wallet.addByPrivateKey(key_1);
    wallet.encryptAccount('one103q7qe5t2505lypvltkqtddaef5tzfxwsse4z7', '12345').then((value) => {
      console.log(value);
    })

    Parameters

    • address: string

      address in accounts

    • password: string

      string that used to encrypt

    • Optional options: EncryptOptions

      encryption options

    Returns Promise<Account>

getAccount

  • getAccount(address: string): Account | undefined
  • Get Account instance using address as param

    example
    const key_1 = '45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e';
    wallet.addByPrivateKey(key_1);
    console.log(wallet.getAccount('one103q7qe5t2505lypvltkqtddaef5tzfxwsse4z7'));

    Parameters

    • address: string

      address hex

    Returns Account | undefined

    Account instance which lives in Wallet

newMnemonic

  • newMnemonic(): string
  • function

    newMnemonic

    memberof

    Wallet

    Returns string

    Mnemonics

removeAccount

  • removeAccount(address: string): void
  • function

    removeAccount

    memberof

    Wallet

    description

    remove Account using address as param

    Parameters

    • address: string

    Returns void

setMessenger

  • Set Customer Messenage

    example
    const customMessenger = new Messenger(
      new HttpProvider('https://api.s0.b.hmny.io'),
      ChainType.Harmony, // if you are connected to Harmony's blockchain
      ChainID.HmyLocal, // check if the chainId is correct
    )
    const wallet = new Wallet();
    wallet.setMessenger(customMessenger);
    console.log(wallet.messenger);

    Parameters

    Returns void

setSigner

  • setSigner(address: string): void
  • Set signer

    Parameters

    • address: string

      one of the address in the accounts

    Returns void

signStaking

  • signStaking(staking: StakingTransaction, account?: Account | undefined, password?: string | undefined, updateNonce?: boolean, encodeMode?: string, blockNumber?: string, shardID?: number): Promise<StakingTransaction>
  • Parameters

    • staking: StakingTransaction
    • Default value account: Account | undefined = this.signer
    • Default value password: string | undefined = undefined
    • Default value updateNonce: boolean = true
    • Default value encodeMode: string = "rlp"
    • Default value blockNumber: string = "latest"
    • Default value shardID: number = this.messenger.currentShard

    Returns Promise<StakingTransaction>

signTransaction

  • signTransaction(transaction: Transaction, account?: Account | undefined, password?: string | undefined, updateNonce?: boolean, encodeMode?: string, blockNumber?: string): Promise<Transaction>
  • Parameters

    • transaction: Transaction
    • Default value account: Account | undefined = this.signer
    • Default value password: string | undefined = undefined
    • Default value updateNonce: boolean = true
    • Default value encodeMode: string = "rlp"
    • Default value blockNumber: string = "latest"

    Returns Promise<Transaction>

Static generateMnemonic

  • generateMnemonic(): string
  • Returns string

Generated using TypeDoc