@latticexyz/network

# @latticexyz/network

# Table of contents

# Enumerations

# Classes

# Interfaces

# Type Aliases

# Variables

# Functions

# Enumerations

# ConnectionState

ConnectionState: Enum ConnectionState

# Defined in

network/src/createProvider.ts:40


# ContractSchemaValue

ContractSchemaValue: Enum ContractSchemaValue

# Defined in

network/src/types.ts:139


# InputType

InputType: Enum InputType

# Defined in

network/src/workers/SyncWorker.ts:54


# NetworkEvents

NetworkEvents: Enum NetworkEvents

# Defined in

network/src/types.ts:107


# SyncState

SyncState: Enum SyncState

# Defined in

network/src/workers/constants.ts:3

# Classes

# SyncWorker

SyncWorker: Class SyncWorker<C>

# Type parameters

Name Type
C extends Components

# Defined in

network/src/workers/SyncWorker.ts:63

# Interfaces

# ClockConfig

ClockConfig: Interface ClockConfig

# Defined in

network/src/types.ts:25


# NetworkConfig

NetworkConfig: Interface NetworkConfig

# Defined in

network/src/types.ts:10


# ProviderConfig

ProviderConfig: Interface ProviderConfig

# Defined in

network/src/types.ts:39

# Type Aliases

# Ack

Ƭ Ack: Object

# Type declaration

Name Type
type Ack

# Defined in

network/src/workers/SyncWorker.ts:59


# CacheStore

Ƭ CacheStore: ReturnType<typeof createCacheStore>

# Defined in

network/src/workers/CacheStore.ts:12


# Clock

Ƭ Clock: Object

# Type declaration

Name Type
currentTime number
dispose Function
lastUpdateTime number
time$ Observable<number>
update Function

# Defined in

network/src/types.ts:31


# Config

Ƭ Config: Object

# Type declaration

Name Type
data SyncWorkerConfig
type Config

# Defined in

network/src/workers/SyncWorker.ts:58


# ContractConfig

Ƭ ContractConfig: Object

# Type declaration

Name Type
abi ContractInterface
address string

# Defined in

network/src/types.ts:51


# ContractEvent

Ƭ ContractEvent: Object

# Type parameters

Name Type
C extends Contracts

# Type declaration

Name Type
args Result
contractKey keyof C
eventKey string
lastEventInTx boolean
txHash string

# Defined in

network/src/types.ts:67


# ContractSchemaValueTypes

Ƭ ContractSchemaValueTypes: Object

# Type declaration

Name Type
0 boolean
1 number
10 number
11 string
12 string
13 string
14 string
15 string
16 string
17 string
18 boolean[]
19 number[]
2 number
20 number[]
21 number[]
22 string[]
23 string[]
24 string[]
25 string[]
26 number[]
27 number[]
28 number[]
29 string[]
3 number
30 string[]
31 string[]
32 string[]
33 string[]
4 string
5 string
6 string
7 string
8 number
9 number

# Defined in

network/src/types.ts:232


# ContractTopics

Ƭ ContractTopics: Object

# Type declaration

Name Type
key string
topics string[][]

# Defined in

network/src/types.ts:62


# Contracts

Ƭ Contracts: Object

# Index signature

▪ [key: string]: BaseContract

# Defined in

network/src/types.ts:47


# ContractsConfig

Ƭ ContractsConfig: { [key in keyof C]: ContractConfig }

# Type parameters

Name Type
C extends Contracts

# Defined in

network/src/types.ts:56


# ECSCache

Ƭ ECSCache: Awaited<ReturnType<typeof getIndexDbECSCache>>

# Defined in

network/src/workers/CacheStore.ts:13


# Input

Ƭ Input: Config | Ack

# Defined in

network/src/workers/SyncWorker.ts:61


# Mappings

Ƭ Mappings: Object

# Type parameters

Name Type
C extends Components

# Index signature

▪ [hashedContractId: string]: keyof C

# Defined in

network/src/types.ts:76


# Network

Ƭ Network: Awaited<ReturnType<typeof createNetwork>>

# Defined in

network/src/createNetwork.ts:12


# NetworkComponentUpdate

Ƭ NetworkComponentUpdate: { [key in keyof C]: Object }[keyof C] & Object

# Type parameters

Name Type
C extends Components = Components

# Defined in

network/src/types.ts:80


# NetworkEvent

