Fetch the next available App ID on Avail DA
Query the next unregistered App ID available for claim using the dataAvailability_nextAppId method.
Note
App Ids are core to the dev experience on Avail DA, and we highly recommend you understand how they work before you start working with them.
You can check out our docs for the same.dataAvailability_nextAppId
Note
app_ids, once registered, cannot be claimed by another dev.
You can use this method to fetch the next available app_id for your awesome rollup :)Parameters
None
Returns
app_id: The next available App ID
Minimal example (Fetch the next available app_id)
Note
- You will need to set up the dev environment required to run this example. For instructions, check out our docs here.
- If you're sending an extrinsic (i.e conducting a transaction) you will need to replace the demo seed phrase with your own seed phrase. The rest of the code should work as is.
- Inside
your-file-name.ts, add the following code:
import { SDK, Pallets } from 'avail-js-sdk';
export async function getNextAppId() {
// Initialize SDK with Turing endpoint
const sdk = await SDK.New('wss://turing-rpc.avail.so/ws');
// Get the current block hash
const blockHash = await sdk.client.bestBlockHash();
console.log(`Current block hash: ${blockHash}`);
// Get storage at the current block
const storageAt = await sdk.client.storageAt(blockHash);
// Fetch the next available app ID
const nextAppId = await Pallets.DataAvailabilityStorage.NextAppId.fetch(storageAt);
console.log(`Next available App ID is: ${nextAppId}`);
console.log("App ID fetched successfully");
process.exit(0);
}
// Execute the function
getNextAppId();- Run the code using:
ts-node your-file-name.tsSample Response:
99