Create Publication

We are looking for publications that demonstrate building dApps or smart contracts!
See the full list of Gitcoin bounties that are eligible for rewards.

Tutorial Thumbnail
Beginner · 15 minutes or less

Create an Account on TestNet using Java

This tutorial demonstrates the steps involved in creating a basic Standalone Algorand Account using the Java SDK and funding it using the Algorand Testnet Faucet.

Requirements

Background

Many tutorials will need accounts to perform transactions on. Code samples will typically call a restore account function from a mnemonic code. Copy off the account addresses and mnemonics generated from this tutorial for later use. To learn more about Accounts on Algorand visit the Accounts Overview page in the docs.

Steps

1. Generate an Algorand keypair

Import algodsdk account

import com.algorand.algosdk.account.Account;

2. Retrieve the private key mnemonic

Standlone Account Derivation

System.out.println("My Passphrase Mnemonic1: " + myAccount1.toMnemonic());

3. Send Algos to the new account

Let’s send Algos to the new account by visiting the TestNet faucet.

Enter the Algorand Public Address in the textbox, complete the recaptcha, and click “Dispense”. If you receive a 200 status code, your account should now be funded with 100 Algos.

4. Check your balance

You can check your balance with any block explorer connected to TestNet.

You can also connect to a node through the Java algod client. Make sure to first retrieve an IP address and access token through one of the methods described in the Workspace Setup. Also make sure to replace the placeholder values with your own token, server and port values.

Once you have an address and token. Instantiate a client and call the accountInformation method to check the account’s balance.

5. Optional - Import account into mobile wallet

The mnemonic you just generated is compatible with Algorand’s mobile wallet. Tap the “Recover from passphrase” button to import this account into your mobile wallet. Your balance should now update.

6. Completed Code

Here is the completed code to generate 3 accounts.

package com.algorand.javatest;
import com.algorand.algosdk.account.Account;

public class myTutorialCreateAccounts {
    public static void main(String args[]) throws Exception {
        Account myAccount1 = new Account();
        System.out.println("My Address1: " + myAccount1.getAddress());
        System.out.println("My Passphrase1: " + myAccount1.toMnemonic());
        Account myAccount2 = new Account();
        System.out.println("My Address2: " + myAccount2.getAddress());
        System.out.println("My Passphrase2: " + myAccount2.toMnemonic());
        Account myAccount3 = new Account();
        System.out.println("My Address3: " + myAccount3.getAddress());
        System.out.println("My Passphrase3: " + myAccount3.toMnemonic());

        //Copy off accounts and mnemonics    
        //Dispense TestNet Algos to each account: https://bank.testnet.algorand.network/
    }
}