Asset Transaction history

I want to the asset transacation to be displayed on fromtend and I want to fetch it from the blcokchain.
I am working in the sandbox environment.
How can I do that here

const algosdk = require('algosdk');

const assetId = <your asset ID>;
const algodToken = '<your algod token>';
const algodServer = 'http://localhost:4001';

async function getAssetHistory() {
  const algodClient = new algosdk.Algodv2(algodToken, algodServer);

  const assetTransactions = await algodClient.transactionByAsset(
    1000, // retrieve up to 1000 transactions
    1, // include asset transfer transactions
    1, // include asset configuration transactions
    1, // include asset destroy transactions
    undefined // do not filter by sender address

  return assetTransactions.transactions;

async function main() {
  const transactions = await getAssetHistory();
  console.log('Transactions:', transactions);

main().catch((err) => console.log(err));```

This is a code I got somewhere can I use this?
Please help
If there is any link please do share

You can use lookupAssetTransactions from the Indexer (not Algod).
You need to create an indexer object (not algod). Token and address are provided here for sandbox GitHub - algorand/sandbox: Algorand node sandbox

See Indexer | algosdk for the function.

See Indexer - Algorand Developer Portal for the documentation of the indexer.

Note: I’m assuming you are using a private network / sandnet / localnet. If you are using TestNet, sandbox does not provide an indexer and you need to use a public indexer or run a full archival node and indexer yourself. See Ecosystem Tools & Projects | Algorand Developer Portal for a list of API service. E.g., API

Yes I am using the testnet sandbox, can I make changes in the sandbox in that case?

You may.

However, note that to have a TestNet indexer, you currently need a TestNet archival node.
This requires a large amount of disk space and a long time to sync (a few weeks).
(There soon will be a “follower mode” for algod node that should reduce the amount of storage needed, but you would still need the indexer storage).
See for the sizes

You will also need to disable fast catchup completely in the scripts as fast catchup is incompatible with archival mode.

If you are not in production (which I guess you are not since TestNet is not for production), I usually recommend:

  • (best) either use sandbox in “dev” mode - this gives you a private network, an indexer as well as the fact that each transaction creates a block, which makes testing even faster. See GitHub - algorand/sandbox: Algorand node sandbox
  • or use sandbox in “release” mode - same as above but blocks are created every 3.5s or so like on the normal netowkr
  • or use a free public API endpoint: Ecosystem Tools & Projects | Algorand Developer Portal (not all endpoints on this page are for algod/indexer but many are). (For production, you will want to review the terms and conditions / SLA for these endpoints - but for development, they are a good solution)

In general, using TestNet is more in a second phase where you want to allow outside people to test your project. You most likely want to start with a private network.

See Install a node - Algorand Developer Portal for all information about how to run nodes.

Okay thanks @fabrice !
I’ll try to do this!