Packages
network
Readme

@latticexyz/network

@latticexyz/network

Table of contents

Enumerations

Classes

Interfaces

Type Aliases

Variables

Functions

Type Aliases

Ack

Ƭ Ack: Object

Type declaration

NameType
typeAck

Defined in

workers/SyncWorker.ts:65 (opens in a new tab)


CacheStore

Ƭ CacheStore: ReturnType<typeof createCacheStore>

Defined in

workers/CacheStore.ts:12 (opens in a new tab)


Clock

Ƭ Clock: Object

Type declaration

NameType
currentTimenumber
dispose() => void
lastUpdateTimenumber
time$Observable<number>
update(time: number, maintainStale?: boolean) => void

Defined in

types.ts:31 (opens in a new tab)


Config

Ƭ Config: Object

Type declaration

NameType
dataSyncWorkerConfig
typeConfig

Defined in

workers/SyncWorker.ts:64 (opens in a new tab)


ContractConfig

Ƭ ContractConfig: Object

Type declaration

NameType
abiContractInterface
addressstring

Defined in

types.ts:51 (opens in a new tab)


ContractEvent

Ƭ ContractEvent<C>: Object

Type parameters

NameType
Cextends Contracts

Type declaration

NameType
argsResult
blockNumbernumber
contractKeykeyof C
eventKeystring
lastEventInTxboolean
logIndex?number
txHashstring

Defined in

types.ts:67 (opens in a new tab)


ContractSchemaValueTypes

Ƭ ContractSchemaValueTypes: Object

Type declaration

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

Defined in

types.ts:242 (opens in a new tab)


ContractTopics

Ƭ ContractTopics: Object

Type declaration

NameType
keystring
topicsstring[][]

Defined in

types.ts:62 (opens in a new tab)


Contracts

Ƭ Contracts: Object

Index signature

▪ [key: string]: BaseContract

Defined in

types.ts:47 (opens in a new tab)


ContractsConfig

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

Type parameters

NameType
Cextends Contracts

Defined in

types.ts:56 (opens in a new tab)


ECSCache

Ƭ ECSCache: Awaited<ReturnType<typeof getIndexDbECSCache>>

Defined in

workers/CacheStore.ts:13 (opens in a new tab)


Input

Ƭ Input: Config | Ack

Defined in

workers/SyncWorker.ts:67 (opens in a new tab)


Mappings

Ƭ Mappings<C>: Object

Type parameters

NameType
Cextends Components

Index signature

▪ [hashedContractId: string]: keyof C

Defined in

types.ts:80 (opens in a new tab)


Network

Ƭ Network: Awaited<ReturnType<typeof createNetwork>>

Defined in

createNetwork.ts:12 (opens in a new tab)


NetworkComponentUpdate

Ƭ NetworkComponentUpdate<C>: { [key in keyof C]: Object }[keyof C] & { blockNumber: number ; entity: EntityID ; lastEventInTx: boolean ; logIndex?: number ; txHash: string ; txMetadata?: TxMetadata }

Type parameters

NameType
Cextends Components = Components

Defined in

types.ts:84 (opens in a new tab)


NetworkEvent

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

Type parameters

NameType
Cextends Components = Components

Defined in

types.ts:121 (opens in a new tab)


Providers

Ƭ Providers: ReturnType<typeof createProvider>

Defined in

createProvider.ts:8 (opens in a new tab)


State

Ƭ State: Map<number, ComponentValue>

Defined in

workers/CacheStore.ts:11 (opens in a new tab)


SyncStateStruct

Ƭ SyncStateStruct: Object

Type declaration

NameType
msgstring
percentagenumber
stateSyncState

Defined in

types.ts:279 (opens in a new tab)


SyncWorkerConfig

Ƭ SyncWorkerConfig: Object

Type declaration

NameType
cacheAgeThreshold?number
cacheInterval?number
chainIdnumber
disableCache?boolean
fetchSystemCalls?boolean
initialBlockNumbernumber
modeUrl?string
providerProviderConfig
pruneOptions?{ hashedComponentId: string ; playerAddress: string }
pruneOptions.hashedComponentIdstring
pruneOptions.playerAddressstring
snapshotNumChunks?number
snapshotServiceUrl?string
streamServiceUrl?string
worldContractContractConfig

Defined in

types.ts:133 (opens in a new tab)


SystemCall

Ƭ SystemCall<C>: Object

Type parameters

NameType
Cextends Components = Components

Type declaration

NameType
txSystemCallTransaction
typeSystemCall
updatesNetworkComponentUpdate[]

Defined in

types.ts:110 (opens in a new tab)


SystemCallTransaction

Ƭ SystemCallTransaction: Object

Type declaration

NameType
datastring
hashstring
tostring
valueBigNumber

