Options
All
  • Public
  • Public/Protected
  • All
Menu

Class API

Hierarchy

  • API

Index

Constructors

constructor

  • Initaliizes a new API object, you need to provide the URL of a Convex Network Node.

    example
    const convex = API.create('https://convex.world')

    Parameters

    • url: string

      URL of the convex network node.

    • Optional language: Language

    Returns API

Properties

language

language: Language

Default language to use

Readonly registry

registry: Registry

Registry used to resolve account names

Readonly url

url: string

URL of the network

Methods

createAccount

  • Create a new account address with the convex network. You can provide an already existing account Public/Private keys or leave empty, and a new Account will be created.

    example
    // create a new account with a random keys and new address
    const newAccount = await convex.createAccount()
    
    // Create an account with our own keys, but with a new address
    keyPair = KeyPair.importFromFile('my-account.pem', 'secret')
    const accountWithNewAddress = await convex.createAccount(keyPair)

    Parameters

    • keyPair: KeyPair
    • Optional name: string

    Returns Promise<Account>

    An Account object with a new account address.

Protected do_transaction_get

  • do_transaction_get(name: string, url: string): Promise<unknown>
  • Parameters

    • name: string
    • url: string

    Returns Promise<unknown>

Protected do_transaction_post

  • do_transaction_post(name: string, url: string, data: unknown): Promise<unknown>
  • Parameters

    • name: string
    • url: string
    • data: unknown

    Returns Promise<unknown>

getAccountInfo

  • Request account information, from the convex network.

    example
     await convex.getAccountInfo(account)
    
     {
         "address": "405",
         "is_library": false,
         "is_actor": false,
         "memory_size": 75,
         "allowance": 10000000,
         "type": "user",
         "balance": 10000000000,
         "sequence": 0,
         "environment": {}
    }
    

    Parameters

    • addressAccount: Account | BigInt | number | string

      Account or address BigInt to use as the query the account.

    Returns Promise<IAccountInformation>

    The account information of the type IAccountInformation, for example:

getAddress

  • getAddress(functionName: string, addressAccount: Account | BigInt | number | string): Promise<string>
  • Get the address of a deployed function. The function must be owned by the account address passed, for this method to work.

    Parameters

    • functionName: string

      The deployed function go get the address off.

    • addressAccount: Account | BigInt | number | string

      Account or address BigInt to use as the query address. This address is the address used by the owner of the deployed function

    Returns Promise<string>

    The address of the deployed function

getBalance

  • getBalance(addressAccount: Account | BigInt | number | string): Promise<BigInt>
  • Get the current balance of an account.

    example
    
    const balance = await convex.balance(account)
    console.log(`balance of ${balance} for account at address ${account.address}`)
    
    const sameBalance = await convex.balance(account.address)
    console.log(`balance of ${sameBalance} for account at address ${account.address}`)
    
    const mainFundBalance = await convex.balance(9)
    console.log(`main fund balance of ${mainFundBalance} for address #9`)

    Parameters

    • addressAccount: Account | BigInt | number | string

      Account object or BigInt address of the account to get the balance.

    Returns Promise<BigInt>

    The balance of funds held by the account address.

loadAccount

  • Loads an account using the account name. The name must be registered by using registerAccountName or the accountSetup method.

    example
    // get the current account keys we need to use
    const keyPair = await KeyPair.importFromFile('account_file.pem', 'secret')
    
    // load the account from an account name already registered.
    const account = await convex.loadAccount('my-account-name', keyPair)
    

    Parameters

    Returns Promise<Account>

    An Account object with the account name and adderss set.

query

  • query(transaction: string, addressAccount: Account | BigInt | number | string, language?: Language): Promise<unknown>
  • Send a query transaction to the network. A query transaction does not change the network state and so does not need any funds to perform a transaction. Possible query transactions are balance query, address query and calling read operations in contracts.

    prama

    addressAccount Address BigInt or Account object to use for the query transaction.

    example
    const resultQuery = await convex.query('(balance *address*)', account.address)
    consol.log(`Result from a query ${resultQuery}`)

    Parameters

    • transaction: string

      Read only transaction to perform.

    • addressAccount: Account | BigInt | number | string
    • Optional language: Language

    Returns Promise<unknown>

    The query results.

registerAccountName

  • registerAccountName(name: string, account: Account, ownerAddressAccount?: Account | BigInt | number | string): Promise<Account>
  • Register an account name with the CNS ( Convex Named Service), this name can be used in the convex sandbox or used by the API libraries to resolve an account name to an account address.

    example
    // load the account from an account name already registered.
    const registerAccount = await convex.loadAccount('my-registration-account', keyPair)
    
    // create a new account with a new address
    let newAccount = await convex.createAccount(keyPair)
    
    // now we can register the name for the new account, by paying for the fees from the registerAccount
    newAccount = await convex.registerAccountName('my-new-name', registerAccount, newAccount.address)
    

    Parameters

    • name: string
    • account: Account
    • Optional ownerAddressAccount: Account | BigInt | number | string

    Returns Promise<Account>

    an account object with the address set

