### Initialize Vue App with Polkadot-JS Keyring Source: https://github.com/polkadot-js/docs/blob/master/docs/ui-keyring/start/init.md This snippet shows the initialization of the Polkadot-JS keyring followed by mounting a Vue application. Similar to the React example, it waits for WASM libraries and keyring data to be ready before creating and mounting the Vue instance. This ensures that the application has access to the keyring when it starts. ```javascript import keyring from '@polkadot/ui-keyring'; import { cryptoWaitReady } from '@polkadot/util-crypto'; import Vue from 'vue'; import App from './App.vue'; // Assuming App is your main Vue component cryptoWaitReady().then(() => { keyring.loadAll({ ... }); // Configuration options for keyring.loadAll // mount Vue and render new Vue({ render: (h) => h(App) }).$mount('#app'); }); ``` -------------------------------- ### Get Storage Keys with Pagination (Polkadot-JS) Source: https://github.com/polkadot-js/docs/blob/master/docs/asset-hub-kusama/rpc.md Returns storage keys matching a prefix with pagination support. This is the recommended method for retrieving keys. Requires a storage key (prefix), a count for pagination, an optional start key, and an optional block hash. ```javascript api.rpc.state.getKeysPaged(key, count, startKey, at).then((result) => { console.log(result); }); ``` -------------------------------- ### Start Migration Source: https://github.com/polkadot-js/docs/blob/master/docs/asset-hub-kusama/extrinsics.md Initiates the data migration process. Typically called by the Relay Chain to start migration on Asset Hub and receive a handshake. ```APIDOC ## POST /api/tx/ahMigrator/startMigration ### Description Start the data migration. This is typically called by the Relay Chain to start the migration on the Asset Hub and receive a handshake message indicating the Asset Hub's readiness. ### Method POST ### Endpoint /api/tx/ahMigrator/startMigration ### Parameters No parameters required. ### Request Example ```json { } ``` ### Response #### Success Response (200) - **result** (null) - Indicates successful execution. #### Response Example ```json { "result": null } ``` ``` -------------------------------- ### Tasks Example Module API Source: https://github.com/polkadot-js/docs/blob/master/docs/substrate/storage.md Provides examples related to task management and summation. ```APIDOC ## GET /api/query/tasksExample/numbers ### Description Retrieves a list of numbers to be added to a running total. ### Method GET ### Endpoint /api/query/tasksExample/numbers ### Response #### Success Response (200) - **numbers** (Option) - A list of numbers, or null if none are available. ### Response Example ```json { "numbers": [10, 20, 30] } ``` ``` ```APIDOC ## GET /api/query/tasksExample/total ### Description Retrieves the current running total. ### Method GET ### Endpoint /api/query/tasksExample/total ### Response #### Success Response (200) - **total** (u32) - The current running total. ### Response Example ```json { "total": 60 } ``` ``` -------------------------------- ### Install Polkadot JS API and Contract Packages with Yarn Source: https://github.com/polkadot-js/docs/blob/master/docs/api-contract/start/install.md Installs the `@polkadot/api` and `@polkadot/api-contract` packages using Yarn. It is recommended to keep the versions of these two packages in lock-step to ensure compatibility. ```bash yarn add @polkadot/api @polkadot/api-contract ``` -------------------------------- ### Initialize Polkadot-JS Keyring with Polkadot-JS API Source: https://github.com/polkadot-js/docs/blob/master/docs/ui-keyring/start/init.md This example demonstrates initializing the Polkadot-JS keyring in conjunction with the Polkadot-JS API. Since `ApiPromise.create()` already handles WASM availability, the `cryptoWaitReady()` call is omitted. The keyring is loaded after the API is successfully created, allowing for synchronized initialization of both services. ```javascript import { ApiPromise } from '@polkadot/api'; import keyring from '@polkadot/ui-keyring'; // Assume ApiPromise is configured and created elsewhere, e.g.: // const api = await ApiPromise.create({ ... }); ApiPromise.create({ ... }).then((api) => { keyring.loadAll({ ... }); // Configuration options for keyring.loadAll, potentially using api.genesisHash // additional initialization here, including rendering }); ``` -------------------------------- ### Get All Extension Accounts with Polkadot-JS Source: https://github.com/polkadot-js/docs/blob/master/docs/extension/cookbook.md Retrieves all accounts from installed browser extensions that the user has authorized. This function is crucial for dApps to identify and interact with user accounts. It requires calling `web3Enable` first to get extension details and user authorization. ```javascript import { web3Accounts, web3Enable, web3FromSource } from '@polkadot/extension-dapp'; // this call fires up the authorization popup const extensions = await web3Enable('my cool dapp'); if (extensions.length === 0) { // no extension installed, or the user did not accept the authorization // in this case we should inform the use and give a link to the extension return; } // we are now informed that the user has at least one extension and that we // will be able to show and use accounts const allAccounts = await web3Accounts(); ``` -------------------------------- ### Initialize React App with Polkadot-JS Keyring Source: https://github.com/polkadot-js/docs/blob/master/docs/ui-keyring/start/init.md This code illustrates how to initialize the Polkadot-JS keyring and then mount a React application. The `cryptoWaitReady()` and `keyring.loadAll()` calls are executed within a promise chain, ensuring the keyring is ready before the React app is rendered to the DOM element with the ID 'app'. This pattern is common in Polkadot-JS UI examples. ```javascript import keyring from '@polkadot/ui-keyring'; import { cryptoWaitReady } from '@polkadot/util-crypto'; import ReactDOM from 'react-dom'; import App from './App'; // Assuming App is your main React component cryptoWaitReady().then(() => { keyring.loadAll({ ... }); // Configuration options for keyring.loadAll // mount React and render ReactDOM.render(, document.getElementById('app')); }); ``` -------------------------------- ### Bounties Pallet Bounty Count Query Example (JavaScript) Source: https://github.com/polkadot-js/docs/blob/master/docs/polkadot/storage.md This snippet demonstrates how to get the total number of bounty proposals made in the Bounties pallet using the polkadot-js API. ```javascript const bountyCount = await api.query.bounties.bountyCount(); console.log('Total number of bounties:', bountyCount.toString()); ``` -------------------------------- ### Polkadot-JS Keyring Initialization with Custom Store Source: https://github.com/polkadot-js/docs/blob/master/docs/ui-keyring/start/init.md This snippet illustrates how to initialize the Polkadot-JS keyring using a custom store, such as `ExtensionStore` (often used in browser extensions) or `FileStore` (for Electron environments). By providing a specific store instance to `keyring.loadAll()`, you can override the default browser `localStorage` behavior for storing keyring data. ```javascript // For file storage where available, e.g. in Electron environments. // import { FileStore } from '@polkadot/ui-keyring/stores'; // const fileStore = new FileStore('~./keyring-data'); // ExtensionStore is available in https://github.com/polkadot-js/extension // import { ExtensionStore } from '@polkadot/ui-keyring/stores'; // Hypothetical path // const extensionStore = new ExtensionStore(); import keyring from '@polkadot/ui-keyring'; // Example using a hypothetical ExtensionStore keyring.loadAll({ store: extensionStore, ... }); // Example using FileStore (if imported and instantiated) // keyring.loadAll({ store: fileStore, ... }); // When the store is not specified, it defaults to new BrowserStore() // import { BrowserStore } from '@polkadot/ui-keyring/stores'; ``` -------------------------------- ### Get Grandpa Stalled Status (Option<(u32,u32)>) Source: https://github.com/polkadot-js/docs/blob/master/docs/substrate/storage.md Checks if the Grandpa consensus mechanism is currently stalled. Returns a tuple of block numbers if stalled, indicating the start and end of the stalled period. ```javascript const stalled = await api.query.grandpa.stalled(); console.log(stalled.toString()); ``` -------------------------------- ### Get Society Info - JavaScript Source: https://github.com/polkadot-js/docs/blob/master/docs/derives/derives.md Retrieves overall information for a society. This function is asynchronous and returns society details. Note: The example currently calls `candidates()` and might be a typo, it should likely call `info()`. ```javascript const societyInfo = await api.derive.society.candidates(); console.log(societyInfo); ``` -------------------------------- ### Proxy Module: createPure Source: https://github.com/polkadot-js/docs/blob/master/docs/substrate/extrinsics.md Spawns a fresh new account that is guaranteed to be otherwise inaccessible, and initializes it with a proxy. ```APIDOC ## POST /api/tx/proxy/createPure ### Description Spawns a fresh new account that is guaranteed to be otherwise inaccessible, and initializes it with a proxy of `proxy_type` for `origin` sender. Requires a `Signed` origin. ### Method POST ### Endpoint /api/tx/proxy/createPure ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **proxy_type** (KitchensinkRuntimeProxyType) - Required - The type of the proxy that the sender will be registered as over the new account. - **index** (u16) - Required - A disambiguation index, in case this is called multiple times in the same transaction. - **delay** (u32) - Required - The announcement period required of the initial proxy. ### Request Example ```json { "proxy_type": "Any", "index": 0, "delay": 0 } ``` ### Response #### Success Response (200) - **result** (string) - A success message indicating the pure account was created. #### Response Example ```json { "result": "Pure account created successfully." } ``` ``` -------------------------------- ### forceNewEraAlways Source: https://github.com/polkadot-js/docs/blob/master/docs/substrate/extrinsics.md Force there to be a new era at the end of sessions indefinitely. The dispatch origin must be Root. Warning: The election process starts multiple blocks before the end of the era. If this is called just before a new era is triggered, the election process may not have enough blocks to get a result. ```APIDOC ## POST /api/tx/staking/forceNewEraAlways ### Description Indefinitely forces the creation of a new era at the end of each session. This action requires Root origin. Similar to `forceNewEra`, calling this near an era's end may interfere with the election process. Ensure sufficient time for election results before execution. ### Method POST ### Endpoint /api/tx/staking/forceNewEraAlways ### Parameters *No parameters required.* ### Request Example ```json {} ``` ### Response #### Success Response (200) - **result** (string) - Confirmation message of the operation. #### Response Example ```json { "result": "New eras will be forced indefinitely." } ``` -------------------------------- ### POST /api/tx/proxy/createPure Source: https://github.com/polkadot-js/docs/blob/master/docs/asset-hub-kusama/extrinsics.md Spawns a new, inaccessible account and initializes it with a proxy for the sender. Requires a signed origin and incurs a deposit. ```APIDOC ## POST /api/tx/proxy/createPure ### Description Spawn a fresh new account that is guaranteed to be otherwise inaccessible, and initialize it with a proxy of `proxy_type` for the origin sender. Requires a `Signed` origin. Fails with `Duplicate` if this has already been called in this transaction, from the same sender, with the same parameters. Fails if there are insufficient funds to pay for deposit. ### Method POST ### Endpoint /api/tx/proxy/createPure ### Parameters #### Query Parameters - **proxy_type** (AssetHubKusamaRuntimeProxyType) - Required - The type of the proxy that the sender will be registered as over the new account. - **delay** (u32) - Required - The announcement period required of the initial proxy. Will generally be zero. - **index** (u16) - Required - A disambiguation index, in case this is called multiple times in the same transaction. ### Request Example ```json { "proxy_type": "Any", "delay": 0, "index": 0 } ``` ### Response #### Success Response (200) - **result** (object) - Transaction details upon successful submission. #### Response Example ```json { "result": { "status": "ExtrinsicStatus.InBlock", "hash": "0x..." } } ``` ``` -------------------------------- ### Get Transaction Payment Information with Polkadot-JS Source: https://github.com/polkadot-js/docs/blob/master/docs/api/start/api.tx.subs.md This example illustrates how to retrieve the estimated weight and fees for a transaction before sending it. It uses the `.paymentInfo` method on an encoded transaction, which takes the sender's keypair as an argument. The `partialFee` and `weight` are then logged to the console. ```javascript // construct a transaction const transfer = api.tx.balances.transferKeepAlive(BOB, 12345); // retrieve the payment info const { partialFee, weight } = await transfer.paymentInfo(alice); console.log(`transaction will have a weight of ${weight}, with ${partialFee.toHuman()} weight fees`); // send the tx transfer.signAndSend(alice, ({ events = [], status }) => { ... }); ``` -------------------------------- ### Create and Manage Keypairs Source: https://context7.com/polkadot-js/docs/llms.txt Generate keypairs with mnemonics and manage cryptographic keys. This example demonstrates creating keyrings, generating mnemonics, and adding/creating pairs. ```javascript import { Keyring } from '@polkadot/keyring'; import { cryptoWaitReady, mnemonicGenerate } from '@polkadot/util-crypto'; async function main() { // we only need to do this once per app, somewhere in our init code // (when using the API and waiting on `isReady` this is done automatically) await cryptoWaitReady(); // create a keyring with some non-default values specified const keyring = new Keyring({ type: 'sr25519', ss58Format: 2 }); // generate a mnemonic with default params (we can pass the number // of words required 12, 15, 18, 21 or 24, less than 12 words, while // valid, is not supported since it is more-easily crackable) const mnemonic = mnemonicGenerate(); // create & add the pair to the keyring with the type and some additional // metadata specified const pair = keyring.addFromUri(mnemonic, { name: 'first pair' }, 'ed25519'); // the pair has been added to our keyring console.log(keyring.pairs.length, 'pairs available'); // log the name & address (the latter encoded with the ss58Format) console.log(pair.meta.name, 'has address', pair.address); // create an ed25519 pair from the mnemonic const ep = keyring.createFromUri(mnemonic, { name: 'ed25519' }, 'ed25519'); // create an sr25519 pair from the mnemonic (keyring defaults) const sp = keyring.createFromUri(mnemonic, { name: 'sr25519' }); // log the addresses, different cryptos, different results console.log(ep.meta.name, ep.address); console.log(sp.meta.name, sp.address); } main().catch(console.error); ``` -------------------------------- ### forceNewEra Source: https://github.com/polkadot-js/docs/blob/master/docs/substrate/extrinsics.md Force there to be a new era at the end of the next session. After this, it will be reset to normal (non-forced) behaviour. The dispatch origin must be Root. Warning: The election process starts multiple blocks before the end of the era. If this is called just before a new era is triggered, the election process may not have enough blocks to get a result. ```APIDOC ## POST /api/tx/staking/forceNewEra ### Description Forces the system to initiate a new era at the conclusion of the upcoming session. Normal operation will resume thereafter. This action requires Root origin. Be aware that calling this close to an era's natural end might disrupt the election process due to insufficient time for results. The operation has O(1) complexity. ### Method POST ### Endpoint /api/tx/staking/forceNewEra ### Parameters *No parameters required.* ### Request Example ```json {} ``` ### Response #### Success Response (200) - **result** (string) - Confirmation message of the operation. #### Response Example ```json { "result": "New era forced successfully." } ``` -------------------------------- ### POST /api/stateTrieMigration/migrateCustomTop Source: https://github.com/polkadot-js/docs/blob/master/docs/substrate/extrinsics.md Migrate the list of top keys by iterating each of them one by one. This does not affect the global migration process tracker. ```APIDOC ## POST /api/stateTrieMigration/migrateCustomTop ### Description Migrate the list of top keys by iterating each of them one by one. This does not affect the global migration process tracker ([`MigrationProcess`]), and should only be used in case any keys are leftover due to a bug. ### Method POST ### Endpoint /api/stateTrieMigration/migrateCustomTop ### Parameters #### Request Body - **keys** (Vec) - Required - A list of top keys to migrate. - **witness_size** (u32) - Required - The witness size for the migration. ### Request Example ```json { "keys": ["0x1122", "0x3344"], "witness_size": 256 } ``` ### Response #### Success Response (200) - **result** (string) - Indicates the successful migration of custom top keys. #### Response Example ```json { "result": "Custom top keys migrated successfully." } ``` ``` -------------------------------- ### forceNewEraAlways Source: https://github.com/polkadot-js/docs/blob/master/docs/kusama/extrinsics.md Force there to be a new era at the end of sessions indefinitely. The dispatch origin must be Root. Warning: The election process starts multiple blocks before the end of the era. If this is called just before a new era is triggered, the election process may not have enough blocks to get a result. ```APIDOC ## POST /api/staking/forceNewEraAlways ### Description Continuously forces a new era to begin at the end of every session indefinitely. This operation requires Root privileges. ### Method POST ### Endpoint /api/staking/forceNewEraAlways ### Parameters * No parameters are required. ### Request Example ```json {} ``` ### Response #### Success Response (200) - **result** (string) - Indicates the success of the operation. #### Response Example ```json { "result": "Indefinite new era forcing enabled." } ``` ``` -------------------------------- ### Proxy Create Pure API Source: https://github.com/polkadot-js/docs/blob/master/docs/asset-hub-polkadot/extrinsics.md Spawns a new account that is inaccessible except through proxy configurations. It initializes the account with a specified proxy type for the sender. ```APIDOC ## POST /api/tx/proxy/createPure ### Description Spawn a fresh new account that is guaranteed to be otherwise inaccessible, and initialize it with a proxy of `proxy_type` for `origin` sender. Requires a `Signed` origin. Fails with `Duplicate` if this has already been called in this transaction, from the same sender, with the same parameters. Fails if there are insufficient funds to pay for deposit. ### Method POST ### Endpoint /api/tx/proxy/createPure ### Parameters #### Request Body - **proxy_type** (AssetHubPolkadotRuntimeProxyType) - Required - The type of the proxy that the sender will be registered as over the new account. - **delay** (u32) - Required - The announcement period required of the initial proxy. Will generally be zero. - **index** (u16) - Required - A disambiguation index, in case this is called multiple times in the same transaction. ### Request Example ```json { "proxy_type": "Any", "delay": 0, "index": 0 } ``` ### Response #### Success Response (200) - **result** (string) - The dispatch result (e.g., extrinsic hash). #### Response Example ```json { "result": "0x..." } ``` ``` -------------------------------- ### Subscribe to Balance Changes Source: https://context7.com/polkadot-js/docs/llms.txt Monitor account balance changes using subscription callbacks. This example retrieves the initial balance and then subscribes to updates, logging any changes. ```javascript const { ApiPromise } = require('@polkadot/api'); // Known account we want to use (available on dev chain, with funds) const ALICE = '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY'; async function main () { // Create an await for the API const api = await ApiPromise.create(); // Retrieve the initial balance. Since the call has no callback, it is simply a promise // that resolves to the current on-chain value let { data: { free: previousFree }, nonce: previousNonce } = await api.query.system.account(ALICE); console.log(`${ALICE} has a balance of ${previousFree}, nonce ${previousNonce}`); console.log(`You may leave this example running and start example 06 or transfer any value to ${ALICE}`); // Here we subscribe to any balance changes and update the on-screen value api.query.system.account(ALICE, ({ data: { free: currentFree }, nonce: currentNonce }) => { // Calculate the delta const change = currentFree.sub(previousFree); // Only display positive value changes (Since we are pulling `previous` above already, // the initial balance change will also be zero) if (!change.isZero()) { console.log(`New balance change of ${change}, nonce ${currentNonce}`); previousFree = currentFree; previousNonce = currentNonce; } }); } main().catch(console.error); ``` -------------------------------- ### startDestroy Source: https://github.com/polkadot-js/docs/blob/master/docs/asset-hub-kusama/extrinsics.md Start the process of destroying a fungible asset class. This is the first in a series of extrinsics that should be called to allow destruction of an asset class. ```APIDOC ## POST /tx/assets/startDestroy ### Description Start the process of destroying a fungible asset class. `start_destroy` is the first in a series of extrinsics that should be called, to allow destruction of an asset class. The origin must conform to `ForceOrigin` or must be `Signed` by the asset's `owner`. It will fail with either [`Error::ContainsHolds`] or [`Error::ContainsFreezes`] if an account contains holds or freezes in place. ### Method POST ### Endpoint /tx/assets/startDestroy ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **id** (Compact) - Required - The identifier of the asset to be destroyed. This must identify an existing asset. ### Request Example ```json { "id": "1" } ``` ### Response #### Success Response (200) - **result** (Extrinsic) - The extrinsic to be signed and sent. #### Response Example ```json { "result": "0x..." } ``` ``` -------------------------------- ### forceNewEra Source: https://github.com/polkadot-js/docs/blob/master/docs/kusama/extrinsics.md Force there to be a new era at the end of the next session. After this, it will be reset to normal (non-forced) behaviour. The dispatch origin must be Root. Warning: The election process starts multiple blocks before the end of the era. If this is called just before a new era is triggered, the election process may not have enough blocks to get a result. ```APIDOC ## POST /api/staking/forceNewEra ### Description Forces a new era to begin at the conclusion of the next session. Following this, the system reverts to its standard, non-forced era progression. This operation requires Root privileges. ### Method POST ### Endpoint /api/staking/forceNewEra ### Parameters * No parameters are required. ### Request Example ```json {} ``` ### Response #### Success Response (200) - **result** (string) - Indicates the success of the operation. #### Response Example ```json { "result": "New era forced successfully." } ``` ``` -------------------------------- ### ParaScheduler Session Start Block API Source: https://github.com/polkadot-js/docs/blob/master/docs/polkadot/storage.md Retrieves the block number where the current session started. ```APIDOC ## GET /api/paraScheduler/sessionStartBlock ### Description Retrieves the block number at which the current session started. This is used to track the number of group rotations. Session changes are signaled during a block and enacted at finalization, with effects observed in the following block. ### Method GET ### Endpoint /api/paraScheduler/sessionStartBlock ### Parameters ### Request Body ### Request Example ```json {} ``` ### Response #### Success Response (200) - **sessionStartBlock** (u32) - The block number of the session start. #### Response Example ```json { "sessionStartBlock": 12345 } ``` ``` -------------------------------- ### Eras Start Session Index Source: https://github.com/polkadot-js/docs/blob/master/docs/polkadot/storage.md Retrieves the session index at which an era started for the last `Config::HistoryDepth` eras. ```APIDOC ## GET / Eras Start Session Index ### Description Retrieves the session index at which an era started for the last `Config::HistoryDepth` eras. Tracks the starting session for eras within the history depth. ### Method GET ### Endpoint `api.query.staking.erasStartSessionIndex(era: u32)` ### Parameters #### Path Parameters - **era** (u32) - Required - The era index. ### Response #### Success Response (200) - **Option** - An optional session index. #### Response Example ```json 1234 ``` ``` -------------------------------- ### startDestroy Source: https://github.com/polkadot-js/docs/blob/master/docs/asset-hub-polkadot/extrinsics.md Initiates the process of destroying a fungible asset class. This extrinsic requires the origin to be ForceOrigin or Signed by the asset's owner. It will fail if the asset has holds or freezes. ```APIDOC ## POST /api/poolAssets/startDestroy ### Description Start the process of destroying a fungible asset class. This is the first in a series of extrinsics for asset destruction. ### Method POST ### Endpoint /api/poolAssets/startDestroy ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **id** (u32) - Required - The identifier of the asset to be destroyed. Must identify an existing asset. ### Request Example ```json { "id": 123 } ``` ### Response #### Success Response (200) - **message** (string) - Indicates the operation was successful. #### Response Example ```json { "message": "startDestroy initiated successfully" } ``` ### Errors - `ContainsHolds`: If an account contains holds. - `ContainsFreezes`: If an account contains freezes. ``` -------------------------------- ### Make RPC Queries Source: https://context7.com/polkadot-js/docs/llms.txt Perform direct RPC calls to retrieve chain information and subscribe to updates. This example fetches the chain name, latest header, and subscribes to new headers. ```javascript const { ApiPromise } = require('@polkadot/api'); async function main () { const api = await ApiPromise.create(); // Retrieve the chain name const chain = await api.rpc.system.chain(); // Retrieve the latest header const lastHeader = await api.rpc.chain.getHeader(); // Log the information console.log(`${chain}: last block #${lastHeader.number} has hash ${lastHeader.hash}`); let count = 0; // Subscribe to the new headers const unsubHeads = await api.rpc.chain.subscribeNewHeads((lastHeader) => { console.log(`${chain}: last block #${lastHeader.number} has hash ${lastHeader.hash}`); if (++count === 10) { unsubHeads(); } }); } main().catch(console.error); ``` -------------------------------- ### Pallet Example MBMS API Endpoints Source: https://github.com/polkadot-js/docs/blob/master/docs/substrate/storage.md Query methods for the Pallet Example MBMS pallet. ```APIDOC ## myMap(key: u32) ### Description Define a storage item to illustrate multi-block migrations. ### Method GET ### Endpoint /api/query/palletExampleMbms/myMap/{key} ### Parameters #### Path Parameters - **key** (u32) - Required - The key for the map. #### Query Parameters - **at** (string) - Optional - The block hash to query at. ### Response #### Success Response (200) - **result** (Option) - The value associated with the key. #### Response Example ```json { "result": "12345" } ``` ``` -------------------------------- ### Create Other Asset Account - Polkadot-JS Source: https://github.com/polkadot-js/docs/blob/master/docs/asset-hub-polkadot/extrinsics.md Creates an asset account for a specified 'who'. A deposit is taken from the signer, who must be the Freezer or Admin of the asset and have sufficient funds. The origin must be Signed. ```javascript import api from '@polkadot/api'; async function touchOtherAssetAccount(api, id, who) { const unsub = await api.tx.assets.touchOther(id, who).signAndSend(senderAddress, ({ events, status }) => { if (status.isInBlock) { console.log('Included at block hash', status.asInBlock.toHex()); console.log('Events:'); events.forEach(({ phase, event: { data, method, section } }) => { console.log(' ', `${phase.toString()} : ${section}.${method} with data ${data.toString()}`); }); } }); } ``` -------------------------------- ### POST /api/foreignAssets/startDestroy Source: https://github.com/polkadot-js/docs/blob/master/docs/asset-hub-polkadot/extrinsics.md Initiates the process of destroying a fungible asset class. This is the first step in a series of extrinsics for asset destruction. The origin must be ForceOrigin or Signed by the asset's owner. ```APIDOC ## POST /api/foreignAssets/startDestroy ### Description Start the process of destroying a fungible asset class. `start_destroy` is the first in a series of extrinsics that should be called, to allow destruction of an asset class. The origin must conform to `ForceOrigin` or must be `Signed` by the asset's `owner`. ### Method POST ### Endpoint /api/foreignAssets/startDestroy ### Parameters #### Request Body - **id** (StagingXcmV5Location) - Required - The identifier of the asset to be destroyed. This must identify an existing asset. ### Request Example ```json { "id": "StagingXcmV5Location" } ``` ### Response #### Success Response (200) - **Success** (bool) - Indicates if starting the destruction process was successful. #### Response Example ```json { "Success": true } ``` ``` -------------------------------- ### Eras Start Session Index API Source: https://github.com/polkadot-js/docs/blob/master/docs/substrate/storage.md Retrieves the session index at which an era started for the last `Config::HistoryDepth` eras. ```APIDOC ## GET /api/staking/erasStartSessionIndex ### Description Retrieves the session index at which an era started for the last `Config::HistoryDepth` eras. ### Method GET ### Endpoint `/api/staking/erasStartSessionIndex/{era}` ### Parameters #### Path Parameters - **era** (u32) - Required - The era index. ### Response #### Success Response (200) - **sessionIndex** (Option) - The session index when the era started. Returns `null` if not available. #### Response Example ```json { "sessionIndex": 100 } ``` ``` -------------------------------- ### touchOther Source: https://github.com/polkadot-js/docs/blob/master/docs/asset-hub-kusama/extrinsics.md Create an asset account for `who`. A deposit will be taken from the signer account. ```APIDOC ## POST /tx/assets/touchOther ### Description Create an asset account for `who`. A deposit will be taken from the signer account. Emits `Touched` event when successful. ### Method POST ### Endpoint /tx/assets/touchOther ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **id** (Compact) - Required - The identifier of the asset for the account to be created. - **who** (MultiAddress) - Required - The account to be created. ### Request Example ```json { "id": "1", "who": "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQy" } ``` ### Response #### Success Response (200) - **result** (Extrinsic) - The extrinsic to be signed and sent. #### Response Example ```json { "result": "0x..." } ``` ``` -------------------------------- ### Get Injected Accounts Source: https://github.com/polkadot-js/docs/blob/master/docs/extension/intro.md Use `web3Accounts` to get a list of all injected accounts across all available extensions. The `meta` property includes the source of the account. ```typescript import { web3Accounts } from "@polkadot/extension-dapp"; async function getAccounts() { const accounts = await web3Accounts(); console.log("Injected accounts:", accounts); } ``` -------------------------------- ### Edgeware Metadata JSON Example Source: https://github.com/polkadot-js/docs/blob/master/docs/api/examples/promise/typegen.md A trimmed example of Edgeware chain metadata in JSON format, as retrieved via a JSONRPC call. This data is used by @polkadot/typegen to generate chain-specific API types. ```json { "jsonrpc": "2.0", "result": "0x6d6574610b6c185379737....", "id": 29 } ``` -------------------------------- ### Create Account from Seed using Keyring (JavaScript) Source: https://github.com/polkadot-js/docs/blob/master/docs/keyring/examples/create-account.md This snippet demonstrates how to create a new account using a seed phrase with the Polkadot JS keyring library. It imports the Keyring class and utility functions, initializes the keyring, and adds an account from a provided seed. The output logs the newly created account's address. Ensure you have '@polkadot/keyring' and '@polkadot/util' installed. ```javascript const { Keyring } = require('@polkadot/keyring'); const { stringToU8a } = require('@polkadot/util'); async function main () { const ALICE_SEED = 'Alice'.padEnd(32, ' '); const keyring = new Keyring(); const pairAlice = keyring.addFromSeed(stringToU8a(ALICE_SEED)); console.log(`Created keyring pair for Alice with address: ${keyring.getPair(pairAlice.address).address}`); } main().catch(console.error).finally(() => process.exit()); ```