Hierarchy

  • Algonaut

Constructors

  • Instantiates Algonaut.js.

    Parameters

    Returns Algonaut

    Example

    Usage:

    import { Algonaut } from '@thencc/algonautjs';
    const algonaut = new Algonaut({
    nodeConfig: {
    BASE_SERVER: 'https://testnet-algorand.api.purestake.io/ps2',
    INDEX_SERVER: 'https://testnet-algorand.api.purestake.io/idx2'
    LEDGER: 'TestNet',
    PORT: '',
    API_TOKEN: { 'X-API-Key': 'YOUR_API_TOKEN' }
    }
    });

Properties

account: null | Account = ...
algodClient: default
connect: (<W, P>(wId, wInitParams?) => Promise<Account[]>)

Type declaration

    • <W, P>(wId, wInitParams?): Promise<Account[]>
    • connects the given wallet + optional init params

      Type Parameters

      • W extends W_ID

      • P extends undefined | string | boolean | {
            config?: InkeyConfig;
            id?: "inkey";
            sdk?: {
                frameBus: FrameBus;
                connect(payload?) => Promise<InkeyAccount[]>;
                disconnect() => Promise<InkeyResponseBase>;
                hide() => void;
                ping<R, T>(data, options?) => Promise<R>;
                show(routepath?) => void;
                signTxns(txns, connectedAccounts?) => Promise<InkeySignTxnResponse>;
                signTxnsUint8Array(txns, connectedAccounts?) => Promise<InkeySignTxnResponse>;
            };
        } | {
            config?: SdkConfig$6;
            id?: "pera";
            sdk?: PeraSdk;
        } | {
            config?: SdkConfig$4;
            id?: "myalgo";
            sdk?: default;
        } | {
            config?: SdkConfig$3;
            id?: "algosigner";
            sdk?: AlgoSignerSdk;
        } | {
            config?: SdkConfig$2;
            id?: "exodus";
            sdk?: ExodusSdk;
        } | {
            config?: SdkConfig$1;
            id?: "defly";
            sdk?: DeflySdk;
        } | {
            config?: SdkConfig;
            id?: "mnemonic";
            sdk?: default;
        }

      Parameters

      • wId: W
      • Optional wInitParams: P

      Returns Promise<Account[]>

      an array of connected accounts

      Argument

      walletId of which wallet type to connect

disconnect: (<W>(wId) => Promise<void>)

Type declaration

    • <W>(wId): Promise<void>
    • Type Parameters

      Parameters

      • wId: W

      Returns Promise<void>

disconnectAll: (() => Promise<void>)

Type declaration

    • (): Promise<void>
    • Returns Promise<void>

indexerClient: undefined | default = ...
inkeyClientSdk: null | {
    frameBus: FrameBus;
    connect(payload?) => Promise<InkeyAccount[]>;
    disconnect() => Promise<InkeyResponseBase>;
    hide() => void;
    ping<R, T>(data, options?) => Promise<R>;
    show(routepath?) => void;
    signTxns(txns, connectedAccounts?) => Promise<InkeySignTxnResponse>;
    signTxnsUint8Array(txns, connectedAccounts?) => Promise<InkeySignTxnResponse>;
} = ...

Type declaration

  • frameBus: FrameBus
  • connect:function
    • Opens Inkey to allow users to create an account or login with a previously created account. Must be called before transactions can be signed.

      Parameters

      • Optional payload: {
            connectedAccounts?: InkeyAccount[];
            siteName?: string;
        }

        Optional payload object, can contain siteName parameter to display the name of the application.

        • Optional connectedAccounts?: InkeyAccount[]
        • Optional siteName?: string

      Returns Promise<InkeyAccount[]>

      Promise resolving to an account object of type { account: string, username: string }[] // return array because we will support arrays of accounts in the future even if we always return 1 for now

  • disconnect:function
    • Tells Inkey to close your session & clear local storage.

      Returns Promise<InkeyResponseBase>

      Success or fail message

  • hide:function
    • Hides the Inkey wallet frame

      Returns void

  • ping:function
    • Sends messages to Inkey via FrameBus

      Type Parameters

      • R = any

      • T = undefined

      Parameters

      • data: any

        Message to send

      • Optional options: {
            showFrame?: boolean;
        }
        • Optional showFrame?: boolean

      Returns Promise<R>

      Whatever Inkey gives us

  • show:function
    • Shows the Inkey wallet frame

      Parameters

      • Optional routepath: string

      Returns void

  • signTxns:function
    • Sends unsigned transactions to Inkey, awaits signing, returns signed txns

      Parameters

      • txns: string[] | TxnForSigning[]

        Array of base64 encoded transactions OR more complex obj array w txn signing type needed

      • Optional connectedAccounts: InkeyAccount[]

      Returns Promise<InkeySignTxnResponse>

      Promise resolving to response object containing signedTxns if successful. Otherwise, provides error or reject properties. { success, reject, error, signedTxns }

  • signTxnsUint8Array:function
    • Signs unsigned transactions, returns signed txns

      Parameters

      • txns: Uint8Array[]

        Array of Uint8Array encoded transactions

      • Optional connectedAccounts: InkeyAccount[]

      Returns Promise<InkeySignTxnResponse>

      Promise resolving to response object containing signedTxns if successful. Otherwise, provides error or reject properties. { success, reject, error, signedTxns }