Ƭ NetworkEvent: NetworkComponentUpdate<C> | SystemCall<C>

# Type parameters

Name Type
C extends Components = Components

# Defined in

network/src/types.ts:112


# Providers

Ƭ Providers: ReturnType<typeof createProvider>

# Defined in

network/src/createProvider.ts:8


# State

Ƭ State: Map<number, ComponentValue>

# Defined in

network/src/workers/CacheStore.ts:11


# SyncStateStruct

Ƭ SyncStateStruct: Object

# Type declaration

Name Type
msg string
percentage number
state SyncState

# Defined in

network/src/types.ts:269


# SyncWorkerConfig

Ƭ SyncWorkerConfig: Object

# Type declaration

Name Type
cacheAgeThreshold? number
cacheInterval? number
chainId number
disableCache? boolean
fetchSystemCalls? boolean
initialBlockNumber number
provider ProviderConfig
pruneOptions? Object
pruneOptions.hashedComponentId string
pruneOptions.playerAddress string
snapshotNumChunks? number
snapshotServiceUrl? string
streamServiceUrl? string
worldContract ContractConfig

# Defined in

network/src/types.ts:124


# SystemCall

Ƭ SystemCall: Object

# Type parameters

Name Type
C extends Components = Components

# Type declaration

Name Type
tx SystemCallTransaction
type SystemCall
updates NetworkComponentUpdate<C>[]

# Defined in

network/src/types.ts:101


# SystemCallTransaction

Ƭ SystemCallTransaction: Object

# Type declaration

Name Type
data string
hash string
to string
value BigNumber

# Defined in

network/src/types.ts:94


# TopicsConfig

Ƭ TopicsConfig: { [ContractType in keyof C]: Object }

# Type parameters

Name Type
C extends Contracts

# Defined in

network/src/createTopics.ts:5


# TxQueue

Ƭ TxQueue: Cached<C>

# Type parameters

Name Type
C extends Contracts

# Defined in

network/src/types.ts:60

# Variables

# ContractSchemaValueArrayToElement

Const ContractSchemaValueArrayToElement: Object

# Type declaration

Name Type
0 ContractSchemaValue
1 ContractSchemaValue
10 ContractSchemaValue
11 ContractSchemaValue
12 ContractSchemaValue
13 ContractSchemaValue
14 ContractSchemaValue
15 ContractSchemaValue
16 ContractSchemaValue
17 ContractSchemaValue
18 ContractSchemaValue
19 ContractSchemaValue
2 ContractSchemaValue
20 ContractSchemaValue
21 ContractSchemaValue
22 ContractSchemaValue
23 ContractSchemaValue
24 ContractSchemaValue
25 ContractSchemaValue
26 ContractSchemaValue
27 ContractSchemaValue
28 ContractSchemaValue
29 ContractSchemaValue
3 ContractSchemaValue
30 ContractSchemaValue
31 ContractSchemaValue
32 ContractSchemaValue
33 ContractSchemaValue
4 ContractSchemaValue
5 ContractSchemaValue
6 ContractSchemaValue
7 ContractSchemaValue
8 ContractSchemaValue
9 ContractSchemaValue

# Defined in

network/src/types.ts:213


# ContractSchemaValueId

Const ContractSchemaValueId: { [key in ContractSchemaValue]: string }

# Defined in

network/src/types.ts:176


# GodID

Const GodID: EntityID

# Defined in

network/src/workers/constants.ts:9


# ack

Const ack: Object

# Type declaration

Name Type
type Ack

# Defined in

network/src/workers/SyncWorker.ts:60

# Functions

# createBlockNumberStream

createBlockNumberStream(providers, options?): Object

Creates a stream of block numbers based on the block event of the currently connected provider. In case initialSync is provided, this stream will also output a stream of past block numbers to drive replaying events.

# Parameters

Name Type Description
providers IComputedValue<undefined | Object> Mobx computed providers object (created by createReconnectingProvider).
options? Object
options.initialSync? Object -
options.initialSync.initialBlockNumber number -
options.initialSync.interval number -

# Returns

Object

Stream of block numbers based on connected provider's block event.

Name Type
blockNumber$ Observable<number>
dispose IReactionDisposer

# Defined in

network/src/createBlockNumberStream.ts:15


# createCacheStore

createCacheStore(): Object

# Returns

Object

