Un-Set the sync round on the ledger (algod must have EnableFollowMode: true), removing the restriction on catchup.
await client.unsetSyncRound().do();
Returns the given account's application information for a specific application.
const address = "XBYLS2E6YI6XXL5BWCAMOA4GTWHXWENZMX5UHXMRNWWUQ7BXCY5WC5TEPA";
const index = 60553466;
const accountInfo = await algodClient.accountApplicationInformation(address, index).do();
The address of the account to look up.
The application ID to look up.
Returns the given account's asset information for a specific asset.
const address = "XBYLS2E6YI6XXL5BWCAMOA4GTWHXWENZMX5UHXMRNWWUQ7BXCY5WC5TEPA";
const index = 60553466;
const accountAssetInfo = await algodClient.accountAssetInformation(address, index).do();
The address of the account to look up.
The asset ID to look up.
Returns the given account's status, balance and spendable amounts.
const address = "XBYLS2E6YI6XXL5BWCAMOA4GTWHXWENZMX5UHXMRNWWUQ7BXCY5WC5TEPA";
const accountInfo = await algodClient.accountInformation(address).do();
The address of the account to look up.
Gets the block info for the given round.
const roundNumber = 18038133;
const block = await algodClient.block(roundNumber).do();
The round number of the block to get.
Given an application ID and the box name (key), return the value stored in the box.
const index = 60553466;
const boxName = Buffer.from("foo");
const boxResponse = await algodClient.getApplicationBoxByName(index, boxName).do();
const boxValue = boxResponse.value;
The application ID to look up.
Given an application ID, return all the box names associated with the app.
const index = 60553466;
const boxesResponse = await algodClient.getApplicationBoxes(index).max(3).do();
const boxNames = boxesResponse.boxes.map(box => box.name);
The application ID to look up.
Given an application ID, return the application information including creator, approval and clear programs, global and local schemas, and global state.
const index = 60553466;
const app = await algodClient.getApplicationByID(index).do();
The application ID to look up.
Given an asset ID, return asset information including creator, name, total supply and special addresses.
const asset_id = 163650;
const asset = await algodClient.getAssetByID(asset_id).do();
The asset ID to look up.
Get the block hash for the block on the given round.
const roundNumber = 18038133;
const block = await algodClient.getBlockHash(roundNumber).do();
The round number of the block to get.
Get the offset (in seconds) applied to the block timestamp when creating new blocks in devmode.
const currentOffset = await client.getBlockOffsetTimestamp().do();
Get the top level transaction IDs for the block on the given round.
const roundNumber = 18038133;
const block = await algodClient.getBlockTxids(roundNumber).do();
The round number of the block to get.
GetLedgerStateDelta returns the ledger delta for the entire round
const round = 12345;
await client.getLedgerStateDelta(round).do();
the round number to be searched for
GetLedgerStateDeltaForTransactionGroup returns the ledger delta for the txn group identified by id
const id = "ABC123";
await client.getLedgerStateDeltaForTransactionGroup(id).do();
txn ID or group ID to be searched for
Get the current sync round on the ledger (algod must have EnableFollowMode: true).
const currentSyncRound = await client.getSyncRound().do();
GetTransactionGroupLedgerStateDeltasForRound returns all ledger deltas for txn groups in the provided round
const round = 12345;
await client.getTransactionGroupLedgerStateDeltasForRound(round).do();
the round number to be searched for
Returns the common needed parameters for a new transaction.
const suggestedParams = await algodClient.getTransactionParams().do();
const amountInMicroAlgos = algosdk.algosToMicroalgos(2); // 2 Algos
const unsignedTxn = algosdk.makePaymentTxnWithSuggestedParamsFromObject({
sender: senderAddress,
receiver: receiverAddress,
amount: amountInMicroAlgos,
suggestedParams: suggestedParams,
});
Often used with
makePaymentTxnWithSuggestedParamsFromObject
, algosToMicroalgos
Returns a Merkle proof for a given transaction in a block.
const round = 18038133;
const txId = "MEUOC4RQJB23CQZRFRKYEI6WBO73VTTPST5A7B3S5OKBUY6LFUDA";
const proof = await algodClient.getTransactionProof(round, txId).do();
The round in which the transaction appears.
The transaction ID for which to generate a 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.
const address = "XBYLS2E6YI6XXL5BWCAMOA4GTWHXWENZMX5UHXMRNWWUQ7BXCY5WC5TEPA";
const pendingTxnsByAddr = await algodClient.pendingTransactionByAddress(address).do();
const maxTxns = 5;
const address = "XBYLS2E6YI6XXL5BWCAMOA4GTWHXWENZMX5UHXMRNWWUQ7BXCY5WC5TEPA";
const pendingTxns = await algodClient
.pendingTransactionByAddress(address)
.max(maxTxns)
.do();
The address of the sender.
Returns the transaction information for a specific pending transaction.
const txId = "DRJS6R745A7GFVMXEXWP4TGVDGKW7VILFTA7HC2BR2GRLHNY5CTA";
const pending = await algodClient.pendingTransactionInformation(txId).do();
The TxID string of the pending transaction to look up.
There are several cases when this might succeed:
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.
const pendingTxns = await algodClient.pendingTransactionsInformation().do();
const maxTxns = 5;
const pendingTxns = await algodClient
.pendingTransactionsInformation()
.max(maxTxns)
.do();
Ready check which returns 200 OK if algod is healthy and caught up
await client.ready().do();
Retrieves the StatusResponse from the running node.
const status = await algodClient.status().do();
Waits for a specific round to occur then returns the StatusResponse
for that round.
const round = 18038133;
const statusAfterBlock = await algodClient.statusAfterBlock(round).do();
The number of the round to wait for.
Returns the supply details for the specified node's ledger.
const supplyDetails = await algodClient.supply().do();
Retrieves the supported API versions, binary build versions, and genesis information.
const versionsDetails = await algodClient.versionsCheck().do();
Create an AlgodClient from
const token = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
const server = "http://localhost";
const port = 4001;
const algodClient = new algosdk.Algodv2(token, server, port);
The algod token from the Algorand node you are interacting with
REST endpoint
Optional
port: string | numberPort number if specifically configured by the server
Optional headers
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.
const bytecode = "TEAL bytecode";
const disassembledSource = await algodClient.disassemble(bytecode).do();
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.
const round = 11111111;
const lightBlockHeaderProof = await algodClient.getLightBlockHeaderProof(round).do();
Gets a state proof that covers a given round.
const round = 11111111;
const stateProof = await algodClient.getStateProof(round).do();
Compiles TEAL source code to binary, returns base64 encoded program bytes and base32 SHA512_256 hash of program bytes (Address style).
const source = "TEAL SOURCE CODE";
const compiledSmartContract = await algodClient.compile(source).do();
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.
const dryRunResult = await algodClient.dryrun(dr).do();
Broadcasts a raw transaction to the network.
const { txid } = await algodClient.sendRawTransaction(signedTxns).do();
const result = await waitForConfirmation(algodClient, txid, 3);
Signed transactions
Often used with waitForConfirmation
Set the offset (in seconds) applied to the block timestamp when creating new blocks in devmode.
const offset = 60
await client.setBlockOffsetTimestamp(offset).do();
Set the sync round on the ledger (algod must have EnableFollowMode: true), restricting catchup.
const round = 10000
await client.setSyncRound(round).do();
Simulate a list of a signed transaction objects being sent to the network.
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();
Simulate transactions being sent to the network.
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();
Generated using TypeDoc
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