Options
All
  • Public
  • Public/Protected
  • All
Menu

ternoa-js

Index

Functions

  • batchAllTx(txHexes: `0x${string}`[]): Promise<SubmittableExtrinsic<"promise", ISubmittableResult>>
  • name

    batchAllTx

    summary

    Create a batchAll transaction of dispatch calls.

    Parameters

    • txHexes: `0x${string}`[]

      Transactions to execute in the batch call

    Returns Promise<SubmittableExtrinsic<"promise", ISubmittableResult>>

    Submittable extrinsic unsigned

  • batchAllTxHex(txHexes: `0x${string}`[]): Promise<`0x${string}`>
  • name

    batchAllTxHex

    summary

    Create a batchAll transaction of dispatch calls in hex format.

    Parameters

    • txHexes: `0x${string}`[]

      Transactions to execute in the batch call

    Returns Promise<`0x${string}`>

    Hex of the submittable extrinsic unsigned

  • batchTx(txHexes: `0x${string}`[]): Promise<SubmittableExtrinsic<"promise", ISubmittableResult>>
  • name

    batchTx

    summary

    Create a batch transaction of dispatch calls.

    Parameters

    • txHexes: `0x${string}`[]

      Transactions to execute in the batch call

    Returns Promise<SubmittableExtrinsic<"promise", ISubmittableResult>>

    Submittable extrinsic unsigned

  • batchTxHex(txHexes: `0x${string}`[]): Promise<`0x${string}`>
  • name

    batchTxHex

    summary

    Create a batch transaction of dispatch calls in hex format.

    Parameters

    • txHexes: `0x${string}`[]

      Transactions to execute in the batch call

    Returns Promise<`0x${string}`>

    Hex of the submittable extrinsic unsigned

  • checkBalanceForTransfer(address: string, value: number | BN): Promise<void>
  • name

    checkBalanceForTransfer

    summary

    Check if an account as enough funds to ensure a transfer

    Parameters

    • address: string

      Public address of the account to check balance for transfer

    • value: number | BN

      Token amount to transfer

    Returns Promise<void>

  • checkFundsForTxFees(tx: SubmittableExtrinsic<"promise", ISubmittableResult>): Promise<void>
  • name

    checkFundsForTxFees

    summary

    Check if a signed transaction sender has enough funds to pay transaction gas fees on transaction submit.

    Parameters

    • tx: SubmittableExtrinsic<"promise", ISubmittableResult>

      Signed transaction object

    Returns Promise<void>

  • checkTxAvailable(txPallet: string, txExtrinsic: string): Promise<boolean>
  • name

    checkTxAvailable

    summary

    Check if the pallet module and the subsequent extrinsic method exist in the Api instance.

    Parameters

    • txPallet: string

      Pallet module of the transaction

    • txExtrinsic: string

      Subsequent extrinsic method of the transaction

    Returns Promise<boolean>

    Boolean, true if the pallet module and the subsequent extrinsic method exist, throw an Error otherwise

  • consts(section: string, constantName: string): Promise<Codec>
  • name

    consts

    summary

    Generic function to get a chain constant.

    example

    console.log(api.consts.balances.existentialDeposit.toString())
    

    Parameters

    • section: string

      The section required to get the chain constant (eg. "balances")

    • constantName: string

      The constantName depending on the section (eg. "existentialDeposit")

    Returns Promise<Codec>

    The constant value

  • createTxHex(txPallet: string, txExtrinsic: string, txArgs?: any[]): Promise<`0x${string}`>
  • name

    createTxHex

    summary

    Create a transaction in hex format.

    Parameters

    • txPallet: string

      Pallet module of the transaction

    • txExtrinsic: string

      Subsequent extrinsic method of the transaction

    • txArgs: any[] = []

      Arguments of the transaction

    Returns Promise<`0x${string}`>

    Hex value of the transaction

  • generateSeed(): Promise<{ address: string; seed: string }>
  • name

    generateSeed

    summary

    Generate a new account

    Returns Promise<{ address: string; seed: string }>

    An object with the seed and the public address

  • getApi(): Promise<ApiPromise>
  • name

    getApi

    summary

    Get initialized substrate Api instance.

    Returns Promise<ApiPromise>

    Promise containing the actual Api instance, a wrapper around the RPC and interfaces of the chain.

  • getApiEndpoint(): Promise<string>
  • name

    getApiEndpoint

    summary

    Provides the wss api endpoint

    Returns Promise<string>

    String, the api endpoint connected with.

  • getBalance(address: string): Promise<BN>
  • name

    getBalance

    summary

    Get the free balance of an account

    Parameters

    • address: string

      Public address of the account to get free balance for

    Returns Promise<BN>

    The free balance of the account

  • getCapsuleMintFee(): Promise<BN>
  • name

    getCapsuleMintFee

    summary

    Get the amount of caps needed to mint a capsule.

    Returns Promise<BN>

    Capsule mint fee

  • getKeyringFromSeed(seed: string): Promise<KeyringPair>
  • name

    getKeyringFromSeed

    summary

    Create a keyring from a seed

    Parameters

    • seed: string

    Returns Promise<KeyringPair>

    A keyring pair

  • getMarketplaceMintFee(): Promise<BN>
  • name

    getMarketplaceMintFee

    summary

    Get the amount of caps needed to mint a marketplace.

    Returns Promise<BN>

    Marketplace mint fee

  • getNftMintFee(): Promise<BN>
  • name

    getNftMintFee

    summary

    Get the amount of caps needed to mint an NFT.

    Returns Promise<BN>

    NFT mint fee

  • getTxFees(txHex: `0x${string}`, address: string): Promise<BN>
  • name

    getTxFees

    summary

    Get the total fees for a transaction hex.

    Parameters

    • txHex: `0x${string}`

      Hex of the transaction

    • address: string

      Public address of the sender

    Returns Promise<BN>

    Total estimated fee which is the sum of the chain gas fee and the treasury fee

  • getTxGasFee(txHex: `0x${string}`, address: string): Promise<Balance>
  • name

    getTxGasFee

    summary

    Get the gas fee estimation for a transaction.

    Parameters

    • txHex: `0x${string}`

      Transaction hex

    • address: string

      Public address of the sender

    Returns Promise<Balance>

    Transaction fee estimation

  • getTxTreasuryFee(txHex: `0x${string}`): Promise<BN>
  • name

    getTxTreasuryFee

    summary

    Get the fee needed by Ternoa treasury for specific transaction services.

    description

    Some Ternoa's services required additional fees on top of chain gas fees, for example: minting a marketplace, minting an NFT or creating a capsule.

    Parameters

    • txHex: `0x${string}`

      Transaction hex

    Returns Promise<BN>

    Fee estimation

  • initializeApi(chain?: string): Promise<void>
  • name

    initializeApi

    summary

    Initialize substrate api with selected or default wss endpoint.

    description

    The default chainEndpoint is "wss://staging.chaos.ternoa.com"

    Parameters

    • chain: string = chainEndpoint

      Chain endpoint

    Returns Promise<void>

  • isApiConnected(): boolean
  • name

    isApiConnected

    summary

    Check if the Api instance existed and if it is connected.

    Returns boolean

    Boolean, true if the underlying provider is connected, false otherwise

  • isTransactionSuccess(result: ISubmittableResult): { indexInterrupted?: number; success: boolean }
  • name

    isTransactionSuccess

    summary

    Check if a transaction result is successful.

    Parameters

    • result: ISubmittableResult

      Generic result passed as a parameter in a transaction callback

    Returns { indexInterrupted?: number; success: boolean }

    Object containing a boolean success field indicating if transaction is successful and a indexInterrupted field to indicate where the transaction stopped in case of a batch

    • Optional indexInterrupted?: number
    • success: boolean
  • isValidAddress(address: string): boolean
  • name

    isValidAddress

    summary

    Check if an address is a valid Ternoa address.

    Parameters

    • address: string

    Returns boolean

    Boolean, true if the address is valid, false otherwise

  • query(module: string, call: string, args?: any[], callback?: (result: any) => void): Promise<Codec>
  • name

    query

    summary

    Generic function to make a chain query.

    example

    // you can query without any args
    const data = await query('balances', 'totalIssuance');

    // or you can pass args parameters to the storage query
    const data = await query('system', 'account', ['5GesFQSwhmuMKAHcDrfm21Z5xrq6kW93C1ch2Xosq1rXx2Eh']);

    Parameters

    • module: string

      The section required to make the chain query (eg. "system")

    • call: string

      The call depending on the section (eg. "account")

    • args: any[] = []

      Array of args for the call

    • Optional callback: (result: any) => void

      Callback function to enable subscription, if not given, no subscription will be made

        • (result: any): void
        • Parameters

          • result: any

          Returns void

    Returns Promise<Codec>

    Result of the query storage call

  • runTx(txPallet: string, txExtrinsic: string, txArgs: any[], keyring?: IKeyringPair, callback?: (result: ISubmittableResult) => void): Promise<`0x${string}`>
  • name

    runTx

    summary

    Create, sign and submit a transaction on blockchain.

    Parameters

    • txPallet: string

      Pallet module of the transaction

    • txExtrinsic: string

      Subsequent extrinsic method of the transaction

    • txArgs: any[]

      Arguments of the transaction

    • Optional keyring: IKeyringPair

      Keyring pair to sign the data, if not given, an unsigned transaction to be signed will be returned

    • Optional callback: (result: ISubmittableResult) => void

      Callback function to enable subscription, if not given, no subscription will be made

        • (result: ISubmittableResult): void
        • Parameters

          • result: ISubmittableResult

          Returns void

    Returns Promise<`0x${string}`>

    Hash of the transaction, or an unsigned transaction to be signed if no keyring pair is passed

  • safeDisconnect(): Promise<void>
  • name

    safeDisconnect

    summary

    Disconnect safely from the underlying provider, halting all network traffic

    Returns Promise<void>

  • signTx(keyring: IKeyringPair, txHex: `0x${string}`): Promise<`0x${string}`>
  • name

    signTx

    summary

    Sign a transaction.

    Parameters

    • keyring: IKeyringPair

      Keyring pair to sign the data

    • txHex: `0x${string}`

      Tx hex of the unsigned transaction to be signed

    Returns Promise<`0x${string}`>

    Hex value of the signed transaction

  • submitTx(txHex: `0x${string}`, callback?: (result: ISubmittableResult) => void): Promise<`0x${string}`>
  • name

    submitTx

    summary

    Send a signed transaction on the blockchain.

    Parameters

    • txHex: `0x${string}`

      Transaction hex of the signed transaction to be submitted

    • Optional callback: (result: ISubmittableResult) => void

      Callback function to enable subscription, if not given, no subscription will be made

        • (result: ISubmittableResult): void
        • Parameters

          • result: ISubmittableResult

          Returns void

    Returns Promise<`0x${string}`>

    Hash of the transaction

  • transfer(from: string, to: string, value: number | BN, keyring?: IKeyringPair, callback?: (result: ISubmittableResult) => void): Promise<`0x${string}`>
  • name

    transfer

    summary

    Transfer some liquid free balance to another account

    Parameters

    • from: string

      Public address of the account to get balance for

    • to: string

      Public address of the account to transfer amount to

    • value: number | BN

      Token amount to transfer

    • Optional keyring: IKeyringPair

      Keyring pair to sign the data

    • Optional callback: (result: ISubmittableResult) => void

      Callback function to enable subscription, if not given, no subscription will be made

        • (result: ISubmittableResult): void
        • Parameters

          • result: ISubmittableResult

          Returns void

    Returns Promise<`0x${string}`>

    Hash of the transaction or the hex value of the signable tx

  • transferAll(to: string, keepAlive?: boolean, keyring?: IKeyringPair, callback?: (result: ISubmittableResult) => void): Promise<`0x${string}`>
  • name

    transferAll

    summary

    Transfer the entire transferable balance from the caller account

    Parameters

    • to: string

      Public address of the account to transfer amount to

    • keepAlive: boolean = true

      Ensure that the transfer does not kill the account, it retains the Existential Deposit

    • Optional keyring: IKeyringPair

      Keyring pair to sign the data

    • Optional callback: (result: ISubmittableResult) => void

      Callback function to enable subscription, if not given, no subscription will be made

        • (result: ISubmittableResult): void
        • Parameters

          • result: ISubmittableResult

          Returns void

    Returns Promise<`0x${string}`>

    Hash of the transaction or the hex value of the signable tx

  • transferKeepAlive(from: string, to: string, value: number | BN, keyring?: IKeyringPair, callback?: (result: ISubmittableResult) => void): Promise<`0x${string}`>
  • name

    transferKeepAlive

    summary

    Transfer some liquid free balance to another account with a check that the transfer will not kill the origin account

    Parameters

    • from: string

      Public address of the account to get balance for

    • to: string

      Public address of the account to transfer amount to

    • value: number | BN

      Token amount to transfer

    • Optional keyring: IKeyringPair

      Keyring pair to sign the data

    • Optional callback: (result: ISubmittableResult) => void

      Callback function to enable subscription, if not given, no subscription will be made

        • (result: ISubmittableResult): void
        • Parameters

          • result: ISubmittableResult

          Returns void

    Returns Promise<`0x${string}`>

    Hash of the transaction or the hex value of the signable tx

  • unFormatBalance(_input: number): Promise<BN>
  • name

    unFormatBalance

    summary

    Format balance from number to BN.

    Parameters

    • _input: number

      Number input

    Returns Promise<BN>

    BN output

Generated using TypeDoc