klaytn/caver-js

Suggestion to export interfaceIds from caver.kct module

Closed this issue · 0 comments

I liked that there is caver-kct module that is providing some of the functions that we as app developers might have to write when there is such use-case. So by providing this package, you saved some of my efforts. Thanks for that. :)
However, from my experience, I feel there is a minor scope of enhancement there.

I am developing a simple nft-indexer for KP17. Let me explain this by my code.
It requires me to maintain the interfaceIds in my listener, although kct module already has same(but not currently exported)
In order to find the type of contract and supported interfaces i am keeping a copy and then checking against it.
refer to below :
https://github.com/narendracode/klaytn-graph/blob/master/packages/listener/src/util.ts
https://github.com/narendracode/klaytn-graph/blob/master/packages/listener/src/index.ts#L21

const isKP17 = await nftContract.methods.supportsInterface(interfaceIds.kip17.IKIP17).call();
const isIKIP17Metadata = await nftContract.methods.supportsInterface(interfaceIds.kip17.IKIP17Metadata).call();
const isIKIP17Enumerable = await nftContract.methods.supportsInterface(interfaceIds.kip17.IKIP17Enumerable).call();

It would be good to expose the interfaceIds so that developers do not have to keep a copy of same.
If developers would like to look for support for custom interfaces then it makes sense to extend the same and work that way.
Small change is required here
https://github.com/klaytn/caver-js/blob/master/packages/caver-kct/src/index.js

const { interfaceIds } = require('./kctHelper')
...
...
class KCT {
    ...
    ...
    this.kip13.currentProvider = this._requestManager.provider
    this.interfaceIds = interfaceIds
}

Thank you