Name Type
blockNumber number
componentToIndex Map<string, number>
components string[]
entities string[]
entityToIndex Map<string, number>
state State

# Defined in

network/src/workers/CacheStore.ts:19


# createContracts

createContracts<C>(config:): Promise<Object>

Create an object of contracts connected to the currently connected provider.

# Type parameters

Name Type
C extends Contracts

# Parameters

Name Type Description
config: Object ContractsConfig
config:.asyncConfig? Function -
config:.config Partial<ContractsConfig<C>> -
config:.signerOrProvider IComputedValue<Signer | Provider> -

# Returns

Promise<Object>

Object with contracts connected to the currently connected provider.

# Defined in

network/src/createContracts.ts:13


# createDecode

createDecode(worldConfig, provider): Function

Create a function to decode raw component values. Fetches component schemas from the contracts and caches them.

# Parameters

Name Type Description
worldConfig ContractConfig Contract address and interface of the World contract
provider JsonRpcProvider ethers JsonRpcProvider

# Returns

Function

Function to decode raw component values using their contract component id

▸ (componentId, data, componentAddress?): Promise<ComponentValue>

# Parameters
Name Type
componentId string
data BytesLike
componentAddress? string
# Returns

Promise<ComponentValue>

# Defined in

network/src/workers/syncUtils.ts:357


# createDecoder

createDecoder<D>(keys, valueTypes): Function

Construct a decoder function from given keys and valueTypes. The consumer is responsible for providing a type D matching the keys and valueTypes.

# Type parameters

Name Type
D extends Object

# Parameters

Name Type Description
keys (keyof D)[] Keys of the component value schema.
valueTypes ContractSchemaValue[] Value types if the component value schema.

# Returns

Function

Function to decode encoded hex value to component value.

▸ (data): D

# Parameters
Name Type
data BytesLike
# Returns

D

# Defined in

network/src/createDecoder.ts:74


# createEncoder

createEncoder<D>(keys, valueTypes): Function

Creates a function to automatically encode component values given a contract component schema.

# Type parameters

Name Type
D extends Object

# Parameters

Name Type Description
keys (keyof D)[] Schema keys
valueTypes ContractSchemaValue[] Schema value types

# Returns

Function

Function to encode component values

▸ (value): string

# Parameters
Name Type
value D
# Returns

string

# Defined in

network/src/createEncoder.ts:11


# createFaucetService

createFaucetService(url): RawClient<FromTsProtoServiceDefinition<Object>, Object>

Create a FaucetServiceClient

# Parameters

Name Type Description
url string FaucetService URL

# Returns

RawClient<FromTsProtoServiceDefinition<Object>, Object>

FaucetServiceClient

# Defined in

network/src/createFaucetService.ts:9


# createFetchSystemCallsFromEvents

createFetchSystemCallsFromEvents(provider): Function

# Parameters

Name Type
provider JsonRpcProvider

# Returns

Function

▸ (events, blockNumber): Promise<SystemCall<Components>[]>

# Parameters
Name Type
events NetworkComponentUpdate<Components>[]
blockNumber number
# Returns

Promise<SystemCall<Components>[]>

# Defined in

network/src/workers/syncUtils.ts:540


# createFetchWorldEventsInBlockRange

createFetchWorldEventsInBlockRange<C>(provider, worldConfig, batch, decode): Function

Create a function to fetch World contract events in a given block range.

# Type parameters

Name Type
C extends Components

# Parameters

Name Type Description
provider JsonRpcProvider ethers JsonRpcProvider
worldConfig ContractConfig Contract address and interface of the World contract.
batch undefined | boolean Set to true if the provider supports batch queries (recommended).
decode Function Function to decode raw component values (createDecode)

# Returns

Function

Function to fetch World contract events in a given block range.

▸ (from, to): Promise<NetworkComponentUpdate<C>[]>

# Parameters
Name Type
from number
to number
# Returns

Promise<NetworkComponentUpdate<C>[]>

# Defined in

network/src/workers/syncUtils.ts:396


# createLatestEventStreamRPC

createLatestEventStreamRPC(blockNumber$, fetchWorldEvents, fetchSystemCallsFromEvents?): Observable<NetworkEvent>

Create a RxJS stream of NetworkComponentUpdates by listening to new blocks from the blockNumber$ stream and fetching the corresponding block from the connected RPC.

Dev

Only use if createLatestEventStreamService is not available.

