shawntabrizi / substrate-collectables-workshop

A guided tutorial for building an NFT marketplace with the Polkadot SDK
https://www.shawntabrizi.com/substrate-collectables-workshop/
MIT License
236 stars 101 forks source link

Unknown type to decode #45

Closed arikan closed 5 years ago

arikan commented 5 years ago

Hi @shawntabrizi thank you for the tutorial, it's been very helpful. I had one issue at the very last section. I pass in the type into addCodecTransform in the react component constructor, but I get the Unknown type to decode error below.

I created kitties and sent them to accounts using the polkadot-js app. I created kitties for different accounts in the oo7 app, however, I got the error below while trying to decode and show the kitty cards.

I have oo7-substrate ^0.4.11

// in the constructor
addCodecTransform('Kitty<Hash,Balance>', {
    id: 'Hash',
    dna: 'Hash',
    price: 'Balance',
    gen: 'u64'
});

// in the console
runtime.substratekitties.allKittiesCount.then(console.log)
8
runtime.substratekitties.allKittiesArray(0).then((result) => { hash = result })
runtime.substratekitties.kitties(hash).then(console.log)

Uncaught Unknown type to decode: Kitty<Hash,Balance>
    decode @ codec.js:363
    StorageBond.r @ storageBond.js:16
    callback @ subscriptionBond.js:20
    ws.onmessage @ nodeService.js:86
arikan commented 5 years ago

As far as I see, the custom Kitty struct type passed into addCodecTransform does not satisfy any of the cases, and finally throws Unknown type to decode here.

https://github.com/paritytech/oo7/blob/master/packages/oo7-substrate/src/codec.js#L363

Whereas it should be added in the transforms dynamically, when addCodecTransform called in the react app.jsx constructor.

function addCodecTransform(type, transform) {
    if (!transforms[type]) {
        transforms[type] = transform
    }
}

https://github.com/paritytech/oo7/blob/master/packages/oo7-substrate/src/codec.js#L106

shawntabrizi commented 5 years ago

Issue here was related to an outdated version of oo7-substrate being used.

To solve the issue, you need to run yarn upgrade in the substrate-ui folder. An update to the substrate-ui repo should be able to solve this permanently.