Check for the AlgoSigner API to be available in the browser context
if (typeof algorand !== 'undefined') {
console.log('AlgoSigner is installed.');
} else {
console.log('AlgoSigner is NOT installed.');
};
code snippet output
Setup Algod and Indexer clients and fetch transactions parameters
const algodServer = 'https://testnet-algorand.api.purestake.io/ps2';
const indexerServer = 'https://testnet-algorand.api.purestake.io/idx2';
const token = { 'X-API-Key': 'YOUR API KEY HERE' };
const port = '';
algodClient = new algosdk.Algodv2(token, algodServer, port);
indexerClient = new algosdk.Indexer(token, indexerServer, port);
algodClient.getTransactionParams().do()
.then(d => {
console.log(d);
txnParams = d;
})
.catch(e => {
console.error(e);
});
code snippet output
Request from the user which accounts will be shared with the dApp
algorand.enable({ genesisID: txnParams.genesisID })
.then((d) => {
console.log(d);
sharedAccounts = d.accounts;
})
.catch((e) => {
console.error(e);
});
code snippet output
Query Indexer with the client to fetch TestNet assets
const name = document.getElementById('name').value;
const limit = document.getElementById('limit').value;
indexerClient.searchForAssets().limit(limit).name(name).do()
.then((d) => {
console.log(d);
})
.catch((e) => {
console.error(e);
});
code snippet output