# Parameters

Name Type Description
blockNumber$ Observable<number> Block number stream
fetchWorldEvents Function Function to fetch World events in a block range (createFetchWorldEventsInBlockRange).
fetchSystemCallsFromEvents? Function -

# Returns

Observable<NetworkEvent>

Stream of NetworkComponentUpdates.

# Defined in

network/src/workers/syncUtils.ts:254


# createLatestEventStreamService

createLatestEventStreamService(streamServiceUrl, worldAddress, transformWorldEvents, includeSystemCalls): Observable<NetworkEvent>

Create a RxJS stream of NetworkComponentUpdates by subscribing to a gRPC streaming service.

# Parameters

Name Type Description
streamServiceUrl string URL of the gPRC stream service to subscribe to.
worldAddress string Contract address of the World contract to subscribe to.
transformWorldEvents Function Function to transform World events from a stream service (createTransformWorldEventsFromStream).
includeSystemCalls boolean -

# Returns

Observable<NetworkEvent>

Stream of NetworkComponentUpdates.

# Defined in

network/src/workers/syncUtils.ts:208


# createNetwork

createNetwork(initialConfig): Promise<Object>

Set up network.

# Parameters

Name Type Description
initialConfig NetworkConfig Initial config (see NetworkConfig).

# Returns

Promise<Object>

Network object

# Defined in

network/src/createNetwork.ts:20


# createProvider

createProvider(config): Object

Create a JsonRpcProvider and WebsocketProvider pair

# Parameters

Name Type Description
config ProviderConfig Config for the provider pair (see ProviderConfig).

# Returns

Object

Provider pair: { json: JsonRpcProvider, ws: WebSocketProvider }

Name Type
json MUDJsonRpcBatchProvider | MUDJsonRpcProvider
ws undefined | WebSocketProvider

# Defined in

network/src/createProvider.ts:19


# createReconnectingProvider

createReconnectingProvider(config): Promise<Object>

Creates a provider pair that automatically updates if the config changes and automatically reconnects if the connection is lost.

# Parameters

Name Type Description
config IComputedValue<ProviderConfig> Mobx computed provider config object (see ProviderConfig). Automatically updates the returned provider pair if the config changes.

# Returns

Promise<Object>

Automatically reconnecting provider pair that updates if the config changes.

# Defined in

network/src/createProvider.ts:54


# createRelayStream

createRelayStream(signer, url, id): Promise<Object>

Create a RelayService connection, including event$ and utils

# Parameters

Name Type Description
signer Signer -
url string ECSRelayService URL
id string User id (eg address)

# Returns

Promise<Object>

RelayService connection

# Defined in

network/src/createRelayStream.ts:16


# createSigner

createSigner(privateKey, providers): Wallet

# Parameters

Name Type
privateKey string
providers Object
providers.json MUDJsonRpcBatchProvider | MUDJsonRpcProvider
providers.ws undefined | WebSocketProvider

# Returns

Wallet

# Defined in

network/src/createSigner.ts:4


# createSnapshotClient

createSnapshotClient(url): ECSStateSnapshotServiceClient

Create a ECSStateSnapshotServiceClient

# Parameters

Name Type Description
url string ECSStateSnapshotService URL

# Returns

ECSStateSnapshotServiceClient

ECSStateSnapshotServiceClient

# Defined in

network/src/workers/syncUtils.ts:44


# createStreamClient

createStreamClient(url): ECSStreamServiceClient

Create a ECSStreamServiceClient

# Parameters

Name Type Description
url string ECSStreamService URL

# Returns

ECSStreamServiceClient

ECSStreamServiceClient

# Defined in

network/src/workers/syncUtils.ts:53


# createSyncWorker

createSyncWorker<C>(ack$?): Object

Create a new SyncWorker (Sync.worker.ts) to performn contract/client state sync. The main thread and worker communicate via RxJS streams.

# Type parameters

Name Type
C extends Components = Components

# Parameters

Name Type
ack$? Observable<Ack>

# Returns

Object

Object { ecsEvent$: Stream of network component updates synced by the SyncWorker, config$: RxJS subject to pass in config for the SyncWorker, dispose: function to dispose of the sync worker }

Name Type
dispose Function
ecsEvents$ Subject<NetworkEvent<C>[]>
input$ Subject<Input>

# Defined in

network/src/createSyncWorker.ts:17


