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

  • default
    • Algodv2

DELETE

GET

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

    Example

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

    Response data schema details

    Parameters

    • account: string | Address

      The address of the account to look up.

    • index: number | bigint

      The application ID to look up.

    Returns default

  • 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 | Address

      The address of the account to look up.

    • index: number | bigint

      The asset ID to look up.

    Returns default

  • Returns the given account's status, balance and spendable amounts.

    Example

    const address = "XBYLS2E6YI6XXL5BWCAMOA4GTWHXWENZMX5UHXMRNWWUQ7BXCY5WC5TEPA";
    const accountInfo = await algodClient.accountInformation(address).do();

    Response data schema details

    Parameters

    • account: string | Address

      The address of the account to look up.

    Returns default

  • Gets the block info for the given round.

    Example

    const roundNumber = 18038133;
    const block = await algodClient.block(roundNumber).do();

    Response data schema details

    Parameters

    • roundNumber: number | bigint

      The round number of the block to get.

    Returns default

  • Given an application ID and the box name (key), return the value stored in the box.

    Example

    const index = 60553466;
    const boxName = Buffer.from("foo");
    const boxResponse = await algodClient.getApplicationBoxByName(index, boxName).do();
    const boxValue = boxResponse.value;

    Response data schema details

    Parameters

    • index: number | bigint

      The application ID to look up.

    • boxName: Uint8Array

    Returns default

  • Given an application ID, return all the box names associated with the app.

    Example

    const index = 60553466;
    const boxesResponse = await algodClient.getApplicationBoxes(index).max(3).do();
    const boxNames = boxesResponse.boxes.map(box => box.name);

    Response data schema details

    Parameters

    • index: number | bigint

      The application ID to look up.

    Returns default

  • Given an application ID, return the application information including creator, approval and clear programs, global and local schemas, and global state.

    Example

    const index = 60553466;
    const app = await algodClient.getApplicationByID(index).do();

    Response data schema details

    Parameters

    • index: number | bigint

      The application ID to look up.

    Returns default

  • Given an asset ID, return asset information including creator, name, total supply and special addresses.

    Example

    const asset_id = 163650;
    const asset = await algodClient.getAssetByID(asset_id).do();

    Response data schema details

    Parameters

    • index: number | bigint

      The asset ID to look up.

    Returns default

  • Get the block hash for the block on the given round.

    Example

    const roundNumber = 18038133;
    const block = await algodClient.getBlockHash(roundNumber).do();

    Response data schema details

    Parameters

    • roundNumber: number | bigint

      The round number of the block to get.

    Returns default

  • Get the top level transaction IDs for the block on the given round.

    Example

    const roundNumber = 18038133;
    const block = await algodClient.getBlockTxids(roundNumber).do();

    Response data schema details

    Parameters

    • roundNumber: number | bigint

      The round number of the block to get.

    Returns default

  • GetLedgerStateDelta returns the ledger delta for the entire round

    Example

    const round = 12345;
    await client.getLedgerStateDelta(round).do();

    Response data schema details

    Parameters

    • round: number | bigint

      the round number to be searched for

    Returns default

  • GetLedgerStateDeltaForTransactionGroup returns the ledger delta for the txn group identified by id

    Example

    const id = "ABC123";
    await client.getLedgerStateDeltaForTransactionGroup(id).do();

    Response data schema details

    Parameters

    • id: string

      txn ID or group ID to be searched for

    Returns default

  • GetTransactionGroupLedgerStateDeltasForRound returns all ledger deltas for txn groups in the provided round

    Example

    const round = 12345;
    await client.getTransactionGroupLedgerStateDeltasForRound(round).do();

    Response data schema details

    Parameters

    • round: number | bigint

      the round number to be searched for

    Returns default

  • 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 | bigint

      The round in which the transaction appears.

    • txID: string

      The transaction ID for which to generate a proof.

    Returns default

  • 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 | Address

      The address of the sender.

    Returns default

  • Returns the transaction information for a specific pending transaction.

    Example

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

    Response data schema details

    Parameters

    • txid: string

      The TxID string of the pending transaction to look up.

    Returns default

    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.

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

    Example 1

    const pendingTxns = await algodClient.pendingTransactionsInformation().do();
    

    Example 2

    const maxTxns = 5;
    const pendingTxns = await algodClient
    .pendingTransactionsInformation()
    .max(maxTxns)
    .do();

    Response data schema details

    Returns default

  • Waits for a specific round to occur then returns the StatusResponse for that round.

    Example

    const round = 18038133;
    const statusAfterBlock = await algodClient.statusAfterBlock(round).do();

    Response data schema details

    Parameters

    • round: number | bigint

      The number of the round to wait for.

    Returns default

