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

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 | BaseHTTPClient | AlgodTokenHeader | CustomTokenHeader

      The algod token from the Algorand node you are interacting with

    • baseServer: string

      REST endpoint

    • Optional port: string | number

      Port number if specifically configured by the server

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

      Optional headers

    Returns Algodv2

GET Methods

  • Returns a Merkle proof for a given transaction in a block.

    Example

    const round = 18038133;
    const txId = "MEUOC4RQJB23CQZRFRKYEI6WBO73VTTPST5A7B3S5OKBUY6LFUDA";
    const proof = await algodClient.getTransactionProof(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 GetTransactionProof

  • 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

  • Given the program bytes, return the TEAL source code in plain text.

    Example

    const bytecode = "TEAL bytecode";
    const disassembledSource = await algodClient.disassemble(bytecode).do();

    Remarks

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

    Parameters

    • source: string | Uint8Array

    Returns Disassemble

  • 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

  • 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

Generated using TypeDoc