# createSystemExecutor

createSystemExecutor<T>(world, network, systems, interfaces, gasPrice$, options?): Object

Create a system executor object. The system executor object is an object indexed by available system ids (given in the interfaces object) with tx-queue enabled system contracts as value.

# Type parameters

Name Type
T extends Object

# Parameters

Name Type Description
world World Recs World object.
network Object Network (createNetwork).
network.blockNumber$ Observable<number> -
network.clock Clock -
network.config NetworkConfig -
network.connected IComputedValue<ConnectionState> -
network.connectedAddress IComputedValue<undefined | string> -
network.connectedAddressChecksummed IComputedValue<undefined | string> -
network.dispose Function -
network.providers IComputedValue<Object> -
network.signer IComputedValue<undefined | Signer> -
systems Component<Object, Metadata, undefined> Recs registry component containing the mapping from system address to system id.
interfaces { [key in string | number | symbol]: ContractInterface } Interfaces of the systems to create.
gasPrice$ BehaviorSubject<number> -
options? Object
options.concurrency? number -
options.devMode? boolean -

# Returns

Object

Systems object to call system contracts.

Name Type
getSystemContract Function
registerSystem Function
systems TxQueue<T>

# Defined in

network/src/createSystemExecutor.ts:22


# createTopics

createTopics<C>(config): ContractTopics[]

# Type parameters

Name Type
C extends Contracts

# Parameters

Name Type
config TopicsConfig<C>

# Returns

ContractTopics[]

# Defined in

network/src/createTopics.ts:12


# createTransformWorldEventsFromStream

createTransformWorldEventsFromStream(decode): Function

Create a function to transform World contract events from a stream service response chunk.

# Parameters

Name Type Description
decode Function Function to decode raw component values (createDecode)

# Returns

Function

Function to transform World contract events from a stream service.

▸ (message): Promise<NetworkComponentUpdate<Components>[]>

# Parameters
Name Type
message ECSStreamBlockBundleReply
# Returns

Promise<NetworkComponentUpdate<Components>[]>

# Defined in

network/src/workers/syncUtils.ts:456


# createTxQueue

createTxQueue<C>(computedContracts, network, gasPrice$, options?): Object

The TxQueue takes care of nonce management, concurrency and caching calls if the contracts are not connected. Cached calls are passed to the queue once the contracts are available.

# Type parameters

Name Type
C extends Contracts

# Parameters

Name Type Description
computedContracts IComputedValue<C> | IObservableValue<C> A computed object containing the contracts to be channelled through the txQueue
network Object A network object containing provider, signer, etc
network.blockNumber$ Observable<number> -
network.clock Clock -
network.config NetworkConfig -
network.connected IComputedValue<ConnectionState> -
network.connectedAddress IComputedValue<undefined | string> -
network.connectedAddressChecksummed IComputedValue<undefined | string> -
network.dispose Function -
network.providers IComputedValue<Object> -
network.signer IComputedValue<undefined | Signer> -
gasPrice$ BehaviorSubject<number> -
options? Object The concurrency declares how many transactions can wait for confirmation at the same time.
options.concurrency? number -
options.devMode? boolean -

# Returns

Object

TxQueue object

Name Type
dispose Function
ready IComputedValue<boolean | undefined>
txQueue TxQueue<C>

# Defined in

network/src/createTxQueue.ts:24


# createWorldTopics

createWorldTopics(): ContractTopics[]

Create World contract topics for the ComponentValueSet and ComponentValueRemoved events.

# Returns

ContractTopics[]

World contract topics for the ComponentValueSet and ComponentValueRemoved events.

# Defined in

network/src/workers/syncUtils.ts:382


# ensureNetworkIsUp

ensureNetworkIsUp(provider, wssProvider?): Promise<void>

Await network to be reachable.

# Parameters

Name Type Description
provider JsonRpcProvider ethers JsonRpcProvider
wssProvider? WebSocketProvider ethers WebSocketProvider

# Returns

Promise<void>

Promise resolving once the network is reachable

# Defined in

network/src/networkUtils.ts:22


# fetchBlock

fetchBlock(provider, requireMinimumBlockNumber?): Promise<Block>

Fetch the latest Ethereum block

# Parameters

Name Type Description
provider JsonRpcProvider ethers JsonRpcProvider
requireMinimumBlockNumber? number Minimal required block number. If the latest block number is below this number, the method waits for 1300ms and tries again, for at most 10 times.

