2

enter image description here

I tried to figure out the collection id from the api i got an hex value but when i tried to convert that hex to numbers i got an undefined value here is my code i think the hex value which is outside the json is the number value

(async () => {
// Construct
const wsProvider = new WsProvider('wss://westmint-rpc.polkadot.io');
const api = await ApiPromise.create({ provider: wsProvider });

// Do something
  const ADDR = '5DTestUPts3kjeXSTMyerHihn1uwMfLj8vU8sqF7qYrFabHE';
const AccountId32 = '5GCCJthVSwNXRpbeg44gysJUx9vzjdGdfWhioeM7gCg6VyXf';
const u32 = '4';
// Retrieve the last timestamp
const collectionMetadataOf = await api.query.nfts.collectionMetadataOf.entries();
const accounts = api.query.nfts.collectionMetadataOf.entries();
console.log(`${collectionMetadataOf} `);
const obj = JSON.parse(`${collectionMetadataOf} `);
console.log(obj.data)



> Running this code in terminals using node js returns
> node index.js
> return : 
2023-07-13 19:28:26        API/INIT: westmint/9435: Not decorating runtime apis without matching versions: FungiblesApi/2 (1 known)
2023-07-13 19:28:26        API/INIT: westmint/9435: Not decorating unknown runtime apis: 0x8a8047a53a8277ec/1
0xe8d49389c2e23e152fdd6364daadd2cc7c447fa0f5e1581c6e2b96cd7bee295111d2df4e979aa105cf552e9544ebd2b500000000,{"deposit":10087500000,"data":"0x516d584d6452365a75664770533247313248546b6b524b7355766977327238526f4c333472624752643675736742"},0xe8d49389c2e23e152fdd6364daadd2cc7c447fa0f5e1581c6e2b96cd7bee29511c8a02f456942930c9730654ca687a3a04000000,{"deposit":10087500000,"data":"0x516d507955664b50776337475434577978554e414c506f50733563655068364736376974465270737a5753594d38"},0xe8d49389c2e23e152fdd6364daadd2cc7c447fa0f5e1581c6e2b96cd7bee29513436db8bf2d563cb5d2999a82809eded0b000000,{"deposit":10064500000,"data":"0x"},0xe8d49389c2e23e152fdd6364daadd2cc7c447fa0f5e1581c6e2b96cd7bee2951969e061847da7e84337ea78dc577cd1d05000000,{"deposit":10072500000,"data":"0x48656c6c6f20436f6c6c656374696f6e"},0xe8d49389c2e23e152fdd6364daadd2cc7c447fa0f5e1581c6e2b96cd7bee295199850724010e3222888eeb8478c9ffd307000000,{"deposit":10070000000,"data":"0x68656c6c6f20616761696e"},0xe8d49389c2e23e152fdd6364daadd2cc7c447fa0f5e1581c6e2b96cd7bee2951be1f3931028cc05c2e18a319e8f64f9e08000000,{"deposit":10100000000,"data":"0x697066733a2f2f697066732f6261666b7265696236756632716e6833656d6468336634637a3262726778787432786f6c616e62336f796d68753769616a346a616f773734746b6d"},0xe8d49389c2e23e152fdd6364daadd2cc7c447fa0f5e1581c6e2b96cd7bee2951de18007c0afadc771c45bf719bc7fe5103000000,{"deposit":10087500000,"data":"0x516d6357686b664377586a484a434358596d484c4e4452776f6f744d5548384750465356444a6a554b5170513535"},0xe8d49389c2e23e152fdd6364daadd2cc7c447fa0f5e1581c6e2b96cd7bee2951f71f22775221b1945fe6cfa3c6550c7c09000000,{"deposit":10093500000,"data":"0x697066733a2f2f697066732f516d58625172696d4468583277726b76487676764e345852697852313366766d4b5856676b5a354b48325a6f616e"}


`

1 Answer 1

0

If you want to get the same values as you are getting with PolkadotJS UI try this snippet:

const collectionMetadataOf = await api.query.nfts.collectionMetadataOf.entries();
        collectionMetadataOf.forEach(([{ args: [id] }, value]) => {
        const metadata = JSON.parse(`${value}`);
        console.log(id.toHuman());
        console.log(metadata);
});

You can see more information and examples of how to parse the information with entries() in the docs: How do I use .entries()/.keys() on double maps?

2
  • 1
    thanks bro i appreciate your efforts it solved that issue and you also saved my time amazing i was hopeless when i didn't got any solution but you made my day thanks again Commented Jul 18, 2023 at 12:30
  • That's why this site is for, to help devs!
    – Alex Bean
    Commented Jul 18, 2023 at 14:05

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.