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 App IDs from Avail DA
On-chain name of method: dataAvailablity_appKeys
Parameters
parameter | type | optional | description |
---|---|---|---|
key | string | true | The app_id associated with this key will be fetched |
Return value
On failure, a reason for failure is returned. On sucess, the returned JSON object contains:
Owner
: The owner of theapp_id
appID
: The numerical index of theapp_id
Minimal example (Fetch a particular app_id
)
-
You will need to set up the dev enviornment 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:
avail-js
import { SDK } from "avail-js-sdk"
const main = async () => {
const providerEndpoint = "wss://turing-rpc.avail.so/ws"
const sdk = await SDK.New(providerEndpoint)
const key = "Reserved-2"
const value = await sdk.api.query.dataAvailability.appKeys(key)
console.log(value.toHuman())
process.exit()
}
main()
- Run the code using:
ts-node your-file-name.ts
Another example (Fetch all available app_ids
registered on Avail DA)
- Think of the
dataAvailablity_appKeys
as a method that returns all theapp_ids
registered on Avail DA as a mapping of their names to their owner and index. - In most cases a dev will be interested in fetching only a particular
app_id
and not all of them. - We are however including both scenarios here.
- Inside
your-file-name.ts
, add the following code:
avail-js
import { SDK } from "avail-js-sdk"
const main = async () => {
const providerEndpoint = "wss://turing-rpc.avail.so/ws"
const sdk = await SDK.New(providerEndpoint)
const appKeys = await sdk.api.query.dataAvailability.appKeys.entries()
for (const [key, value] of appKeys) {
console.log(key.toHuman())
console.log(value.toHuman())
}
process.exit()
}
main()
- Run the code using:
ts-node your-file-name.ts