# Returns

Promise<Block>

Promise resolving with the latest Ethereum block

# Defined in

network/src/networkUtils.ts:38


# fetchEventsInBlockRange

fetchEventsInBlockRange<C>(provider, topics, startBlockNumber, endBlockNumber, contracts, supportsBatchQueries?): Promise<ContractEvent<C>[]>

Fetch events from block range, ordered by block, transaction index and log index

# Type parameters

Name Type
C extends Contracts

# Parameters

Name Type Description
provider JsonRpcProvider ethers JsonRpcProvider
topics ContractTopics[] Topics to fetch events for
startBlockNumber number Start of block range to fetch events from (inclusive)
endBlockNumber number End of block range to fetch events from (inclusive)
contracts ContractsConfig<C> Contracts to fetch events from
supportsBatchQueries? boolean Set to true if the provider supports batch queries (recommended)

# Returns

Promise<ContractEvent<C>[]>

Promise resolving with an array of ContractEvents

# Defined in

network/src/networkUtils.ts:143


# fetchEventsInBlockRangeChunked

fetchEventsInBlockRangeChunked(fetchWorldEvents, fromBlockNumber, toBlockNumber, interval?, setPercentage?): Promise<NetworkComponentUpdate<Components>[]>

Fetch ECS events from contracts in the given block range.

# Parameters

Name Type Default value Description
fetchWorldEvents Function undefined Function to fetch World events in a block range (createFetchWorldEventsInBlockRange).
fromBlockNumber number undefined Start of block range (inclusive).
toBlockNumber number undefined End of block range (inclusive).
interval number 50 Chunk fetching the blocks in intervals to avoid overwhelming the client.
setPercentage? Function undefined -

# Returns

Promise<NetworkComponentUpdate<Components>[]>

Promise resolving with array containing the contract ECS events in the given block range.

# Defined in

network/src/workers/syncUtils.ts:291


# fetchLogs

fetchLogs<C>(provider, topics, startBlockNumber, endBlockNumber, contracts, requireMinimumBlockNumber?): Promise<Log[]>

Fetch logs with the given topics from a given block range.

# Type parameters

Name Type
C extends Contracts

# Parameters

Name Type Description
provider JsonRpcProvider ethers JsonRpcProvider
topics ContractTopics[] Topics to fetch logs for
startBlockNumber number Start of block range to fetch logs from (inclusive)
endBlockNumber number End of block range to fetch logs from (inclusive)
contracts ContractsConfig<C> Contracts to fetch logs from
requireMinimumBlockNumber? number Minimal block number required to fetch blocks

# Returns

Promise<Log[]>

Promise resolving with an array of logs from the specified block range and topics

# Defined in

network/src/networkUtils.ts:70


# fetchSnapshot

fetchSnapshot(snapshotClient, worldAddress, decode): Promise<CacheStore>

Load from the remote snapshot service.

Deprecated

this util will be removed in a future version, use fetchSnapshotChunked instead

# Parameters

Name Type Description
snapshotClient ECSStateSnapshotServiceClient<Object> ECSStateSnapshotServiceClient
worldAddress string Address of the World contract to get the snapshot for.
decode Function Function to decode raw component values (createDecode).

# Returns

Promise<CacheStore>

Promise resolving with CacheStore containing the snapshot state.

# Defined in

network/src/workers/syncUtils.ts:88


# fetchSnapshotChunked

fetchSnapshotChunked(snapshotClient, worldAddress, decode, numChunks?, setPercentage?, pruneOptions?): Promise<CacheStore>

Load from the remote snapshot service in chunks via a stream.

# Parameters

Name Type Default value Description
snapshotClient ECSStateSnapshotServiceClient<Object> undefined ECSStateSnapshotServiceClient
worldAddress string undefined Address of the World contract to get the snapshot for.
decode Function undefined Function to decode raw component values (createDecode).
numChunks number 10 -
setPercentage? Function undefined -
pruneOptions? Object undefined -
pruneOptions.hashedComponentId string undefined -
pruneOptions.playerAddress string undefined -

# Returns

Promise<CacheStore>

Promise resolving with CacheStore containing the snapshot state.

# Defined in

network/src/workers/syncUtils.ts:113


# fetchStateInBlockRange

