AlgoDriver

This page describes documentation specific to the Algorand ChainDriver template named as AlgoDriver created by the Blockin team. It is implemented using the PureStake Indexer and Client API and algosdk npm library.

Installation and Initialization

First, npm install blockin-algo-driver

Then, import via import AlgoDriver from 'blockin-algo-driver';

To initialize a new instance, runnew AlgoDriver('Testnet' or 'Mainnet', PURESTAKE_API_KEY);

You do not have to specify an API key, but it is needed for functions that require an API key (marked with **).

Visit here for more information on how to get started with Purestake and getting a Purestake API Key. Note that this key should always be kept private and never leaked in your frontend.

Asset ID Scheme

For anything where an asset ID is needed in AlgoDriver, we use the asset ID field as specified on Algorand and AlgoExplorer. To check if an asset ID is valid, the URL 'https://algoexplorer.io/asset/assetID' must point to the asset.

Additional Functionality

This ChainDriver implements all functionality seen in the ChainDriver interface. However since Algorand is really unique due to its opt in transactions and smart contract restrictions, some additional functionality was needed to be exported from AlgoDriver.

To call the function belows, you will need to store the intialized driver into a variable and call them that way, as seen below. You won't be able to call them via Blockin directly.

const driver = new AlgoDriver('Testnet' or 'Mainnet', PURESTAKE_API_KEY;

driver.functionCall();

makePaymentTxn(assetParams: CreatePaymentParams) : Promise<UniversalTxn>

This function creates a vanilla payment transaction.

Generates an unsigned asset creation transaction which can be signed and broadcasted to the blockchain network.

Note that a valid ChainDriver with API key must be set in order to successfully call this function.

assetParams - JSON object specifying payment transaction fields:

to: string;

from?: string;

amount?: number | bigint;

note?: string;

extras?: any;

returns - If successful, will return a UniversalTxn object that specifies the bytes to sign and submit to create a valid payment transaction. Throws upon error.

makeAssetOptInTxn(assetParams: CreateOptInAssetParams)

This function creates an asset opt-in transaction.

Generates an unsigned asset creation transaction which can be signed and broadcasted to the blockchain network.

Note that a valid ChainDriver with API key must be set in order to successfully call this function.

assetParams - JSON object specifying asset opt in fields:

to: string;

from?: string;

assetIndex: number;

extras?: any;

returns - If successful, will return a UniversalTxn object that specifies the bytes to sign and submit to create a valid asset opt-in transaction. Throws upon error.

makeContractOptInTxn(appParams: CreateContractOptInParams) : Promise<UniversalTxn>

This function creates an Algorand contract opt-in transaction.

Generates an unsigned asset creation transaction which can be signed and broadcasted to the blockchain network.

Note that a valid ChainDriver with API key must be set in order to successfully call this function.

appParams - JSON object specifying contract opt-in fields:

from: string;

appIndex: number;

extras?: any;

returns - If successful, will return a UniversalTxn object that specifies the bytes to sign and submit to create a valid contract opt-in transaction. Throws upon error.

makeContractNoOpTxn(appParams: CreateContractNoOpParams) : Promise<UniversalTxn>

This function creates an Algorand contract no-op transaction.

Generates an unsigned asset creation transaction which can be signed and broadcasted to the blockchain network.

Note that a valid ChainDriver with API key must be set in order to successfully call this function.

appParams - JSON object specifying contract no-op fields:

from: string;

appIndex: number;

appArgs: Uint8Array[] | undefined;

accounts: string[] | undefined;

foreignAssets: number[] | undefined;

returns - If successful, will return a UniversalTxn object that specifies the bytes to sign and submit to create a valid contract no-op transaction. Throws upon error.

lookupApplicationLocalState(address: string): Promise<LookupAccountAppLocalStates>

Looks up the application's local state for Algorand smart contract development.

address - The address to lookup

returns - If successful, will return PureStake API's LookupAccountAppLocalStates type.

Last updated