Get Started

This example runs on TestNet, using a Purestake node.

import Algonaut from '@thencc/algonautjs';

const algonaut = new Algonaut({
  BASE_SERVER: 'https://testnet-algorand.api.purestake.io/ps2',
  LEDGER: 'TestNet',
  PORT: '',
  API_TOKEN: { 'X-API-Key': 'INSERT_API_KEY_HERE' },
  //SIGNING_MODE: 'wallet-connect' // uncomment if you are using WalletConnect+Algorand Wallet
});

const status = await algonaut.checkStatus();
console.log(status);

Connect to Account with WalletConnect

One of the easiest ways we've found to interface with the Algorand blockchain is to connect to users' account with the Algorand Wallet on mobile.

Using WalletConnect, we prompt the user to scan a QR code, which connects our app to their wallet. From there, they sign transactions with a single tap on their phone.

// Log a user in via WalletConnect
const user = { address: '' };

// calling connectAlgoWallet opens a QR code prompt
// which the user scans with the Algorand mobile wallet
algonaut.connectAlgoWallet({
  onConnect: (payload) => {
    // set "authenticated" state, to use in our app
    const { accounts } = payload[0];
    user.address = accounts[0];
  },
  onDisconnect: () => {
    // "log out" the user
    user.address = '';
  },
  onSessionUpdate: (accounts) => {
    user.address = accounts[0];
  }
});

Sign Transactions with WalletConnect

In this example, we are storing account info as local state in a contract identified by ACCOUNT_CONTRACT_ID.

Various functions in Algonaut.js will return AlgonautAtomicTransaction, which can be used in createWalletConnectTransactions to bundle the transactions for signing via WalletConnect.

See the list of functions with an atomic prefix in the API docs.

const txns = await algonaut.createWalletConnectTransactions([
  await algonaut.atomicOptInApp({
    appIndex: ACCOUNT_CONTRACT_ID,
    appArgs: [
      'set_all',
      account.name,
      account.bio || '',
      account.avatar || ''
    ]
  })
]);
const response = await algonaut.sendWalletConnectTxns(txns);