react-moralis icon indicating copy to clipboard operation
react-moralis copied to clipboard

Export chainType

Open PatrickAlphaC opened this issue 3 years ago • 1 comments

New Feature Request

Checklist

Current Limitation

When calling a function that takes a chain as a parameter in typescript, I need to create a new type to do so:



type chainType =
    | "eth"
    | "0x1"
    | "ropsten"
    | "0x3"
    | "rinkeby"
    | "0x4"
    | "goerli"
    | "0x5"
    | "kovan"
    | "0x2a"
    | "polygon"
    | "0x89"
    | "mumbai"
    | "0x13881"
    | "bsc"
    | "0x38"
    | "bsc testnet"
    | "0x61"
    | "avalanche"
    | "0xa86a"
    | "avalanche testnet"
    | "0xa869"
    | "fantom"
    | "0xfa"
    | undefined

type tokenIdMetadataParams = {
    chain: chainType
    address: string
    token_id: string
}

    const options: tokenIdMetadataParams = {
        chain: chainId!.toString() as chainType,
        address: nftAddress,
        token_id: tokenId.toString(),
    }

    const fetchTokenIdMetadata = async () => {
        const tokenIdMetadata = await Web3Api.token.getTokenIdMetadata(options)
        console.log(tokenIdMetadata)
    }

It would be great if we could just import this chainType

PatrickAlphaC avatar Mar 15 '22 17:03 PatrickAlphaC

You can use the Moralis.Chain. but it seems that there are some small differences between these types and the type that gets accepted in the API. Will look into it

ErnoW avatar Mar 15 '22 17:03 ErnoW