inkeyLoaded: boolean = false
inkeyLoading: boolean = false
libConfig: {
    disableLogs: boolean;
} = defaultLibConfig

Type declaration

  • disableLogs: boolean
nodeConfig: {
    API_TOKEN: any;
    BASE_SERVER: string;
    INDEX_SERVER?: string;
    LEDGER: string;
    PORT: string;
} = defaultNodeConfig

Type declaration

  • API_TOKEN: any
  • BASE_SERVER: string
  • Optional INDEX_SERVER?: string
  • LEDGER: string
  • PORT: string
sdk: __module = algosdk
setActiveAccount: ((acct) => void)

Type declaration

    • (acct): void
    • Parameters

      Returns void

subscribeToAccountChanges: ((handler, opts?) => (() => void))

Type declaration

    • (handler, opts?): (() => void)
    • Parameters

      • handler: ((a) => void)
          • (a): void
          • Parameters

            Returns void

      • Optional opts: {
            callOnSet: boolean;
        }
        • callOnSet: boolean

      Returns (() => void)

        • (): void
        • Returns void

walletState: AnyWalletState

Accessors

Methods

  • Checks if account has at least one token (before playback) Keeping this here in case this is a faster/less expensive operation than checking actual balance

    Parameters

    • address: string

      Address to check

    • assetIndex: number

      the index of the ASA

    Returns Promise<boolean>

  • Used for decoding state

    Parameters

    • encoded: string

      Base64 string

    Returns string

    Human-readable string

  • Checks status of Algorand network

    Returns Promise<any>

    Promise resolving to status of Algorand network

  • Compiles TEAL source via algodClient.compile

    Parameters

    • programSource: string

      source to compile

    Returns Promise<Uint8Array>

    Promise resolving to Buffer of compiled bytes

  • Creates a wallet address + mnemonic from account's secret key. Changed in 0.3: this does NOT set algonaut.account.

    Returns AlgonautWallet

    AlgonautWallet Object containing address and mnemonic

  • Does what it says on the tin.

    Parameters

    • txn: string

      base64-encoded unsigned transaction

    Returns Transaction

    transaction object

  • Sync function that returns a correctly-encoded argument array for an algo transaction

    Parameters

    • args: any[]

      must be an any[] array, as it will often need to be a mix of strings and numbers. Valid types are: string, number, and bigint

    Returns Uint8Array[]

    a Uint8Array of encoded arguments

  • Parameters

    • encoded: string

      Base64 string

    Returns string

    Human-readable string

    Deprecated

    Use b64StrToHumanStr instead

  • Creates a LogicSig from a base64 program string. Note that this method does not COMPILE the program, just builds an LSig from an already compiled base64 result!

    Parameters

    • base64ProgramString: string

    Returns LogicSigAccount

    an algosdk LogicSigAccount

  • Fetch full account info for an account

    Parameters

    • address: string

      the accress to read info for

    Returns Promise<any>

    Promise of type AccountInfo

  • Checks Algo balance of account

    Parameters

    • address: string

      Wallet of balance to check

    Returns Promise<any>

    Promise resolving to Algo balance

  • Get an application's escrow account

    Parameters

    • appId: number | bigint

      ID of application

    Returns string

    Escrow account address as string

  • Gets global state for an application.

    Parameters

    • applicationIndex: number

      the applications index

    Returns Promise<any>

    object representing global state

  • Get info about an application (globals, locals, creator address, index)

    Parameters

    • appId: number

      ID of application

    Returns Promise<AlgonautAppState>

    Promise resolving to application state

  • Gets account local state for an app. Defaults to AnyWallets.activeAddress unless an address is provided.

    Parameters

    • applicationIndex: number

      the applications index

    • Optional address: string

    Returns Promise<void | AlgonautAppState>

  • Get info about an asset

    Parameters

    • assetIndex: number

    Returns Promise<any>

  • Loads and/or returns the inkey-wallet client sdk for whatever use. see inkey-client-js docs for more.

    Returns Promise<{
        frameBus: FrameBus;
        connect(payload?) => Promise<InkeyAccount[]>;
        disconnect() => Promise<InkeyResponseBase>;
        hide() => void;
        ping<R, T>(data, options?) => Promise<R>;
        show(routepath?) => void;
        signTxns(txns, connectedAccounts?) => Promise<InkeySignTxnResponse>;
        signTxnsUint8Array(txns, connectedAccounts?) => Promise<InkeySignTxnResponse>;
    }>

  • Returns undefined | boolean | {
        API_TOKEN: any;
        BASE_SERVER: string;
        INDEX_SERVER?: string;
        LEDGER: string;
        PORT: string;
    }

    nodeConfig object or false if no nodeConfig is set

  • Checks token balance of account

    Parameters

    • address: string

      Wallet of balance to check

    • assetIndex: number

      the ASA index

    Returns Promise<number>

    Promise resolving to token balance

  • Returns Promise<Account[]>

    Deprecated

    use .connect or loop through enabled wallets' methods

  • Returns Promise<void>

    Deprecated

    use .disconnect or loop through enabled wallets' methods

  • Hides the inkey-wallet modal

    Returns Promise<void>

  • Shows the inkey-wallet modal

    Parameters

    • Optional route: string

    Returns Promise<void>

  • You can be opted into an asset but still have a zero balance. Use this call for cases where you just need to know the address's opt-in state

    Parameters

    • args: {
          account: string;
          assetId: number;
      }

      object containing account and assetId properties

      • account: string
      • assetId: number

    Returns Promise<boolean>

    boolean true if account holds asset

  • checks if config obj is valid for use

    Parameters

    • Optional nodeConfig: {
          API_TOKEN: any;
          BASE_SERVER: string;
          INDEX_SERVER?: string;
          LEDGER: string;
          PORT: string;
      }
      • API_TOKEN: any
      • BASE_SERVER: string
      • Optional INDEX_SERVER?: string
      • LEDGER: string
      • PORT: string

    Returns boolean

    boolean. true is good.

  • Parameters

    • mnemonic: string

      Mnemonic associated with Algonaut account

    Returns Promise<Account[]>

    If mnemonic is valid, it returns the account (address, chain). Otherwise, throws an error.

    Deprecated

    use .connect() with mnemonic arg Recovers account from mnemonic (helpful for rapid development but overall very insecure unless on server-side)

  • Recovers account from mnemonic Changed in 0.3: this does NOT set algonaut.account.

    Parameters

    • mnemonic: string

      Mnemonic associated with Algonaut account

    Returns default

    If mnemonic is valid, returns algosdk account (.addr, .sk). Otherwise, throws an error.

  • sets config for use (new algod, indexerClient, etc)

    Parameters

    • Optional nodeConfig: {
          API_TOKEN: any;
          BASE_SERVER: string;
          INDEX_SERVER?: string;
          LEDGER: string;
          PORT: string;
      } | "testnet" | "mainnet"

    Returns void

  • Signs a transaction or multiple w the correct wallet according to AW (does not send / submit txn(s) to network)

    Parameters

    Returns Promise<Uint8Array[]>

    Promise resolving to AlgonautTransactionStatus

  • Helper function to turn globals and locals array into more useful objects

    Parameters

    • stateArray: object[]

      State array returned from functions like getAppInfo

    Returns any

    A more useful object: { array[0].key: array[0].value, array[1].key: array[1].value, ... } TODO add correct typing for this method

  • Parameters

    • str: string

      string

    • enc: BufferEncoding = 'utf8'

      the encoding type of the string (defaults to utf8)

    Returns Uint8Array

    string encoded as Uint8Array

    Deprecated

    use toUint8Array instead.

  • Parameters

    • str: string

      string

    • enc: BufferEncoding = 'utf8'

      the encoding type of the string (defaults to utf8)

    Returns Uint8Array

    string encoded as Uint8Array

  • txn(b64) -> txnBuff (buffer)

    Parameters

    • txn: string

      base64-encoded unsigned transaction

    Returns Buffer

    trransaction as buffer object

  • Converts between buff -> b64 (txns)

    Parameters

    • buff: Uint8Array

      likely a algorand txn as a Uint8Array buffer

    Returns string

    string (like for inkey / base64 transmit use)

  • Describes an Algorand transaction, for display in Inkey

    Parameters

    • txn: Transaction

      Transaction to describe

    Returns string

  • Does what it says on the tin.

    Parameters

    • txn: Transaction

      algorand txn object

    Returns string

    string (like for inkey / base64 transmit use)

  • Decodes a Base64-encoded Uint8 Algorand address and returns a string

    Parameters

    • encoded: string

      An encoded Algorand address

    Returns string

    Decoded address

  • General purpose method to await transaction confirmation

    Parameters

    • txId: string

      a string id of the transacion you want to watch

    • Optional limitDelta: number

      how many rounds to wait, defaults to 50

    • log: boolean = false

      set to true if you'd like to see "waiting for confirmation" log messages

    Returns Promise<AlgonautTransactionStatus>

Generated using TypeDoc