2

I finished the substrate kitty tutorial (backend and frontend). Now I would like to build a simple frontend for the RMRK pallet. Now I stuck on the .multi(...) method. Where can I find a documentation about this .multi-method?

      unsub = await api.query.rmrkCore.collections.multi(collectionIds, collections => {
          const collectionsMap = collections.map(collection => parseCollection(collection.unwrap()));
          setCollections(collectionsMap);
      });

The collection.unwrap() returns an error because it is [null,null]

--> However, with the following code I get a nice map<id,collections>

const entries = await api.query.rmrkCore.collections.entries();
const ids = entries.map(entry => entry[0]);
setCollectionIds(ids);

My goal is to parse the collections and store them (setCollections(collectionsMap))

I am grateful about any help :)

3
  • Not sure if this is useful but have you taken a look at: github.com/rmrk-team/rmrk-tools#collection
    – Bruno
    Commented Mar 8, 2022 at 14:34
  • Also, where can do you see this multi() method? I cannot find it.
    – Bruno
    Commented Mar 8, 2022 at 21:39
  • 1
    I found the solution :) In the RMRK pallet you don't have to query a collection by it's ID - api.query.rmrkCore.collections.entries() returns already ALL collections. Not sure if this will be performant in the future but for now I get all collection-data for all collections.
    – SiAlDev
    Commented Mar 9, 2022 at 1:26

1 Answer 1

1

I found an example in the polkadot-js-docs. In short: it is a multi-query to retrieve several objects. I guess in the kitty-tutorial first the ids of the single objects are retrieved and second for each id the body is queried in a multi-query.

here the example from the docs:

// Import the API
const { ApiPromise } = require('@polkadot/api');

// Our address for Alice on the dev chain
const ALICE = '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY';
const BOB = '5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty';

async function main () {
  // Create our API with a default connection to the local node
  const api = await ApiPromise.create();

  // Retrieve the last block header, extracting the hash and parentHash
  const { hash, parentHash } = await api.rpc.chain.getHeader();

  console.log(`last header hash ${hash.toHex()}`);

  // Retrieve the balance at the preceding block for Alice. For at queries
  // the format is always `.at(<blockhash>, ...params)`
  const balance = await api.query.system.account.at(parentHash, ALICE);

  console.log(`Alice's balance at ${parentHash.toHex()} was ${balance.data.free}`);

  // Now perform a multi query, returning multiple balances at once
  const balances = await api.query.system.account.multi([ALICE, BOB]);

  console.log(`Current balances for Alice and Bob are ${balances[0].data.free} and ${balances[1].data.free}`);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.