Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Algodv2

Algod client connects an application to the Algorand blockchain. The algod client requires a valid algod REST endpoint IP address and algod token from an Algorand node that is connected to the network you plan to interact with.

Algod is the main Algorand process for handling the blockchain. Messages between nodes are processed, the protocol steps are executed, and the blocks are written to disk. The algod process also exposes a REST API server that developers can use to communicate with the node and the network. Algod uses the data directory for storage and configuration information.

Relevant Information

How do I obtain an algod address and token?

Run Algod in Postman OAS3

Hierarchy

Index

Constructors

  • Create an AlgodClient from

    • either a token, baseServer, port, and optional headers
    • or a base client server for interoperability with external dApp wallets

    Example

    const token  = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
    const server = "http://localhost";
    const port = 4001;
    const algodClient = new algosdk.Algodv2(token, server, port);
    remarks

    The above configuration is for a sandbox private network. For applications on production, you are encouraged to run your own node, or use an Algorand REST API provider with a dedicated API key.

    Parameters

    • tokenOrBaseClient: string | AlgodTokenHeader | CustomTokenHeader | BaseHTTPClient

      The algod token from the Algorand node you are interacting with

    • baseServer: string = 'http://r2.algorand.network'

      REST endpoint

    • port: string | number = 4180

      Port number if specifically configured by the server

    • headers: Record<string, string> = {}

      Optional headers

    Returns Algodv2

GET Methods

  • Returns the given account's application information for a specific application.

    Example

    const address = "XBYLS2E6YI6XXL5BWCAMOA4GTWHXWENZMX5UHXMRNWWUQ7BXCY5WC5TEPA";
    const index = 60553466;
    const accountInfo = await algodClient.accountApplicationInformation(address).do();

    Response data schema details

    Parameters

    • account: string

      The address of the account to look up.

    • index: number

      The application ID to look up.

    Returns AccountApplicationInformation

  • Returns the given account's asset information for a specific asset.

    Example

    const address = "XBYLS2E6YI6XXL5BWCAMOA4GTWHXWENZMX5UHXMRNWWUQ7BXCY5WC5TEPA";
    const index = 60553466;
    const accountAssetInfo = await algodClient.accountAssetInformation(address, index).do();

    Response data schema details

    Parameters

    • account: string

      The address of the account to look up.

    • index: number

      The asset ID to look up.

    Returns AccountAssetInformation

  • block(roundNumber: number): Block
  • getProof(round: number, txID: string): Proof
  • Returns a Merkle proof for a given transaction in a block.

    Example

    const round = 18038133;
    const txId = "MEUOC4RQJB23CQZRFRKYEI6WBO73VTTPST5A7B3S5OKBUY6LFUDA";
    const proof = await algodClient.getProof(round, txId).do();

    Response data schema details

    Parameters

    • round: number

      The round in which the transaction appears.

    • txID: string

      The transaction ID for which to generate a proof.

    Returns Proof

  • Returns the list of pending transactions sent by the address, sorted by priority, in decreasing order, truncated at the end at MAX. If MAX = 0, returns all pending transactions.

    Example 1

    const address = "XBYLS2E6YI6XXL5BWCAMOA4GTWHXWENZMX5UHXMRNWWUQ7BXCY5WC5TEPA";
    const pendingTxnsByAddr = await algodClient.pendingTransactionByAddress(address).do();

    Example 2

    const maxTxns = 5;
    const address = "XBYLS2E6YI6XXL5BWCAMOA4GTWHXWENZMX5UHXMRNWWUQ7BXCY5WC5TEPA";
    const pendingTxns = await algodClient
    .pendingTransactionByAddress(address)
    .max(maxTxns)
    .do();

    Response data schema details

    Parameters

    • address: string

      The address of the sender.

    Returns PendingTransactionsByAddress

  • Returns the transaction information for a specific pending transaction.

    Example

    const txId = "DRJS6R745A7GFVMXEXWP4TGVDGKW7VILFTA7HC2BR2GRLHNY5CTA";
    const pending = await algodClient.pendingTransactionInformation(txId).do();

    Response data schema details

    remarks



    There are several cases when this might succeed:

    • transaction committed (committed round > 0)
    • transaction still in the pool (committed round = 0, pool error = "")
    • transaction removed from pool due to error (committed round = 0, pool error != "")

    Or the transaction may have happened sufficiently long ago that the node no longer remembers it, and this will return an error.

    Parameters

    • txid: string

      The TxID string of the pending transaction to look up.

    Returns PendingTransactionInformation

Other Methods

  • Set the default int decoding method for all JSON requests this client creates.

    Parameters

    • method: IntDecoding

      {"default" | "safe" | "mixed" | "bigint"} method The method to use when parsing the response for request. Must be one of "default", "safe", "mixed", or "bigint". See JSONRequest.setIntDecoding for more details about what each method does.

    Returns void

POST Methods

  • compile(source: string | Uint8Array): Compile
  • Compiles TEAL source code to binary, returns base64 encoded program bytes and base32 SHA512_256 hash of program bytes (Address style).

    Example

    const source = "TEAL SOURCE CODE";
    const compiledSmartContract = await algodClient.compile(source).do();

    Response data schema details

    remarks

    This endpoint is only enabled when a node's configuration file sets EnableDeveloperAPI to true.

    Parameters

    • source: string | Uint8Array

    Returns Compile

  • Provides debugging information for a transaction (or group).

    Executes TEAL program(s) in context and returns debugging information about the execution. This endpoint is only enabled when a node's configureation file sets EnableDeveloperAPI to true.

    Example

    const dryRunResult = await algodClient.dryrun(dr).do();
    

    Response data schema details

    Parameters

    Returns Dryrun

Generated using TypeDoc