fetchStateInBlockRange(fetchWorldEvents, fromBlockNumber, toBlockNumber, interval?, setPercentage?): Promise<CacheStore>

Fetch ECS state from contracts in the given block range.

# Parameters

Name Type Default value Description
fetchWorldEvents Function undefined Function to fetch World events in a block range (createFetchWorldEventsInBlockRange).
fromBlockNumber number undefined Start of block range (inclusive).
toBlockNumber number undefined End of block range (inclusive).
interval number 50 Chunk fetching the blocks in intervals to avoid overwhelming the client.
setPercentage? Function undefined -

# Returns

Promise<CacheStore>

Promise resolving with CacheStore containing the contract ECS state in the given block range.

# Defined in

network/src/workers/syncUtils.ts:326


# flattenValue

flattenValue<V>(value, valueType): ContractSchemaValueTypes[V]

# Type parameters

Name Type
V extends ContractSchemaValue

# Parameters

Name Type
value string | number | boolean | string[] | number[] | BigNumber | BigNumber[] | boolean[]
valueType V

# Returns

ContractSchemaValueTypes[V]

# Defined in

network/src/createDecoder.ts:10


# formatComponentID

formatComponentID(componentID): string

# Parameters

Name Type
componentID string | BigNumber

# Returns

string

# Defined in

network/src/utils.ts:20


# formatEntityID

formatEntityID(entityID): EntityID

# Parameters

Name Type
entityID string | BigNumber | EntityID

# Returns

EntityID

# Defined in

network/src/utils.ts:12


# getCacheId

getCacheId(namespace, chainId, worldAddress): string

# Parameters

Name Type
namespace string
chainId number
worldAddress string

# Returns

string

# Defined in

network/src/workers/CacheStore.ts:15


# getCacheStoreEntries

getCacheStoreEntries<Cm>(__namedParameters): IterableIterator<NetworkComponentUpdate<Cm>>

# Type parameters

Name Type
Cm extends Components

# Parameters

Name Type
__namedParameters Object
__namedParameters.blockNumber number
__namedParameters.componentToIndex Map<string, number>
__namedParameters.components string[]
__namedParameters.entities string[]
__namedParameters.entityToIndex Map<string, number>
__namedParameters.state State

# Returns

IterableIterator<NetworkComponentUpdate<Cm>>

# Defined in

network/src/workers/CacheStore.ts:73


# getIndexDBCacheStoreBlockNumber

getIndexDBCacheStoreBlockNumber(cache): Promise<number>

# Parameters

Name Type
cache Object
cache.db IDBDatabase
cache.entries Function
cache.get Function
cache.keys Function
cache.remove Function
cache.set Function
cache.values Function

# Returns

Promise<number>

# Defined in

network/src/workers/CacheStore.ts:149


# getIndexDbECSCache

getIndexDbECSCache(chainId, worldAddress, version?, idb?): Promise<Object>

# Parameters

Name Type
chainId number
worldAddress string
version? number
idb? IDBFactory

# Returns

Promise<Object>

# Defined in

network/src/workers/CacheStore.ts:153


# getRevertReason

getRevertReason(txHash, provider): Promise<string>

Get the revert reason from a given transaction hash

# Parameters

Name Type Description
txHash string Transaction hash to get the revert reason from
provider BaseProvider ethers Provider

# Returns

Promise<string>

Promise resolving with revert reason string

# Defined in

network/src/networkUtils.ts:227


# getSnapshotBlockNumber

getSnapshotBlockNumber(snapshotClient, worldAddress): Promise<number>

Return the snapshot block number.

# Parameters

Name Type Description
snapshotClient undefined | ECSStateSnapshotServiceClient<Object> ECSStateSnapshotServiceClient
worldAddress string Address of the World contract to get the snapshot for.

# Returns

Promise<number>

Snapsot block number

# Defined in

network/src/workers/syncUtils.ts:64


# isNetworkComponentUpdateEvent

isNetworkComponentUpdateEvent<C>(e): e is NetworkComponentUpdate<C>

# Type parameters

Name Type
C extends Components

# Parameters

Name Type
e NetworkEvent<C>

# Returns

e is NetworkComponentUpdate<C>

# Defined in

network/src/types.ts:118


# isSystemCallEvent

isSystemCallEvent<C>(e): e is SystemCall<C>

# Type parameters

Name Type
C extends Components

# Parameters

Name Type
e NetworkEvent<C>

