Options
All
  • Public
  • Public/Protected
  • All
Menu

This package provides some helper utilities for switching between different Ethereum-compatible chains. It also describes the SDK built-in chains, in which it already has a deployed smart contract.

remarks

The current built-in chains are Polygon Mainnet and Polygon Testnet (Mumbai).

remarks

A built-in chain is one that we have already deployed an ERC-721 contract that implements the Video NFT ABI. Those can be used as a default contract with which to mint a Video NFT.

remarks

When using a built-in chain you don't need to provide a contract address on the calls to the Web3 minter for minting an NFT. You can still provide one anyway if you wish to use your own contract, but it does need to implement the Video NFT ABI for the SDK to work properly.

remarks

You can also use custom chains that are not built-in, but you will need always to provide your contract address to the Web3 minter functions and handle any NFT marketplace URLs or integrations.

Index

Type aliases

BuiltinChainInfo: { defaultContract: HexChainId; opensea?: { baseUrl: string; chainName: string }; spec: ChainSpec }

Describes all the information about a built-in chain. Also contains some helper information for generating NFT marketplace links (currently OpenSea).

Type declaration

  • defaultContract: HexChainId
  • Optional opensea?: { baseUrl: string; chainName: string }
    • baseUrl: string
    • chainName: string
  • spec: ChainSpec
ChainSpec: { blockExplorerUrls: string[]; chainId: `0x${string}`; chainName: string; iconUrls?: string[]; nativeCurrency: { decimals: number; symbol: string }; rpcUrls: string[] }

Defines the interface necessary for registering a new chain in a web3 wallet. Especifically tested with MetaMask.

Type declaration

  • [unknown: string]: any
  • blockExplorerUrls: string[]
  • chainId: `0x${string}`
  • chainName: string
  • Optional iconUrls?: string[]
  • nativeCurrency: { decimals: number; symbol: string }
    • [unknown: string]: any
    • decimals: number
    • symbol: string
  • rpcUrls: string[]
HexChainId: `0x${string}`

Hexadecimal representation of a chain ID.

Functions

  • addChain(ethereum: ExternalProvider, chainSpec: ChainSpec): Promise<void>
  • Requests the web3 wallet to add a chain to the wallet and switch to it.

    Parameters

    • ethereum: ExternalProvider

      Web3 connectivity external provider. In the case of MetaMask this is the object injected into window.ethereum.

    • chainSpec: ChainSpec

      The full specification of the chain to add.

    Returns Promise<void>

    Promise that will be fulfilled when the switch is complete (e.g. after user approves it).

  • Gets the information about the built-in chain with the specified chain ID.

    Parameters

    • chainId: string | number

      ID of the chain to get information about.

    Returns BuiltinChainInfo | null

    The built-in chain information or null if it's not built-in.

  • isChainBuiltin(chainId: string | number): boolean
  • Returns whether the chain with the specified ID is built-in.

    Parameters

    • chainId: string | number

      Chain ID to check.

    Returns boolean

    Boolean representing whether the chain is built-in.

  • listBuiltinChains(): `0x${string}`[]
  • Gets a list of the built-in chains IDs.

    Returns `0x${string}`[]

    List of built-in chain IDs in hexadecimal format.

  • switchChain(ethereum: ExternalProvider, chainId: string): Promise<void>
  • Requests the web3 wallet to switch the current chain to the specified one.

    Parameters

    • ethereum: ExternalProvider

      Web3 connectivity external provider. In the case of MetaMask this is the object injected into window.ethereum.

    • chainId: string

      The ID of the chain to switch to.

    Returns Promise<void>

    Promise that will be fulfilled when the switch is complete (e.g. after user approves it).

  • switchOrAddChain(ethereum: ExternalProvider, chainSpec: ChainSpec): Promise<{ added: boolean }>
  • Composes switchChain and addChain to switch to the specified chain if it is already configured or otherwise add it to the wallet and then switch to it.

    Parameters

    • ethereum: ExternalProvider

      Web3 connectivity external provider. In the case of MetaMask this is the object injected into window.ethereum.

    • chainSpec: ChainSpec

      The full specification of the chain to switch to or add.

    Returns Promise<{ added: boolean }>

    Object with a single added field indicating whether the chain was switched to or added. An exception is thrown if the operation is unsucessful (e.g. the user rejects the request in the wallet).

  • toHexChainId(chainId: string | number): HexChainId
  • Normalizes any representation of a chain ID into a hexadecimal string, in a format supported by web3 wallets.

    Parameters

    • chainId: string | number

      Chain ID to normalize.

    Returns HexChainId

    Normalized hexadecimal string representing the chain ID.

  • toNumberChainId(chainId: string | number): number
  • Converts any representation of a chain ID into its numerical ID.

    Parameters

    • chainId: string | number

      Chain ID to convert.

    Returns number

    Numerical ID of the chain.

Generated using TypeDoc