Funding an Account
To use the Algorand blockchain, accounts need to be funded with ALGO tokens. This guide explains different methods of funding accounts across Algorand’s various networks. You can also transfer ALGO tokens from an existing funded account to a new account using the Algorand SDK or through wallet applications. All Algorand accounts require a minimum balance to be registered in the ledger. The specific method you choose will depend on whether you’re working with MainNet, TestNet, or LocalNet.
Choosing the Right Funding Method
The appropriate funding method depends on your specific needs:
- Development and Testing: Use TestNet faucet or LocalNet’s pre-funded accounts
- Production Applications: Use MainNet on-ramps to acquire real ALGO tokens
- Automated Deployments: Use AlgoKit’s ensureFunded utilities
- CI/CD Environments: Use TestNet Dispenser API with appropriate credentials
By selecting the right funding mechanism for your use case, you can streamline development and ensure your Algorand applications have the resources they need to operate effectively.
LocalNet Funding Options
LocalNet provides pre-funded accounts for development and testing. You can use these existing accounts or create and fund new ones using various mechanisms.
Retrieving the Default LocalNet Dispenser
This utils function retrieves the default LocalNet dispenser account, which is pre-funded and can be used to provide ALGOs to other accounts in a local development environment. The LocalNet dispenser is automatically available and is designed for testing purposes, making it easy to create and fund new accounts without external dependencies.
/** * Get the default LocalNet dispenser account that can be used to fund other accounts */ const localNetDispenser = await algorand.account.localNetDispenser()
""" Returns the default LocalNet dispenser account. This account can be used to fund test accounts on LocalNet. """ localnet_dispenser = algorand_client.account.localnet_dispenser()
Environment-Based Dispenser
The below function retrieves a dispenser account configured through environment variables. It allows developers to specify a custom funding account for different environments (e.g., development, testing, staging). The function looks for environment variables containing the dispenser’s private key or mnemonic, making it flexible for dynamic funding configurations across various deployments. The dispenser here is managed by the developer and is not a public dispenser that already exists.
/** * Get a dispenser account from environment variables. */ const environmentDispenser = await algorand.account.dispenserFromEnvironment()
""" Returns an account (with private key loaded) that can act as a dispenser from environment variables. If environment variables are not present, returns the default LocalNet dispenser account. """ dispenser = algorand_client.account.dispenser_from_environment()
TestNet Funding Options
TestNet Faucet
Algorand provides a faucet for funding TestNet accounts with test ALGO tokens for development purposes.
- Visit Lora Explorer and choose the network(localnet or testnet) or visit the Algorand TestNet Dispenser
- Sign in with your Google account and complete the reCAPTCHA
- Enter your Algorand TestNet address
- Click “Dispense” to receive test ALGOs
TestNet Dispenser API
For developers needing programmatic access to TestNet funds, AlgoKit provides utils to interact with the TestNet Dispenser API.
Ensuring Funds from TestNet Dispenser
The ensureFundedFromTestNetDispenserApi
function checks if a specified Algorand account has enough funds on TestNet. If the balance is below the required threshold, it automatically requests additional ALGOs from the TestNet Dispenser API. The dispenser client is initialized using the ALGOKIT_DISPENSER_ACCESS_TOKEN
environment variable for authentication. This is particularly useful for CI/CD pipelines and automated tests, ensuring accounts remain funded without manual intervention.
/** * Ensure an account has sufficient funds using the TestNet Dispenser API * The dispenser client uses the `ALGOKIT_DISPENSER_ACCESS_TOKEN` environment variable * to authenticate with the dispenser API. */ const dispenserClient = algorand.client.getTestNetDispenserFromEnvironment() await algorand.account.ensureFundedFromTestNetDispenserApi('ACCOUNTADDRESS', dispenserClient, algo(1))
""" Ensure an account is funded from a dispenser account retrieved from the testnet dispenser API. Uses a dispenser account retrieved from the testnet dispenser API, per the ensure_funded_from_testnet_dispenser_api method, as a funding source such that the given account has a certain amount of Algo free to spend (accounting for Algo locked in minimum balance requirement). """ testnet_dispenser = algorand_client.client.get_testnet_dispenser()
algorand_client.account.ensure_funded_from_testnet_dispenser_api( account_to_fund=random_account.address, dispenser_client=testnet_dispenser, min_spending_balance=AlgoAmount(algo=10), )
Directly Funding an Account
The below utils function sends a fixed amount of ALGOs (1,000,000 microALGOs = 1 ALGO) to a specified account using the TestNet Dispenser API. Unlike the ensureFundedFromTestNetDispenserApi method, which checks the balance before funding, this function transfers funds immediately. It is useful when you need to top up an account with a specific amount without verifying its current balance.
/** * Directly fund an account using the TestNet Dispenser API */ const testnetDispenser = algorand.client.getTestNetDispenserFromEnvironment() await testnetDispenser.fund('ACCOUNTADDRESS', 1_000_000)
""" Directly fund an account using the TestNet Dispenser API """ testnet_dispenser = algorand_client.client.get_testnet_dispenser() testnet_dispenser.fund(address=random_account.address, amount=10, asset_id=0)
Using AlgoKit CLI
The AlgoKit CLI provides a simple command-line interface for funding accounts. This command directly funds the specified receiver address with the requested amount of ALGOs using the TestNet Dispenser. It’s convenient for quick funding operations without writing code.
algokit dispenser fund --receiver <address> --amount <amount>
MainNet On-Ramps
For MainNet transactions, users must acquire real ALGO tokens through cryptocurrency exchanges or other on-ramp services. Required for real-world transactions and decentralized applications. Some of the common On-Ramps are centralized exchanges like Coinbase, Decentralized Exchanges like Tinyman, other DeFi protocols like Folks Finance.
AlgoKit Utils Funding Helpers
AlgoKit provides utility functions to help ensure accounts have sufficient funds, which is particularly useful for automation and deployment scripts.
Ensure Funded
The below code checks the balance of a specified account and transfers ALGOs from a dispenser if the balance falls below the required threshold (1 ALGO in this example). It ensures the account has enough funds before executing transactions, making it useful for automated scripts that depend on a minimum balance.
/** * Ensure an account has sufficient funds by transferring * Algos from a dispenser account if needed */ await algorand.account.ensureFunded('ACCOUNTADDRESS', localNetDispenser, algo(1))
""" Funds a given account using a dispenser account as a funding source. Ensures the given account has a certain amount of Algo free to spend (accounting for Algo locked in minimum balance requirement). """ algorand_client.account.ensure_funded( account_to_fund=random_account.address, dispenser_account=localnet_dispenser.address, min_spending_balance=AlgoAmount(algo=10), )
Funding from Environment Variables
This code combines the ensure-funded mechanism with an environment-configured dispenser. It retrieves a dispenser account from environment variables and uses it to top up the target account if its balance is below 1 ALGO. This approach makes the code more flexible and portable by allowing different dispensers to be used across various environments without hardcoding account details.
/** * Ensure an account has sufficient funds using a dispenser account * loaded from environment variables */ await algorand.account.ensureFundedFromEnvironment('ACCOUNTADDRESS', algo(1))
""" Ensure an account is funded from a dispenser account configured in environment. Uses a dispenser account retrieved from the environment, per the dispenser_from_environment method, as a funding source such that the given account has a certain amount of Algo free to spend (accounting for Algo locked in minimum balance requirement). """ algorand_client.account.ensure_funded_from_environment( account_to_fund=random_account.address, min_spending_balance=AlgoAmount(algo=10), )