Options
All
  • Public
  • Public/Protected
  • All
Menu

Module contexts/ApiContext

This file defines API context which handles whole communication between web application and Ethereum blockchain. First it ensures whether MetaMask is present and properly configured, then it creates subcontexts (from api/* subfolder) for interacting with blockchain itself and deployed game contracts.

Type aliases

ApiStatus

ApiStatus: "NoProvider" | "NotConnected" | "WrongChain" | "OK"

Possible states of API connection to the blockchain.

  • NoProvider - MetaMask (or equivalent Ethereum provider) is missing completely
  • NotConnected - MetaMask cannot establish connection to the blockchain
  • WrongChain - MetaMask is connected to the wrong chain (other than defined in config)
  • OK - Everything is OK, connection with game contracts could be established

Variables

Const ethereum

Ethereum provider injected to the web by MetaMask. If missing, ApiContextBase state must be NoProvider

Functions

Const createApiContext

  • Function for creating global API context. This function should be called exactly once through the whole application.

    Parameters

    • db: DatabaseContext

      Global database context, which is needed for caching information obtained by API

    • notify: NotifyContext

      Global notification context, which is needed for letting user know about important API events

    Returns ApiContext | PartialApiContext | NoApiContext

    Global API context in corresponding state

Generated using TypeDoc