Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • Account

Index

Constructors

constructor

  • Generate an account object

    example
    // import the Account class
    const { Account } = require('@harmony-js/account');
    
    // Messenger is optional, by default, we have a defaultMessenger
    // If you like to change, you will import related package here.
    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
    )
    
    // setMessenger later
    const randomAccount = new Account()
    randomAccount.setMessenger(customMessenger)
    
    // or you can set messenger on `new`
    const randomAccountWithCustomMessenger = new Account(undefined, customMessenger)
    
    // NOTED: Key with or without `0x` are accepted, makes no different
    // NOTED: DO NOT import `mnemonic phrase` using `Account` class, use `Wallet` instead
    const myPrivateKey = '0xe19d05c5452598e24caad4a0d85a49146f7be089515c905ae6a19e8a578a6930'
    const myAccountWithMyPrivateKey = new Account(myPrivateKey)

    Parameters

    • Optional key: string

      import an existing privateKey, or create a random one

    • Default value messenger: Messenger = defaultMessenger

      you can setMessage later, or set message on new

    Returns Account

Accessors

bech32Address

  • get bech32Address(): string

bech32TestNetAddress

  • get bech32TestNetAddress(): string

checksumAddress

  • get checksumAddress(): string

getShardsCount

  • get getShardsCount(): number

Methods

fromFile

  • fromFile(keyStore: string, password: string): Promise<Account>

getAddressFromShardID

  • getAddressFromShardID(shardID: number): string
  • Get account address from shard ID

    example
    console.log(account.getAddressFromShardID(0));
    
    > one103q7qe5t2505lypvltkqtddaef5tzfxwsse4z7-0

    Parameters

    • shardID: number

    Returns string

getAddresses

  • getAddresses(): string[]

getBalance

  • getBalance(blockNumber?: string): Promise<object>
  • Get the account balance

    example
    account.getBalance().then((value) => {
      console.log(value);
    });

    Parameters

    • Default value blockNumber: string = "latest"

      by default, it's latest

    Returns Promise<object>

getShardBalance

  • getShardBalance(shardID: number, blockNumber?: string): Promise<{ address: string; balance: string; nonce: number }>
  • Get the specific shard's balance

    example
    account.getShardBalance().then((value) => {
      console.log(value);
    });

    Parameters

    • shardID: number

      shardID is binding with the endpoint, IGNORE it!

    • Default value blockNumber: string = "latest"

      by default, it's latest

    Returns Promise<{ address: string; balance: string; nonce: number }>

setMessenger

  • example
    // 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
    )
    
    // to create an Account with random privateKey
    // and you can setMessenger later
    const randomAccount = new Account()
    randomAccount.setMessenger(customMessenger)

    Parameters

    Returns void

signStaking

  • signStaking(staking: StakingTransaction, updateNonce?: boolean, encodeMode?: string, blockNumber?: string, shardID?: number): Promise<StakingTransaction>
  • This function is still in development, coming soon!

    Parameters

    • staking: StakingTransaction
    • 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, updateNonce?: boolean, encodeMode?: string, blockNumber?: string): Promise<Transaction>

toFile

  • toFile(password: string, options?: EncryptOptions): Promise<string>

updateBalances

  • updateBalances(blockNumber?: string): Promise<void>

Static add

Static new

Generated using TypeDoc