requestFunds

  • requestFunds(amount: BigInt | number, account: Account): Promise<BigInt>
  • Request funds from the development account. This method only works on development and test networks that provide free funds.

    example
    const fundsRequested = await convex.requestFunds(100000, account)
    console.log(`requested ${fundsRequested} funds for account at address ${account.address}`)

    Parameters

    • amount: BigInt | number

      The amount to request.

    • account: Account

      The Account object to request funds for.

    Returns Promise<BigInt>

    The amount of funds provided for this request.

resolveAccountName

  • resolveAccountName(name: string): Promise<BigInt>
  • Resolve an account name, if found return the account address registered with this account name.

    example
    // resolve to find the address of an account
    const accountAddress = await convex.resolveAccountName('my-account')
    

    Parameters

    • name: string

      Name of the registered account

    Returns Promise<BigInt>

    Address of the registered account or nil

resolveName

  • resolveName(name: string): Promise<BigInt>
  • Resolve a name, if found return the address registered with this name in the Convex Name Services.

    example
    // resolve to find the address of a library or actor
    const nftTokenLibraryAddress = await convex.resolveName('covex.nft-token')
    

    Parameters

    • name: string

      Name of the service

    Returns Promise<BigInt>

    Address of the registered service

send

  • send(transaction: string, account: Account, language?: Language): Promise<unknown>
  • Send a transaction to the network. This assumes that the network state will change, and as a result a transaction fee will be deducted from the account.

    example
    const resultSend = await convex.send('(map inc [1 2 3 4 5])', account)
    consol.log(`Result from calculation ${resultSend}`)

    Parameters

    • transaction: string

      State changing transaction to execute.

    • account: Account

      Account to sign the transaction.

    • Optional language: Language

    Returns Promise<unknown>

    The result from executing the transaction.

setupAccount

  • Setup an account by registering the account name or by loading the account using a pre registered name.

    example
    // get the current account keys we need to use
    const keyPair = await KeyPair.importFromFile('account_file.pem', 'secret')
    
    // creates a new account address or loads the account from an account name already registered.
    const account = await convex.setupAccount('my-account-name', keyPair)
    

    Parameters

    Returns Promise<Account>

    An Account object with the account name and adderss set.

topupAccount

  • topupAccount(account: Account, minBalance?: BigInt, retryCount?: number): Promise<BigInt>
  • Topup account to a minimum balance

    example
    const amount = await convex.topupAccount(account)
    console.log(`${amount} tokens was topped up to account at address ${account.address}`)

    Parameters

    • account: Account

      The convex account to topup

    • Optional minBalance: BigInt

      The minimum balance the account should be topped too

    • Optional retryCount: number

      Number of times to try loop around and topup the account

    Returns Promise<BigInt>

    the amount of funds transfered to the account

Protected transaction_prepare

  • transaction_prepare(address: BigInt, transaction: string, language: Language, sequenceNumber?: BigInt): Promise<unknown>
  • Parameters

    • address: BigInt
    • transaction: string
    • language: Language
    • Optional sequenceNumber: BigInt

    Returns Promise<unknown>

Protected transaction_query

  • transaction_query(address: BigInt, transaction: string, language: Language): Promise<unknown>
  • Parameters

    • address: BigInt
    • transaction: string
    • language: Language

    Returns Promise<unknown>

Protected transaction_submit

  • transaction_submit(address: BigInt, publicKey: string, hashData: string, signedData: string): Promise<unknown>
  • Parameters

    • address: BigInt
    • publicKey: string
    • hashData: string
    • signedData: string

    Returns Promise<unknown>

transfer

  • transfer(sendToAddressAccount: Account | BigInt | number | string, amount: BigInt | number, fromAccount: Account): Promise<BigInt>
  • Transfer funds from one account to another.

    results

    The amount of funds transfered.

    example
    // load the account from an account name already registered.
    const fundingAccount = await convex.loadAccount('my-funding-account', keyPair)
    const newAccount = await convex.createAccount(keyPair)
    
    // send 1000000 tokens from the fundingAccount to the newAccount
    const amount = await convex.transfer(newAccount, 1000000, fundingAccount)
    
    

    Parameters

    • sendToAddressAccount: Account | BigInt | number | string

      To address an Account, BigInt, number or string , that the funds need to be sent too.

    • amount: BigInt | number

      Amount to send for the transfer.

    • fromAccount: Account

      Account to send the funds from. This must be an account object so that the transfer transaction can be sent from the account.

    Returns Promise<BigInt>

Static create

Generated using TypeDoc