Other

  • 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);

    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

    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.

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

    Example

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

    Parameters

    • source: string | Uint8Array

    Returns default

    Remarks

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

  • Gets a proof for a given light block header inside a state proof commitment.

    Example

    const round = 11111111;
    const lightBlockHeaderProof = await algodClient.getLightBlockHeaderProof(round).do();

    Response data schema details

    Parameters

    • round: number | bigint

    Returns default

POST

  • 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

    Parameters

    • source: string | Uint8Array

    Returns default

    Remarks

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

  • 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 default

  • Broadcasts a raw transaction to the network.

    Example

    const { txid } = await algodClient.sendRawTransaction(signedTxns).do();
    const result = await waitForConfirmation(algodClient, txid, 3);

    Response data schema details

    Parameters

    • stxOrStxs: Uint8Array | Uint8Array[]

      Signed transactions

    Returns default

    Remarks

    Often used with waitForConfirmation

  • Set the offset (in seconds) applied to the block timestamp when creating new blocks in devmode.

    Example

    const offset = 60
    await client.setBlockOffsetTimestamp(offset).do();
    

    Response data schema details

    Parameters

    • offset: number | bigint

    Returns default

  • Simulate a list of a signed transaction objects being sent to the network.

    Example

    const txn1 = algosdk.makePaymentTxnWithSuggestedParamsFromObject(txn1Params);
    const txn2 = algosdk.makePaymentTxnWithSuggestedParamsFromObject(txn2Params);
    const txgroup = algosdk.assignGroupID([txn1, txn2]);

    // Actually sign the first transaction
    const signedTxn1 = txgroup[0].signTxn(senderSk).blob;
    // Simulate does not require signed transactions -- use this method to encode an unsigned transaction
    const signedTxn2 = algosdk.encodeUnsignedSimulateTransaction(txgroup[1]);

    const resp = await client.simulateRawTransactions([signedTxn1, signedTxn2]).do();

    Response data schema details

    Parameters

    • stxOrStxs: Uint8Array | Uint8Array[]

    Returns default

  • Simulate transactions being sent to the network.

    Example

    const txn1 = algosdk.makePaymentTxnWithSuggestedParamsFromObject(txn1Params);
    const txn2 = algosdk.makePaymentTxnWithSuggestedParamsFromObject(txn2Params);
    const txgroup = algosdk.assignGroupID([txn1, txn2]);

    // Actually sign the first transaction
    const signedTxn1 = txgroup[0].signTxn(senderSk).blob;
    // Simulate does not require signed transactions -- use this method to encode an unsigned transaction
    const signedTxn2 = algosdk.encodeUnsignedSimulateTransaction(txgroup[1]);

    const request = new modelsv2.SimulateRequest({
    txnGroups: [
    new modelsv2.SimulateRequestTransactionGroup({
    // Must decode the signed txn bytes into an object
    txns: [algosdk.decodeObj(signedTxn1), algosdk.decodeObj(signedTxn2)]
    }),
    ],
    });
    const resp = await client.simulateRawTransactions(request).do();

    Response data schema details

    Parameters

    Returns default

Generated using TypeDoc