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.
Fetch the next available App ID on Avail DA
On-chain name of method: dataAvailability_nextAppId
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
avail-js
- None
Returns
app_id
: The next available App ID
Minimal example (Fetch the next available app_id
)
-
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.
avail-js
- Inside
your-file-name.ts
, add the following code:
avail-js
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}`);
process.exit(0);
}
// Execute the function
getNextAppId();
- Run the code using:
terminal
ts-node your-file-name.ts
Sample Response:
99
Last updated on