Class default

A class for AI Network wallets.

Constructors

Properties

_length: number

The number of accounts.

accounts: Accounts

The list of accounts.

ain: default

The Ain object.

chainId: number

The chain ID of the blockchain.

defaultAccount: null | Account

The default account.

Accessors

  • get length(): number
  • Getter for the number of accounts in the wallet.

    Returns number

Methods

  • Converts an account into a v3 keystore and encrypts it with a password.

    Parameters

    • address: string

      The address of the account.

    • password: string

      The password.

    • options: V3KeystoreOptions = {}

      The v3 keystore options.

    Returns V3Keystore

    The v3 keystore.

  • Adds a new account from the given private key.

    Parameters

    • privateKey: string

      The private key.

    Returns string

    The address of the newly added account.

  • Adds a new account from the given private key and sets the new account as the default account.

    Parameters

    • privateKey: string

      The private key.

    Returns string

    The address of the newly added account.

  • Adds an account from a seed phrase. Only the account at the given index (default = 0) will be added.

    Parameters

    • seedPhrase: string

      The seed phrase.

    • index: number = 0

      The index of the account.

    Returns string

    The address of the newly added account.

  • Adds an account from a v3 keystore.

    Parameters

    • v3Keystore: string | V3Keystore

      The v3 keystore.

    • Optional password: string

      The password of the v3 keystore.

    Returns string

    The address of the newly added account.

  • Clears the wallet (remove all account information).

    Returns void

  • Creates new accounts and adds them to the wallet.

    Parameters

    • numberOfAccounts: number

      The number of accounts to create.

    Returns string[]

    The newly created accounts.

  • Fetches the AIN balance of the address.

    Parameters

    • Optional address: string

      The address of the account. It defaults to the default account of the wallet.

    Returns Promise<number>

    The AIN balance of the account.

  • Gets the hash from the signature.

    Parameters

    • signature: string

      The signature.

    Returns string

    The hash of the signature.

  • Returns the "implied" address. If address is not given, it returns the defaultAccount. It throws an error if an address is not given and defaultAccount is not set, or the specified address is not added to the wallet.

    Parameters

    • Optional inputAddress: string

    Returns string

  • Fetches an account's nonce value, which is the current transaction count of the account.

    Parameters

    • args: {
          address?: string;
          from?: string;
      }

      The ferch options. It may contain a string 'address' value and a string 'from' value. The 'address' is the address of the account to get the nonce of, and the 'from' is the source of the data. It could be either the pending transaction pool ("pending") or the committed blocks ("committed"). The default value is "committed".

      • Optional address?: string
      • Optional from?: string

    Returns Promise<number>

    The nonce value.

  • Returns the full public key of the given address.

    Parameters

    • address: string

    Returns string

  • Fetches an account's timestamp value, which is the timestamp of the last transaction signed by the account with nonce = -2.

    Parameters

    • args: {
          address?: string;
          from?: string;
      }

      The ferch options. It may contain a string 'address' value and a string 'from' value. The 'address' is the address of the account to get the timestamp of, and the 'from' is the source of the data. It could be either the pending transaction pool ("pending") or the committed blocks ("committed"). The default value is "committed".

      • Optional address?: string
      • Optional from?: string

    Returns Promise<number>

    The timestamp value.

  • Returns whether the address has already been added to the wallet.

    Parameters

    • address: string

      The address to check.

    Returns boolean

  • Recovers an address of the account that was used to create the signature.

    Parameters

    • signature: string

      The signature.

    Returns string

    The address recovered.

  • Removes an account from the wallet.

    Parameters

    • address: string

      The address of the account to be removed.

    Returns void

  • Removes a default account (sets it to null).

    Returns void

  • Sets the chain ID.

    Parameters

    • chainId: number

    Returns void

  • Sets the default account as {address}. The account should be already added in the wallet.

    Parameters

    • address: string

      The address of the account.

    Returns void

  • Signs a string data with the private key of the given address. It will use the default account if an address is not provided.

    Parameters

    • data: string

      The data to sign.

    • Optional address: string

      The address of the account. It defaults to the default account of the wallet.

    Returns string

    The signature.

  • Signs a transaction body with the private key of the given address. It will use the default account if an address is not provided.

    Parameters

    • txBody: TransactionBody

      The transaction body.

    • Optional address: string

      The address of the account. It defaults to the adefault account of the wallet..

    Returns string

    The signature.

  • Saves the accounts in the wallet as v3 keystores, locking them with the password.

    Parameters

    • password: string

      The password.

    • options: V3KeystoreOptions = {}

      The v3 keystore options.

    Returns V3Keystore[]

    The v3 keystores.

  • Sends a transfer transaction to the network.

    Parameters

    • input: {
          from?: string;
          gas_price?: number;
          nonce?: number;
          to: string;
          value: number;
      }

      The input parameters of the transaction.

      • Optional from?: string
      • Optional gas_price?: number
      • Optional nonce?: number
      • to: string
      • value: number
    • isDryrun: boolean = false

      The dryrun option.

    Returns Promise<any>

    The return value of the blockchain API.

  • Verifies if the signature is valid and was signed by the address.

    Parameters

    • data: any

      The data used in the signing.

    • signature: string

      The signature to verify.

    • address: string

      The address to verify.

    • Optional chainId: number

      The chain Id for test purposes only.

    Returns boolean

  • Counts the given number's decimals.

    Parameters

    • value: number

      The number.

    Returns number

    The decimal count.

  • Imports an account from a private key.

    Parameters

    • privateKey: Buffer

      The private key.

    Returns Account

    The account.