Defined in

types.ts:103 (opens in a new tab)


TopicsConfig

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

Type parameters

NameType
Cextends Contracts

Defined in

createTopics.ts:5 (opens in a new tab)


TxQueue

Ƭ TxQueue<C>: Cached<C>

Type parameters

NameType
Cextends Contracts

Defined in

types.ts:60 (opens in a new tab)

Variables

ContractSchemaValueArrayToElement

Const ContractSchemaValueArrayToElement: Object

Type declaration

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

Defined in

types.ts:223 (opens in a new tab)


ContractSchemaValueId

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

Defined in

types.ts:186 (opens in a new tab)


GodID

Const GodID: EntityID = SingletonID

Deprecated

Import SingletonID instead

Defined in

workers/constants.ts:12 (opens in a new tab)


SingletonID

Const SingletonID: EntityID

Defined in

workers/constants.ts:9 (opens in a new tab)


ack

Const ack: Object

Type declaration

NameType
typeAck

Defined in

workers/SyncWorker.ts:66 (opens in a new tab)

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

NameTypeDescription
providersIComputedValue<undefined | { json: MUDJsonRpcBatchProvider | MUDJsonRpcProvider ; ws: undefined | WebSocketProvider }>Mobx computed providers object (created by createReconnectingProvider).
options?Object
options.initialSync?Object-
options.initialSync.initialBlockNumbernumber-
options.initialSync.intervalnumber-

Returns

Object

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

NameType
blockNumber$Observable<number>
disposeIReactionDisposer

Defined in

createBlockNumberStream.ts:15 (opens in a new tab)


createCacheStore

createCacheStore(): Object

Returns

Object

NameType
blockNumbernumber
componentToIndexMap<string, number>
componentsstring[]
entitiesstring[]
entityToIndexMap<string, number>
stateState

Defined in

workers/CacheStore.ts:19 (opens in a new tab)


createContracts

