MoralisWeb3 / react-moralis

Hooks and components to use Moralis in a React app
MIT License
624 stars 166 forks source link

Export chainType #219

Open PatrickAlphaC opened 2 years ago

PatrickAlphaC commented 2 years ago

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

ErnoW commented 2 years ago

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