{"id":10489,"library":"algosdk","title":"Algorand JavaScript SDK","description":"algosdk is the official JavaScript library for interacting with the Algorand blockchain network. It provides comprehensive functionalities for account management, transaction creation, signing, and submission, as well as querying blockchain data. Designed for both Node.js (requiring v18.0.0 or higher) and modern browsers, the SDK is actively maintained by Algorand, with frequent releases addressing bugfixes, enhancements, and API updates to align with the latest Algorand protocol specifications. The current stable version is 3.5.2. Version 3.x introduced significant breaking changes compared to v2.x, notably requiring explicit named imports for all functions and classes instead of a single default export or namespace object. It also ships with first-class TypeScript support, requiring TypeScript version 4.2 or higher for optimal usage.","status":"active","version":"3.5.2","language":"javascript","source_language":"en","source_url":"git://github.com/algorand/js-algorand-sdk","tags":["javascript","typescript"],"install":[{"cmd":"npm install algosdk","lang":"bash","label":"npm"},{"cmd":"yarn add algosdk","lang":"bash","label":"yarn"},{"cmd":"pnpm add algosdk","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Since v3, the library requires named imports; a default import or namespace object no longer works for accessing primary classes like Algodv2.","wrong":"import algosdk from 'algosdk';\nconst client = new algosdk.Algodv2(...);","symbol":"Algodv2","correct":"import { Algodv2 } from 'algosdk';"},{"note":"All utility functions must be imported by name in v3. CommonJS `require` is also not the recommended import style.","wrong":"const algosdk = require('algosdk');\nconst txn = algosdk.makePaymentTxnWithSuggestedParams(...);","symbol":"makePaymentTxnWithSuggestedParams","correct":"import { makePaymentTxnWithSuggestedParams } from 'algosdk';"},{"note":"Classes like Transaction, which are used for building complex objects, are also exclusively available via named imports in v3.","wrong":"import * as algosdk from 'algosdk';\nconst txn = new algosdk.Transaction(...);","symbol":"Transaction","correct":"import { Transaction } from 'algosdk';"}],"quickstart":{"code":"import { Algodv2, modelsv2 } from 'algosdk';\n\n// Configure your Algorand client using environment variables\nconst token = process.env.ALGORAND_ALGOD_TOKEN ?? ''; // Algod API token\nconst server = process.env.ALGORAND_ALGOD_SERVER ?? 'http://127.0.0.1'; // Algod server address\nconst port = process.env.ALGORAND_ALGOD_PORT ? parseInt(process.env.ALGORAND_ALGOD_PORT, 10) : 4001; // Algod port\n\nconst client = new Algodv2(token, server, port);\n\n(async () => {\n  try {\n    console.log(\"Fetching Algorand node status...\");\n    // Fetch and log the current Algorand node status\n    const status: modelsv2.NodeStatusResponse = await client.status().do();\n    console.log(\"Node last round:\", status.lastRound);\n\n    // Fetch and log suggested transaction parameters, essential for building transactions\n    const suggestedParams = await client.getTransactionParams().do();\n    console.log(\"Suggested transaction parameters:\", suggestedParams);\n\n    // Example: Fetch account information\n    // Replace 'YOUR_ALGORAND_ADDRESS_HERE' with a valid Algorand address or set via environment variable\n    const testAddress = process.env.ALGORAND_TEST_ACCOUNT_ADDRESS ?? 'YOUR_ALGORAND_ADDRESS_HERE'; \n    if (testAddress !== 'YOUR_ALGORAND_ADDRESS_HERE') {\n      console.log(`\\nFetching account info for ${testAddress}...`);\n      const accountInfo = await client.accountInformation(testAddress).do();\n      console.log(\"Account balance (microAlgos):\", accountInfo.amount);\n      console.log(\"Account assets:\", accountInfo.assets?.length || 0);\n    } else {\n      console.warn(\"\\nSkipping account info fetch. Set ALGORAND_TEST_ACCOUNT_ADDRESS to a valid address to enable this.\");\n    }\n  } catch (e) {\n    console.error(\"An error occurred during quickstart execution:\", e);\n  }\n})();","lang":"typescript","description":"Initializes the Algorand SDK client, fetches node status, retrieves suggested transaction parameters, and optionally fetches account information."},"warnings":[{"fix":"Consult the `v2_TO_v3_MIGRATION_GUIDE.md` in the GitHub repository. Update all imports to use named imports, e.g., `import { Algodv2 } from 'algosdk';`.","message":"Version 3.x introduces significant breaking changes from v2.x. The most notable change is the shift from a default export/namespace object to mandatory named imports for all classes and functions. Code relying on `algosdk.Algodv2` or `const algosdk = require('algosdk');` will break.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Migrate your application to algosdk v3.x or later immediately to ensure continued support, security updates, and access to new Algorand features. Refer to the migration guide for assistance.","message":"The v2.x series of algosdk is in maintenance mode and will reach End-of-Life at the end of March 2025. No new features are being added, and after March 2025, no further updates (including security fixes) will be provided.","severity":"deprecated","affected_versions":"<3.0.0"},{"fix":"Ensure your development and deployment environments are running Node.js v18.0.0 or a newer compatible version.","message":"This package requires Node.js version 18.0.0 or higher. Running it with older Node.js versions may lead to unexpected errors or module resolution issues, especially concerning ESM compatibility.","severity":"gotcha","affected_versions":">=3.0.0"},{"fix":"Upgrade your project's TypeScript dependency to version 4.2 or higher.","message":"While algosdk ships with TypeScript types, proper usage requires TypeScript version 4.2 or higher. Using an older TypeScript compiler might result in type errors or incorrect type inference.","severity":"gotcha","affected_versions":">=3.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Change your import statement to `import { Algodv2 } from 'algosdk';` and then use `new Algodv2(...)` directly.","cause":"Attempting to instantiate Algodv2 via a namespace or default import/require object after migrating to v3.x.","error":"TypeError: algosdk.Algodv2 is not a constructor"},{"fix":"Switch to ES module import syntax: `import { SomeSymbol } from 'algosdk';`. If you must use CommonJS, ensure your environment is configured for CJS (e.g., using `.cjs` extension or `type: 'commonjs'`).","cause":"Using CommonJS `require()` syntax in an ES module context (`type: 'module'` in package.json or `.mjs` file).","error":"ReferenceError: require is not defined"},{"fix":"Update your TypeScript compiler to version 4.2 or higher. Ensure `algosdk` is correctly installed and its types are being picked up by your `tsconfig.json`.","cause":"Using an outdated TypeScript version (older than 4.2) that may not correctly process the SDK's bundled type definitions.","error":"Property 'status' does not exist on type 'Algodv2' or similar TypeScript errors related to missing methods/properties."}],"ecosystem":"npm"}