createContracts<C>(config:): Promise<{ config: ContractsConfig<C> ; contracts: IComputedValue

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

Type parameters

NameType
Cextends Contracts

Parameters

NameTypeDescription
config:ObjectContractsConfig
config:.asyncConfig?(contracts: C) => Promise<Partial<ContractsConfig-
config:.configPartial<ContractsConfig-
config:.signerOrProviderIComputedValue<Signer | Provider>-

Returns

Promise<{ config: ContractsConfig<C> ; contracts: IComputedValue

Object with contracts connected to the currently connected provider.

Defined in

createContracts.ts:13 (opens in a new tab)


createDecode

createDecode(worldConfig, provider): (componentId: string, data: BytesLike, componentAddress?: string) => Promise<ComponentValue>

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

Parameters

NameTypeDescription
worldConfigContractConfigContract address and interface of the World contract
providerJsonRpcProviderethers JsonRpcProvider

Returns

fn

Function to decode raw component values using their contract component id

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

Parameters
NameType
componentIdstring
dataBytesLike
componentAddress?string
Returns

Promise<ComponentValue>

Defined in

workers/syncUtils.ts:367 (opens in a new tab)


createDecoder

createDecoder<D>(keys, valueTypes): (data: BytesLike) => D

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

NameType
Dextends Object

Parameters

NameTypeDescription
keyskeyof D[]Keys of the component value schema.
valueTypesContractSchemaValue[]Value types if the component value schema.

Returns

fn

Function to decode encoded hex value to component value.

▸ (data): D

Parameters
NameType
dataBytesLike
Returns

D

Defined in

createDecoder.ts:74 (opens in a new tab)


createEncoder

createEncoder<D>(keys, valueTypes): (value: D) => string

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

Type parameters

NameType
Dextends Object

Parameters

NameTypeDescription
keyskeyof D[]Schema keys
valueTypesContractSchemaValue[]Schema value types

Returns

fn

Function to encode component values

▸ (value): string

Parameters
NameType
valueD
Returns

string

Defined in

createEncoder.ts:11 (opens in a new tab)


createFastTxExecutor

createFastTxExecutor(signer, globalOptions?): Promise<{ currentNonce: Readonly<{ nonce: number }> ; fastTxExecute: <C, F>(contract: C, func: F, args: Parameters<C[F]>, options: { retryCount?: number }) => Promise<{ hash: string ; tx: ReturnType<C[F]> }> ; gasConfig: Readonly<{ maxFeePerGas?: BigNumber ; maxPriorityFeePerGas?: number }> ; updateFeePerGas: (multiplier: number) => Promise<void> }>

Create a stateful util to execute transactions as fast as possible. Internal state includes the current nonce and the current gas price.

Note: since the signer's nonce is managed in the internal state of this function, using the same signer to send transactions outside of this function or creating multiple instances of this function with the same signer will result in nonce errors.

Parameters

NameType
signerSigner & { provider: JsonRpcProvider }
globalOptionsObject
globalOptions.priorityFeeMultipliernumber

Returns

Promise<{ currentNonce: Readonly<{ nonce: number }> ; fastTxExecute: <C, F>(contract: C, func: F, args: Parameters<C[F]>, options: { retryCount?: number }) => Promise<{ hash: string ; tx: ReturnType<C[F]> }> ; gasConfig: Readonly<{ maxFeePerGas?: BigNumber ; maxPriorityFeePerGas?: number }> ; updateFeePerGas: (multiplier: number) => Promise<void> }>

Defined in

createFastTxExecutor.ts:13 (opens in a new tab)


createFaucetService

createFaucetService(url): RawClient<FromTsProtoServiceDefinition<typeof FaucetServiceDefinition>>

Create a FaucetServiceClient

Parameters

NameTypeDescription
urlstringFaucetService URL

Returns

RawClient<FromTsProtoServiceDefinition<typeof FaucetServiceDefinition>>

FaucetServiceClient

Defined in

createFaucetService.ts:10 (opens in a new tab)


createFetchSystemCallsFromEvents

createFetchSystemCallsFromEvents(provider): (events: NetworkComponentUpdate<Components>[], blockNumber: number) => Promise<SystemCall

Parameters

NameType
providerJsonRpcProvider

Returns

fn

▸ (events, blockNumber): Promise<SystemCall

Parameters
NameType
eventsNetworkComponentUpdate[]
blockNumbernumber
Returns

Promise<SystemCall

Defined in

workers/syncUtils.ts:551 (opens in a new tab)


createFetchWorldEventsInBlockRange

createFetchWorldEventsInBlockRange<C>(provider, worldConfig, batch, decode): (from: number, to: number) => Promise<NetworkComponentUpdate

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

Type parameters

NameType
Cextends Components

Parameters

NameTypeDescription
providerJsonRpcProviderethers JsonRpcProvider
worldConfigContractConfigContract address and interface of the World contract.
batchundefined | booleanSet to true if the provider supports batch queries (recommended).
decode(componentId: string, data: BytesLike, componentAddress?: string) => Promise<ComponentValue>Function to decode raw component values (createDecode)

Returns

fn

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

▸ (from, to): Promise<NetworkComponentUpdate

Parameters
NameType
fromnumber
tonumber
Returns

Promise<NetworkComponentUpdate

Defined in

workers/syncUtils.ts:406 (opens in a new tab)


createLatestEventStreamRPC

createLatestEventStreamRPC(blockNumber$, fetchWorldEvents, boundFetchStoreEvents, 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

NameTypeDescription
blockNumber$Observable<number>Block number stream
fetchWorldEvents(from: number, to: number) => Promise<NetworkComponentUpdateFunction to fetch World events in a block range (createFetchWorldEventsInBlockRange).
boundFetchStoreEvents(fromBlock: number, toBlock: number) => Promise<NetworkComponentUpdate-
fetchSystemCallsFromEvents?(events: NetworkComponentUpdate<Components>[], blockNumber: number) => Promise<SystemCall-

Returns

Observable<NetworkEvent>

Stream of NetworkComponentUpdates.

Defined in

workers/syncUtils.ts:256 (opens in a new tab)


createLatestEventStreamService

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

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

Parameters

NameTypeDescription
streamServiceUrlstringURL of the gPRC stream service to subscribe to.
worldAddressstringContract address of the World contract to subscribe to.
transformWorldEvents(message: ECSStreamBlockBundleReply) => Promise<NetworkComponentUpdateFunction to transform World events from a stream service (createTransformWorldEventsFromStream).
includeSystemCallsboolean-

Returns

Observable<NetworkEvent>

Stream of NetworkComponentUpdates.

Defined in

workers/syncUtils.ts:210 (opens in a new tab)


createNetwork

createNetwork(initialConfig): Promise<{ blockNumber$: Observable<number> ; clock: Clock ; config: NetworkConfig ; connected: IComputedValue<ConnectionState> ; connectedAddress: IComputedValue<undefined | string> ; connectedAddressChecksummed: IComputedValue<undefined | string> ; dispose: () => void ; providers: IComputedValue<{ json: MUDJsonRpcBatchProvider | MUDJsonRpcProvider ; ws: undefined | WebSocketProvider }> ; signer: IComputedValue

Set up network.

Parameters

NameTypeDescription
initialConfigNetworkConfigInitial config (see NetworkConfig).

Returns

Promise<{ blockNumber$: Observable<number> ; clock: Clock ; config: NetworkConfig ; connected: IComputedValue<ConnectionState> ; connectedAddress: IComputedValue<undefined | string> ; connectedAddressChecksummed: IComputedValue<undefined | string> ; dispose: () => void ; providers: IComputedValue<{ json: MUDJsonRpcBatchProvider | MUDJsonRpcProvider ; ws: undefined | WebSocketProvider }> ; signer: IComputedValue

Network object

Defined in

createNetwork.ts:20 (opens in a new tab)


createProvider

createProvider(config): Object

Create a JsonRpcProvider and WebsocketProvider pair

Parameters

NameTypeDescription
configProviderConfigConfig for the provider pair (see ProviderConfig).

Returns

Object

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

NameType
jsonMUDJsonRpcBatchProvider | MUDJsonRpcProvider
wsundefined | WebSocketProvider

Defined in

createProvider.ts:19 (opens in a new tab)


createReconnectingProvider

createReconnectingProvider(config): Promise<{ connected: IComputedValue<ConnectionState> ; dispose: () => void ; providers: IComputedValue<{ json: MUDJsonRpcBatchProvider | MUDJsonRpcProvider ; ws: undefined | WebSocketProvider }> }>

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

Parameters

NameTypeDescription
configIComputedValue<ProviderConfig>Mobx computed provider config object (see ProviderConfig). Automatically updates the returned provider pair if the config changes.

Returns

Promise<{ connected: IComputedValue<ConnectionState> ; dispose: () => void ; providers: IComputedValue<{ json: MUDJsonRpcBatchProvider | MUDJsonRpcProvider ; ws: undefined | WebSocketProvider }> }>

Automatically reconnecting provider pair that updates if the config changes.

Defined in

createProvider.ts:54 (opens in a new tab)


createRelayStream

createRelayStream(signer, url, id): Promise<{ countConnected: () => Promise<number> ; dispose: () => void ; event$: Observable<{ address: any ; message: Message }> ; ping: () => Promise<Identity> ; push: (label: string, data: Uint8Array) => Promise<void> ; subscribe: (label: string) => void ; unsubscribe: (label: string) => void }>

Create a RelayService connection, including event$ and utils

Parameters

NameTypeDescription
signerSigner-
urlstringECSRelayService URL
idstringUser id (eg address)

Returns

Promise<{ countConnected: () => Promise<number> ; dispose: () => void ; event$: Observable<{ address: any ; message: Message }> ; ping: () => Promise<Identity> ; push: (label: string, data: Uint8Array) => Promise<void> ; subscribe: (label: string) => void ; unsubscribe: (label: string) => void }>

RelayService connection

Defined in

createRelayStream.ts:16 (opens in a new tab)


createSigner

createSigner(privateKey, providers): Wallet

Parameters

NameType
privateKeystring
providersObject
providers.jsonMUDJsonRpcBatchProvider | MUDJsonRpcProvider
providers.wsundefined | WebSocketProvider

Returns

Wallet

Defined in

createSigner.ts:4 (opens in a new tab)


createSnapshotClient

createSnapshotClient(url): ECSStateSnapshotServiceClient

Create a ECSStateSnapshotServiceClient

Parameters

NameTypeDescription
urlstringECSStateSnapshotService URL

Returns

ECSStateSnapshotServiceClient

ECSStateSnapshotServiceClient

Defined in

workers/syncUtils.ts:46 (opens in a new tab)


createStreamClient

createStreamClient(url): ECSStreamServiceClient

Create a ECSStreamServiceClient

Parameters

NameTypeDescription
urlstringECSStreamService URL

Returns

ECSStreamServiceClient

ECSStreamServiceClient

Defined in

workers/syncUtils.ts:55 (opens in a new tab)


createSyncWorker

createSyncWorker<C>(ack$?, options?): 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

NameType
Cextends Components = Components

Parameters

NameType
ack$?Observable<Ack>
options?Object
options.thread?"worker" | "main"

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 }

NameType
dispose() => void
ecsEvents$Subject<NetworkEvent
input$Subject<Input>

Defined in

createSyncWorker.ts:17 (opens in a new tab)


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

NameType
Textends Object

Parameters

NameTypeDescription
worldWorldRecs World object.
networkObjectNetwork (createNetwork).
network.blockNumber$Observable<number>-
network.clockClock-
network.configNetworkConfig-
network.connectedIComputedValue<ConnectionState>-
network.connectedAddressIComputedValue<undefined | string>-
network.connectedAddressChecksummedIComputedValue<undefined | string>-
network.dispose() => void-
network.providersIComputedValue<{ json: MUDJsonRpcBatchProvider | MUDJsonRpcProvider ; ws: undefined | WebSocketProvider }>-
network.signerIComputedValue<undefined | Signer>-
systemsComponent<{ value: String }, 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.

NameType
getSystemContract(systemId: string) => { contract: Contract ; name: string }
registerSystem(system: { contract: Contract ; id: string }) => Promise<void>
systemsTxQueue

Defined in

createSystemExecutor.ts:22 (opens in a new tab)


createTopics

createTopics<C>(config): ContractTopics[]

Type parameters

NameType
Cextends Contracts

Parameters

NameType
configTopicsConfig

Returns

ContractTopics[]

Defined in

createTopics.ts:12 (opens in a new tab)


createTransformWorldEventsFromStream

createTransformWorldEventsFromStream(decode): (message: ECSStreamBlockBundleReply) => Promise<NetworkComponentUpdate

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

Parameters

NameTypeDescription
decode(componentId: string, data: BytesLike, componentAddress?: string) => Promise<ComponentValue>Function to decode raw component values (createDecode)

Returns

fn

Function to transform World contract events from a stream service.

▸ (message): Promise<NetworkComponentUpdate

Parameters
NameType
messageECSStreamBlockBundleReply
Returns

Promise<NetworkComponentUpdate

Defined in

workers/syncUtils.ts:467 (opens in a new tab)


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

NameType
Cextends Contracts

Parameters

NameTypeDescription
computedContractsIComputedValue<C> | IObservableValue<C>A computed object containing the contracts to be channelled through the txQueue
networkObjectA network object containing provider, signer, etc
network.blockNumber$Observable<number>-
network.clockClock-
network.configNetworkConfig-
network.connectedIComputedValue<ConnectionState>-
network.connectedAddressIComputedValue<undefined | string>-
network.connectedAddressChecksummedIComputedValue<undefined | string>-
network.dispose() => void-
network.providersIComputedValue<{ json: MUDJsonRpcBatchProvider | MUDJsonRpcProvider ; ws: undefined | WebSocketProvider }>-
network.signerIComputedValue<undefined | Signer>-
gasPrice$BehaviorSubject<number>-
options?ObjectThe concurrency declares how many transactions can wait for confirmation at the same time.
options.concurrency?number-
options.devMode?boolean-

Returns

Object

TxQueue object

NameType
dispose() => void
readyIComputedValue<boolean | undefined>
txQueueTxQueue

Defined in

createTxQueue.ts:24 (opens in a new tab)


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

workers/syncUtils.ts:392 (opens in a new tab)


ensureNetworkIsUp

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

Await network to be reachable.

Parameters

NameTypeDescription
providerJsonRpcProviderethers JsonRpcProvider
wssProvider?WebSocketProviderethers WebSocketProvider

Returns

Promise<void>

Promise resolving once the network is reachable

Defined in

networkUtils.ts:22 (opens in a new tab)


fetchBlock

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

Fetch the latest Ethereum block

Parameters

NameTypeDescription
providerJsonRpcProviderethers JsonRpcProvider
requireMinimumBlockNumber?numberMinimal 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

networkUtils.ts:38 (opens in a new tab)


fetchEventsInBlockRange

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

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

Type parameters

NameType
Cextends Contracts

Parameters

NameTypeDescription
providerJsonRpcProviderethers JsonRpcProvider
topicsContractTopics[]Topics to fetch events for
startBlockNumbernumberStart of block range to fetch events from (inclusive)
endBlockNumbernumberEnd of block range to fetch events from (inclusive)
contractsContractsConfigContracts to fetch events from
supportsBatchQueries?booleanSet to true if the provider supports batch queries (recommended)

Returns

Promise<ContractEvent

Promise resolving with an array of ContractEvents

Defined in

networkUtils.ts:143 (opens in a new tab)


fetchEventsInBlockRangeChunked

fetchEventsInBlockRangeChunked(fetchWorldEvents, boundFetchStoreEvents, fromBlockNumber, toBlockNumber, interval?, setPercentage?): Promise<NetworkComponentUpdate

Fetch ECS events from contracts in the given block range.

Parameters

NameTypeDefault valueDescription
fetchWorldEvents(from: number, to: number) => Promise<NetworkComponentUpdateundefinedFunction to fetch World events in a block range (createFetchWorldEventsInBlockRange).
boundFetchStoreEvents(fromBlock: number, toBlock: number) => Promise<NetworkComponentUpdateundefined-
fromBlockNumbernumberundefinedStart of block range (inclusive).
toBlockNumbernumberundefinedEnd of block range (inclusive).
intervalnumber50Chunk fetching the blocks in intervals to avoid overwhelming the client.
setPercentage?(percentage: number) => voidundefined-

Returns

Promise<NetworkComponentUpdate

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

Defined in

workers/syncUtils.ts:298 (opens in a new tab)


fetchLogs

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

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

Type parameters

NameType
Cextends Contracts

Parameters

NameTypeDescription
providerJsonRpcProviderethers JsonRpcProvider
topicsContractTopics[]Topics to fetch logs for
startBlockNumbernumberStart of block range to fetch logs from (inclusive)
endBlockNumbernumberEnd of block range to fetch logs from (inclusive)
contractsContractsConfigContracts to fetch logs from
requireMinimumBlockNumber?numberMinimal 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

networkUtils.ts:70 (opens in a new tab)


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

NameTypeDescription
snapshotClientECSStateSnapshotServiceClient<{}>ECSStateSnapshotServiceClient
worldAddressstringAddress of the World contract to get the snapshot for.
decode(componentId: string, data: BytesLike, componentAddress?: string) => Promise<ComponentValue>Function to decode raw component values (createDecode).

Returns

Promise<CacheStore>

Promise resolving with CacheStore containing the snapshot state.

Defined in

workers/syncUtils.ts:90 (opens in a new tab)


fetchSnapshotChunked

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

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

Parameters

NameTypeDefault valueDescription
snapshotClientECSStateSnapshotServiceClient<{}>undefinedECSStateSnapshotServiceClient
worldAddressstringundefinedAddress of the World contract to get the snapshot for.
decode(componentId: string, data: BytesLike, componentAddress?: string) => Promise<ComponentValue>undefinedFunction to decode raw component values (createDecode).
numChunksnumber10-
setPercentage?(percentage: number) => voidundefined-
pruneOptions?Objectundefined-
pruneOptions.hashedComponentIdstringundefined-
pruneOptions.playerAddressstringundefined-

Returns

Promise<CacheStore>

Promise resolving with CacheStore containing the snapshot state.

Defined in

workers/syncUtils.ts:115 (opens in a new tab)


fetchStateInBlockRange

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

Fetch ECS state from contracts in the given block range.

Parameters

NameTypeDefault valueDescription
fetchWorldEvents(from: number, to: number) => Promise<NetworkComponentUpdateundefinedFunction to fetch World events in a block range (createFetchWorldEventsInBlockRange).
boundFetchStoreEvents(fromBlock: number, toBlock: number) => Promise<NetworkComponentUpdateundefined-
fromBlockNumbernumberundefinedStart of block range (inclusive).
toBlockNumbernumberundefinedEnd of block range (inclusive).
intervalnumber50Chunk fetching the blocks in intervals to avoid overwhelming the client.
setPercentage?(percentage: number) => voidundefined-

Returns

Promise<CacheStore>

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

Defined in

workers/syncUtils.ts:334 (opens in a new tab)


flattenValue

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

Type parameters

NameType
Vextends ContractSchemaValue

Parameters

NameType
valuestring | number | boolean | string[] | number[] | BigNumber | BigNumber[] | boolean[]
valueTypeV

Returns

ContractSchemaValueTypes[V]

Defined in

createDecoder.ts:10 (opens in a new tab)


getCacheId

getCacheId(namespace, chainId, worldAddress): string

Parameters

NameType
namespacestring
chainIdnumber
worldAddressstring

Returns

string

Defined in

workers/CacheStore.ts:15 (opens in a new tab)


getCacheStoreEntries

getCacheStoreEntries<Cm>(«destructured»): IterableIterator<NetworkComponentUpdate

Type parameters

NameType
Cmextends Components

Parameters

NameType
«destructured»Object
› blockNumbernumber
› componentToIndexMap<string, number>
› componentsstring[]
› entitiesstring[]
› entityToIndexMap<string, number>
› stateState

Returns

IterableIterator<NetworkComponentUpdate

Defined in

workers/CacheStore.ts:88 (opens in a new tab)


getIndexDBCacheStoreBlockNumber

getIndexDBCacheStoreBlockNumber(cache): Promise<number>

Parameters

NameType
cacheObject
cache.dbIDBDatabase
cache.entries<Store>(store: Store) => Promise<IterableIterator<[string, S[Store]]>>
cache.get<Store>(store: Store, key: string) => Promise<S[Store] | undefined>
cache.keys(store: StoreKey<{ BlockNumber: number ; ComponentValues: State ; Mappings: string[] ; Snapshot: ECSStateReply }>) => Promise<IterableIterator
cache.remove(store: StoreKey<{ BlockNumber: number ; ComponentValues: State ; Mappings: string[] ; Snapshot: ECSStateReply }>, key: string) => Promise
cache.set<Store>(store: Store, key: string, value: { BlockNumber: number ; ComponentValues: State ; Mappings: string[] ; Snapshot: ECSStateReply }[Store], ignoreResult: boolean) => undefined | Promise
cache.values<Store>(store: Store) => Promise<IterableIterator<S[Store]>>

Returns

Promise<number>

Defined in

workers/CacheStore.ts:164 (opens in a new tab)


getIndexDbECSCache

getIndexDbECSCache(chainId, worldAddress, version?, idb?): Promise<{ db: IDBDatabase ; entries: <Store>(store: Store) => Promise<IterableIterator<[string, S[Store]]>> ; get: <Store>(store: Store, key: string) => Promise<S[Store] | undefined> ; keys: (store: StoreKey<{ BlockNumber: number ; ComponentValues: State ; Mappings: string[] ; Snapshot: ECSStateReply }>) => Promise<IterableIterator<string>> ; remove: (store: StoreKey<{ BlockNumber: number ; ComponentValues: State ; Mappings: string[] ; Snapshot: ECSStateReply }>, key: string) => Promise<void> ; set: <Store>(store: Store, key: string, value: { BlockNumber: number ; ComponentValues: State ; Mappings: string[] ; Snapshot: ECSStateReply }[Store], ignoreResult: boolean) => undefined | Promise<void> ; values: <Store>(store: Store) => Promise<IterableIterator

Parameters

NameType
chainIdnumber
worldAddressstring
version?number
idb?IDBFactory

Returns

Promise<{ db: IDBDatabase ; entries: <Store>(store: Store) => Promise<IterableIterator<[string, S[Store]]>> ; get: <Store>(store: Store, key: string) => Promise<S[Store] | undefined> ; keys: (store: StoreKey<{ BlockNumber: number ; ComponentValues: State ; Mappings: string[] ; Snapshot: ECSStateReply }>) => Promise<IterableIterator<string>> ; remove: (store: StoreKey<{ BlockNumber: number ; ComponentValues: State ; Mappings: string[] ; Snapshot: ECSStateReply }>, key: string) => Promise<void> ; set: <Store>(store: Store, key: string, value: { BlockNumber: number ; ComponentValues: State ; Mappings: string[] ; Snapshot: ECSStateReply }[Store], ignoreResult: boolean) => undefined | Promise<void> ; values: <Store>(store: Store) => Promise<IterableIterator

Defined in

workers/CacheStore.ts:168 (opens in a new tab)


getRevertReason

getRevertReason(txHash, provider): Promise<string>

Get the revert reason from a given transaction hash

Parameters

NameTypeDescription
txHashstringTransaction hash to get the revert reason from
providerBaseProviderethers Provider

Returns

Promise<string>

Promise resolving with revert reason string

Defined in

networkUtils.ts:230 (opens in a new tab)


getSnapshotBlockNumber

getSnapshotBlockNumber(snapshotClient, worldAddress): Promise<number>

Return the snapshot block number.

Parameters

NameTypeDescription
snapshotClientundefined | ECSStateSnapshotServiceClient<{}>ECSStateSnapshotServiceClient
worldAddressstringAddress of the World contract to get the snapshot for.

Returns

Promise<number>

Snapsot block number

Defined in

workers/syncUtils.ts:66 (opens in a new tab)


isNetworkComponentUpdateEvent

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

Type parameters

NameType
Cextends Components

Parameters

NameType
eNetworkEvent

Returns

e is NetworkComponentUpdate<C>

Defined in

types.ts:127 (opens in a new tab)


isSystemCallEvent

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

Type parameters

NameType
Cextends Components

Parameters

NameType
eNetworkEvent

Returns

e is SystemCall<C>

Defined in

types.ts:123 (opens in a new tab)


loadIndexDbCacheStore

loadIndexDbCacheStore(cache): Promise<CacheStore>

Parameters

NameType
cacheObject
cache.dbIDBDatabase
cache.entries<Store>(store: Store) => Promise<IterableIterator<[string, S[Store]]>>
cache.get<Store>(store: Store, key: string) => Promise<S[Store] | undefined>
cache.keys(store: StoreKey<{ BlockNumber: number ; ComponentValues: State ; Mappings: string[] ; Snapshot: ECSStateReply }>) => Promise<IterableIterator
cache.remove(store: StoreKey<{ BlockNumber: number ; ComponentValues: State ; Mappings: string[] ; Snapshot: ECSStateReply }>, key: string) => Promise
cache.set<Store>(store: Store, key: string, value: { BlockNumber: number ; ComponentValues: State ; Mappings: string[] ; Snapshot: ECSStateReply }[Store], ignoreResult: boolean) => undefined | Promise
cache.values<Store>(store: Store) => Promise<IterableIterator<S[Store]>>

Returns

Promise<CacheStore>

Defined in

workers/CacheStore.ts:143 (opens in a new tab)


mergeCacheStores

mergeCacheStores(stores): CacheStore

Parameters

NameType
stores{ blockNumber: number ; componentToIndex: Map<string, number> ; components: string[] ; entities: string[] ; entityToIndex: Map<string, number> ; state: State }[]

Returns

CacheStore

Defined in

workers/CacheStore.ts:117 (opens in a new tab)


messagePayload

messagePayload(msg): string

Parameters

NameType
msgMessage

Returns

string

Defined in

utils.ts:8 (opens in a new tab)


normalizeComponentID

normalizeComponentID(componentID): string

Parameters

NameType
componentIDstring | BigNumber

Returns

string

Defined in

utils.ts:30 (opens in a new tab)


normalizeEntityID

normalizeEntityID(entityID): EntityID

Parameters

NameType
entityIDstring | BigNumber | EntityID

Returns

EntityID

Defined in

utils.ts:15 (opens in a new tab)


parseSystemCallsFromStreamEvents

parseSystemCallsFromStreamEvents(events): SystemCall[]

Parameters

NameType
eventsNetworkComponentUpdate[]

Returns

SystemCall[]

Defined in

workers/syncUtils.ts:531 (opens in a new tab)


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

NameTypeDescription
responseECSStateReplyECSStateReply
cacheStoreObjectCacheStore to store snapshot state into.
cacheStore.blockNumbernumber-
cacheStore.componentToIndexMap<string, number>-
cacheStore.componentsstring[]-
cacheStore.entitiesstring[]-
cacheStore.entityToIndexMap<string, number>-
cacheStore.stateState-
decode(componentId: string, data: BytesLike, componentAddress?: string) => Promise<ComponentValue>Function to decode raw component values (createDecode).

Returns

Promise<void>

Promise resolving once state is reduced into CacheStore.

Defined in

workers/syncUtils.ts:160 (opens in a new tab)


reduceFetchedStateV2

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

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

Parameters

NameTypeDescription
responseECSStateReplyV2ECSStateReplyV2
cacheStoreObjectCacheStore to store snapshot state into.
cacheStore.blockNumbernumber-
cacheStore.componentToIndexMap<string, number>-
cacheStore.componentsstring[]-
cacheStore.entitiesstring[]-
cacheStore.entityToIndexMap<string, number>-
cacheStore.stateState-
decode(componentId: string, data: BytesLike, componentAddress?: string) => Promise<ComponentValue>Function to decode raw component values (createDecode).

Returns

Promise<void>

Promise resolving once state is reduced into CacheStore.

Defined in

workers/syncUtils.ts:183 (opens in a new tab)


saveCacheStoreToIndexDb

saveCacheStoreToIndexDb(cache, store): Promise<void>

Parameters

NameType
cacheObject
cache.dbIDBDatabase
cache.entries<Store>(store: Store) => Promise<IterableIterator<[string, S[Store]]>>
cache.get<Store>(store: Store, key: string) => Promise<S[Store] | undefined>
cache.keys(store: StoreKey<{ BlockNumber: number ; ComponentValues: State ; Mappings: string[] ; Snapshot: ECSStateReply }>) => Promise<IterableIterator
cache.remove(store: StoreKey<{ BlockNumber: number ; ComponentValues: State ; Mappings: string[] ; Snapshot: ECSStateReply }>, key: string) => Promise
cache.set<Store>(store: Store, key: string, value: { BlockNumber: number ; ComponentValues: State ; Mappings: string[] ; Snapshot: ECSStateReply }[Store], ignoreResult: boolean) => undefined | Promise
cache.values<Store>(store: Store) => Promise<IterableIterator<S[Store]>>
storeObject
store.blockNumbernumber
store.componentToIndexMap<string, number>
store.componentsstring[]
store.entitiesstring[]
store.entityToIndexMap<string, number>
store.stateState

Returns

Promise<void>

Defined in

workers/CacheStore.ts:135 (opens in a new tab)


storeEvent

storeEvent<Cm>(cacheStore, «destructured»): void

Type parameters

NameType
Cmextends Components

Parameters

NameType
cacheStoreObject
cacheStore.blockNumbernumber
cacheStore.componentToIndexMap<string, number>
cacheStore.componentsstring[]
cacheStore.entitiesstring[]
cacheStore.entityToIndexMap<string, number>
cacheStore.stateState
«destructured»Omit<NetworkComponentUpdate

Returns

void

Defined in

workers/CacheStore.ts:30 (opens in a new tab)


storeEvents

storeEvents<Cm>(cacheStore, events): void

Type parameters

NameType
Cmextends Components

Parameters

NameType
cacheStoreObject
cacheStore.blockNumbernumber
cacheStore.componentToIndexMap<string, number>
cacheStore.componentsstring[]
cacheStore.entitiesstring[]
cacheStore.entityToIndexMap<string, number>
cacheStore.stateState
eventsOmit<NetworkComponentUpdate[]

Returns

void

Defined in

workers/CacheStore.ts:79 (opens in a new tab)