# Returns

e is SystemCall<C>

# Defined in

network/src/types.ts:114


# loadIndexDbCacheStore

loadIndexDbCacheStore(cache): Promise<CacheStore>

# Parameters

Name Type
cache Object
cache.db IDBDatabase
cache.entries Function
cache.get Function
cache.keys Function
cache.remove Function
cache.set Function
cache.values Function

# Returns

Promise<CacheStore>

# Defined in

network/src/workers/CacheStore.ts:128


# mergeCacheStores

mergeCacheStores(stores): CacheStore

# Parameters

Name Type
stores Object[]

# Returns

CacheStore

# Defined in

network/src/workers/CacheStore.ts:102


# messagePayload

messagePayload(msg): string

# Parameters

Name Type
msg Message

# Returns

string

# Defined in

network/src/utils.ts:7


# parseSystemCallsFromStreamEvents

parseSystemCallsFromStreamEvents(events): SystemCall<Components>[]

# Parameters

Name Type
events NetworkComponentUpdate<Components>[]

# Returns

SystemCall<Components>[]

# Defined in

network/src/workers/syncUtils.ts:520


# reduceFetchedState

reduceFetchedState(response, cacheStore, decode): Promise<void>

Reduces a snapshot response by storing corresponding ECS events into the cache store.

Deprecated

this util will be removed in a future version, use reduceFetchedStateV2 instead

# Parameters

Name Type Description
response ECSStateReply ECSStateReply
cacheStore Object CacheStore to store snapshot state into.
cacheStore.blockNumber number -
cacheStore.componentToIndex Map<string, number> -
cacheStore.components string[] -
cacheStore.entities string[] -
cacheStore.entityToIndex Map<string, number> -
cacheStore.state State -
decode Function Function to decode raw component values (createDecode).

# Returns

Promise<void>

Promise resolving once state is reduced into CacheStore.

# Defined in

network/src/workers/syncUtils.ts:158


# reduceFetchedStateV2

reduceFetchedStateV2(response, cacheStore, decode): Promise<void>

Reduces a snapshot response by storing corresponding ECS events into the cache store.

# Parameters

Name Type Description
response ECSStateReplyV2 ECSStateReplyV2
cacheStore Object CacheStore to store snapshot state into.
cacheStore.blockNumber number -
cacheStore.componentToIndex Map<string, number> -
cacheStore.components string[] -
cacheStore.entities string[] -
cacheStore.entityToIndex Map<string, number> -
cacheStore.state State -
decode Function Function to decode raw component values (createDecode).

# Returns

Promise<void>

Promise resolving once state is reduced into CacheStore.

# Defined in

network/src/workers/syncUtils.ts:181


# saveCacheStoreToIndexDb

saveCacheStoreToIndexDb(cache, store): Promise<void>

# Parameters

Name Type
cache Object
cache.db IDBDatabase
cache.entries Function
cache.get Function
cache.keys Function
cache.remove Function
cache.set Function
cache.values Function
store Object
store.blockNumber number
store.componentToIndex Map<string, number>
store.components string[]
store.entities string[]
store.entityToIndex Map<string, number>
store.state State

# Returns

Promise<void>

# Defined in

network/src/workers/CacheStore.ts:120


# storeEvent

storeEvent<Cm>(cacheStore, __namedParameters): void

# Type parameters

Name Type
Cm extends Components

# Parameters

Name Type
cacheStore Object
cacheStore.blockNumber number
cacheStore.componentToIndex Map<string, number>
cacheStore.components string[]
cacheStore.entities string[]
cacheStore.entityToIndex Map<string, number>
cacheStore.state State
__namedParameters Omit<NetworkComponentUpdate<Cm>, "txHash" | "lastEventInTx">

# Returns

void

# Defined in

network/src/workers/CacheStore.ts:30


# storeEvents

storeEvents<Cm>(cacheStore, events): void

# Type parameters

Name Type
Cm extends Components

# Parameters

Name Type
cacheStore Object
cacheStore.blockNumber number
cacheStore.componentToIndex Map<string, number>
cacheStore.components string[]
cacheStore.entities string[]
cacheStore.entityToIndex Map<string, number>
cacheStore.state State
events Omit<NetworkComponentUpdate<Cm>, "txHash" | "lastEventInTx">[]

# Returns

void

# Defined in

network/src/workers/CacheStore.ts:64