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
  • Get bech32 Address

    example
    console.log(account.bech32Address);

    Returns string

bech32TestNetAddress

  • get bech32TestNetAddress(): string
  • get Bech32 TestNet Address

    example
    console.log(account.bech32TestNetAddress);

    Returns string

checksumAddress

  • get checksumAddress(): string
  • check sum address

    example
    console.log(account.checksumAddress);

    Returns string

getShardsCount

  • get getShardsCount(): number
  • get Shards number with this Account

    example
    console.log(account.getShardsCount);

    Returns number

Methods

fromFile

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

    • keyStore: string
    • password: string

    Returns 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[]
  • Get all shards' addresses from the account

    example
    console.log(account.getAddresses());

    Returns string[]

getBalance

  • getBalance(blockNumber?: string): Promise<Balance>
  • 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<Balance>

getShardBalance

  • getShardBalance(shardID: number, blockNumber?: string): Promise<{ address: string; balance: any; 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: any; nonce: number }>

getShardNonce

  • getShardNonce(shardID: number, blockNumber?: string): Promise<any>
  • Get the specific shard's nonce

    example
    account.getShardNonce().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<any>

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

  • 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>
  • function

    signTransaction

    Parameters

    • transaction: Transaction
    • Default value updateNonce: boolean = true
    • Default value encodeMode: string = "rlp"
    • Default value blockNumber: string = "latest"

    Returns Promise<Transaction>

toFile

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

    • password: string
    • Optional options: EncryptOptions

    Returns Promise<string>

updateBalances

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

    updateShards

    Parameters

    • Default value blockNumber: string = "latest"

    Returns Promise<void>

Static add

  • Static Method: add a private key to Account

    example
    const account = new Account.add(key_1);
    console.log(account);

    Parameters

    • key: string

      private Key

    Returns Account

Static new

  • static method create account

    example
    const account = new Account();
    console.log(account);

    Returns Account

Generated using TypeDoc