Purpose: instructions to download and create a script that allows users to query a subnet and discover the future next adjustment interval block will be (and provide an approximate time to adjustment), using a terminal window.
const { ApiPromise, WsProvider } = require("@polkadot/api");
const prompt = require("prompt-sync")();
// If you do not want to be prompted for network when running the script,
// change this variable to "finney" to default to the finney endpoint,
// or "local" if you want to default to your own subtensor endpoint.
let network = "";
// If you have your own local subtensor and want to use its entry point, specify
// your entrypoint's wss address here (e.g., "wss://127.0.0.1:443")
let localNetworkEntryPoint = "";
if (network === "") {
network = prompt("Enter network (finney, subvortex, local): ");
}
if ((network === "local" || network === "l") && localNetworkEntryPoint != "") {
networkEntryPoint = localNetworkEntryPoint;
} else {
networkEntryPoint = "wss://entrypoint-finney.opentensor.ai:443";
}
let subnet = prompt("Enter subnet netuid to query:");
if (!(Number.isInteger(subnet)) || subnet < 1 || subnet > 32) {
subnet == 1;
} else {
subnet == subnet;
}
async function queryBittensorData() {
const wsProvider = new WsProvider(
networkEntryPoint );
const api = await ApiPromise.create({ provider: wsProvider });
const [
lastAdjustmentBlock,
adjustmentInterval,
currentBlock,
] = await Promise.all([
api.query.subtensorModule.lastAdjustmentBlock(subnet),
api.query.subtensorModule.adjustmentInterval(subnet),
api.query.system.number(),
]);
let nextAdjustmentBlock = lastAdjustmentBlock.toNumber() + adjustmentInterval.toNumber();
let currentBlockNumber = currentBlock.toNumber();
let blocksToGo = nextAdjustmentBlock - currentBlockNumber;
console.log(`Information for subnet`,subnet);
console.log(`-=-=-=-=-=-=-=-=-=-=-=-=-=-`);
console.log(`Last Adjustment Block: ${lastAdjustmentBlock.toNumber()}`);
console.log(`Adjustment Interval: ${adjustmentInterval.toNumber()}`);
console.log(`Next Adjustment Block: `, nextAdjustmentBlock);
console.log(`Current Block: `, currentBlockNumber);
console.log(`Blocks to go:`,blocksToGo,`in approximately`,blocksToGo*12,`seconds (`,blocksToGo*12/60,`minutes).`);
}
queryBittensorData()
.catch(console.error)
.finally(() => process.exit());
console.warn = () => {};