@latticexyz/network
@latticexyz/network
Table of contents
Enumerations
Classes
Interfaces
Type Aliases
- Ack
- CacheStore
- Clock
- Config
- ContractConfig
- ContractEvent
- ContractSchemaValueTypes
- ContractTopics
- Contracts
- ContractsConfig
- ECSCache
- Input
- Mappings
- Network
- NetworkComponentUpdate
- NetworkEvent
- Providers
- State
- SyncStateStruct
- SyncWorkerConfig
- SystemCall
- SystemCallTransaction
- TopicsConfig
- TxQueue
Variables
Functions
- createBlockNumberStream
- createCacheStore
- createContracts
- createDecode
- createDecoder
- createEncoder
- createFastTxExecutor
- createFaucetService
- createFetchSystemCallsFromEvents
- createFetchWorldEventsInBlockRange
- createLatestEventStreamRPC
- createLatestEventStreamService
- createNetwork
- createProvider
- createReconnectingProvider
- createRelayStream
- createSigner
- createSnapshotClient
- createStreamClient
- createSyncWorker
- createSystemExecutor
- createTopics
- createTransformWorldEventsFromStream
- createTxQueue
- createWorldTopics
- ensureNetworkIsUp
- fetchBlock
- fetchEventsInBlockRange
- fetchEventsInBlockRangeChunked
- fetchLogs
- fetchSnapshot
- fetchSnapshotChunked
- fetchStateInBlockRange
- flattenValue
- getCacheId
- getCacheStoreEntries
- getIndexDBCacheStoreBlockNumber
- getIndexDbECSCache
- getRevertReason
- getSnapshotBlockNumber
- isNetworkComponentUpdateEvent
- isSystemCallEvent
- loadIndexDbCacheStore
- mergeCacheStores
- messagePayload
- normalizeComponentID
- normalizeEntityID
- parseSystemCallsFromStreamEvents
- reduceFetchedState
- reduceFetchedStateV2
- saveCacheStoreToIndexDb
- storeEvent
- storeEvents
Type Aliases
Ack
Ƭ Ack: Object
Type declaration
Name | Type |
---|---|
type | Ack |
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
Name | Type |
---|---|
currentTime | number |
dispose | () => void |
lastUpdateTime | number |
time$ | Observable <number > |
update | (time : number , maintainStale? : boolean ) => void |
Defined in
types.ts:31 (opens in a new tab)
Config
Ƭ Config: Object
Type declaration
Name | Type |
---|---|
data | SyncWorkerConfig |
type | Config |
Defined in
workers/SyncWorker.ts:64 (opens in a new tab)
ContractConfig
Ƭ ContractConfig: Object
Type declaration
Name | Type |
---|---|
abi | ContractInterface |
address | string |
Defined in
types.ts:51 (opens in a new tab)
ContractEvent
Ƭ ContractEvent<C
>: Object
Type parameters
Name | Type |
---|---|
C | extends Contracts |
Type declaration
Name | Type |
---|---|
args | Result |
blockNumber | number |
contractKey | keyof C |
eventKey | string |
lastEventInTx | boolean |
logIndex? | number |
txHash | string |
Defined in
types.ts:67 (opens in a new tab)
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
types.ts:242 (opens in a new tab)
ContractTopics
Ƭ ContractTopics: Object
Type declaration
Name | Type |
---|---|
key | string |
topics | string [][] |
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
Name | Type |
---|---|
C | extends 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
Defined in
workers/SyncWorker.ts:67 (opens in a new tab)
Mappings
Ƭ Mappings<C
>: Object
Type parameters
Name | Type |
---|---|
C | extends 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
Name | Type |
---|---|
C | extends Components = Components |
Defined in
types.ts:84 (opens in a new tab)
NetworkEvent
Ƭ NetworkEvent<C
>: NetworkComponentUpdate
<C
> | SystemCall
Type parameters
Name | Type |
---|---|
C | extends 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
Name | Type |
---|---|
msg | string |
percentage | number |
state | SyncState |
Defined in
types.ts:279 (opens in a new tab)
SyncWorkerConfig
Ƭ SyncWorkerConfig: Object
Type declaration
Name | Type |
---|---|
cacheAgeThreshold? | number |
cacheInterval? | number |
chainId | number |
disableCache? | boolean |
fetchSystemCalls? | boolean |
initialBlockNumber | number |
modeUrl? | string |
provider | ProviderConfig |
pruneOptions? | { hashedComponentId : string ; playerAddress : string } |
pruneOptions.hashedComponentId | string |
pruneOptions.playerAddress | string |
snapshotNumChunks? | number |
snapshotServiceUrl? | string |
streamServiceUrl? | string |
worldContract | ContractConfig |
Defined in
types.ts:133 (opens in a new tab)
SystemCall
Ƭ SystemCall<C
>: Object
Type parameters
Name | Type |
---|---|
C | extends Components = Components |
Type declaration
Name | Type |
---|---|
tx | SystemCallTransaction |
type | SystemCall |
updates | NetworkComponentUpdate [] |
Defined in
types.ts:110 (opens in a new tab)
SystemCallTransaction
Ƭ SystemCallTransaction: Object
Type declaration
Name | Type |
---|---|
data | string |
hash | string |
to | string |
value | BigNumber |
Defined in
types.ts:103 (opens in a new tab)
TopicsConfig
Ƭ TopicsConfig<C
>: { [ContractType in keyof C]: Object }
Type parameters
Name | Type |
---|---|
C | extends Contracts |
Defined in
createTopics.ts:5 (opens in a new tab)
TxQueue
Ƭ TxQueue<C
>: Cached
<C
>
Type parameters
Name | Type |
---|---|
C | extends Contracts |
Defined in
types.ts:60 (opens in a new tab)
Variables
ContractSchemaValueArrayToElement
• Const
ContractSchemaValueArrayToElement: Object
Type declaration
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
Name | Type |
---|---|
type | Ack |
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
Name | Type | Description |
---|---|---|
providers | IComputedValue <undefined | { json : MUDJsonRpcBatchProvider | MUDJsonRpcProvider ; ws : undefined | WebSocketProvider }> | 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
createBlockNumberStream.ts:15 (opens in a new tab)
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
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
Name | Type |
---|---|
C | extends Contracts |
Parameters
Name | Type | Description |
---|---|---|
config: | Object | ContractsConfig |
config:.asyncConfig? | (contracts : C ) => Promise <Partial <ContractsConfig | - |
config:.config | Partial <ContractsConfig | - |
config:.signerOrProvider | IComputedValue <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
Name | Type | Description |
---|---|---|
worldConfig | ContractConfig | Contract address and interface of the World contract |
provider | JsonRpcProvider | ethers JsonRpcProvider |
Returns
fn
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
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
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
fn
Function to decode encoded hex value to component value.
▸ (data
): D
Parameters
Name | Type |
---|---|
data | BytesLike |
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
Name | Type |
---|---|
D | extends Object |
Parameters
Name | Type | Description |
---|---|---|
keys | keyof D [] | Schema keys |
valueTypes | ContractSchemaValue [] | Schema value types |
Returns
fn
Function to encode component values
▸ (value
): string
Parameters
Name | Type |
---|---|
value | D |
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
Name | Type |
---|---|
signer | Signer & { provider : JsonRpcProvider } |
globalOptions | Object |
globalOptions.priorityFeeMultiplier | number |
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
Name | Type | Description |
---|---|---|
url | string | FaucetService 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
Name | Type |
---|---|
provider | JsonRpcProvider |
Returns
fn
▸ (events
, blockNumber
): Promise
<SystemCall
Parameters
Name | Type |
---|---|
events | NetworkComponentUpdate [] |
blockNumber | number |
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
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 | (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
Name | Type |
---|---|
from | number |
to | number |
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
Name | Type | Description |
---|---|---|
blockNumber$ | Observable <number > | Block number stream |
fetchWorldEvents | (from : number , to : number ) => Promise <NetworkComponentUpdate | Function 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
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 | (message : ECSStreamBlockBundleReply ) => Promise <NetworkComponentUpdate | Function to transform World events from a stream service (createTransformWorldEventsFromStream). |
includeSystemCalls | boolean | - |
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
Name | Type | Description |
---|---|---|
initialConfig | NetworkConfig | Initial 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
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
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
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
<{ 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
Name | Type | Description |
---|---|---|
signer | Signer | - |
url | string | ECSRelayService URL |
id | string | User 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
Name | Type |
---|---|
privateKey | string |
providers | Object |
providers.json | MUDJsonRpcBatchProvider | MUDJsonRpcProvider |
providers.ws | undefined | WebSocketProvider |
Returns
Wallet
Defined in
createSigner.ts:4 (opens in a new tab)
createSnapshotClient
▸ createSnapshotClient(url
): ECSStateSnapshotServiceClient
Create a ECSStateSnapshotServiceClient
Parameters
Name | Type | Description |
---|---|---|
url | string | ECSStateSnapshotService URL |
Returns
ECSStateSnapshotServiceClient
ECSStateSnapshotServiceClient
Defined in
workers/syncUtils.ts:46 (opens in a new tab)
createStreamClient
▸ createStreamClient(url
): ECSStreamServiceClient
Create a ECSStreamServiceClient
Parameters
Name | Type | Description |
---|---|---|
url | string | ECSStreamService 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
Name | Type |
---|---|
C | extends Components = Components |
Parameters
Name | Type |
---|---|
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 }
Name | Type |
---|---|
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
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 | () => void | - |
network.providers | IComputedValue <{ json : MUDJsonRpcBatchProvider | MUDJsonRpcProvider ; ws : undefined | WebSocketProvider }> | - |
network.signer | IComputedValue <undefined | Signer > | - |
systems | Component <{ 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.
Name | Type |
---|---|
getSystemContract | (systemId : string ) => { contract : Contract ; name : string } |
registerSystem | (system : { contract : Contract ; id : string }) => Promise <void > |
systems | TxQueue |
Defined in
createSystemExecutor.ts:22 (opens in a new tab)
createTopics
▸ createTopics<C
>(config
): ContractTopics
[]
Type parameters
Name | Type |
---|---|
C | extends Contracts |
Parameters
Name | Type |
---|---|
config | TopicsConfig |
Returns
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
Name | Type | Description |
---|---|---|
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
Name | Type |
---|---|
message | ECSStreamBlockBundleReply |
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
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 | () => void | - |
network.providers | IComputedValue <{ json : MUDJsonRpcBatchProvider | MUDJsonRpcProvider ; ws : undefined | WebSocketProvider }> | - |
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 | () => void |
ready | IComputedValue <boolean | undefined > |
txQueue | TxQueue |
Defined in
createTxQueue.ts:24 (opens in a new tab)
createWorldTopics
▸ createWorldTopics(): ContractTopics
[]
Create World contract topics for the ComponentValueSet
and ComponentValueRemoved
events.
Returns
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
Name | Type | Description |
---|---|---|
provider | JsonRpcProvider | ethers JsonRpcProvider |
wssProvider? | WebSocketProvider | ethers 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
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
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
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 | Contracts to fetch events from |
supportsBatchQueries? | boolean | Set 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
Name | Type | Default value | Description |
---|---|---|---|
fetchWorldEvents | (from : number , to : number ) => Promise <NetworkComponentUpdate | undefined | Function to fetch World events in a block range (createFetchWorldEventsInBlockRange). |
boundFetchStoreEvents | (fromBlock : number , toBlock : number ) => Promise <NetworkComponentUpdate | undefined | - |
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? | (percentage : number ) => void | undefined | - |
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
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 | 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
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
Name | Type | Description |
---|---|---|
snapshotClient | ECSStateSnapshotServiceClient <{}> | ECSStateSnapshotServiceClient |
worldAddress | string | Address 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
Name | Type | Default value | Description |
---|---|---|---|
snapshotClient | ECSStateSnapshotServiceClient <{}> | undefined | ECSStateSnapshotServiceClient |
worldAddress | string | undefined | Address of the World contract to get the snapshot for. |
decode | (componentId : string , data : BytesLike , componentAddress? : string ) => Promise <ComponentValue > | undefined | Function to decode raw component values (createDecode). |
numChunks | number | 10 | - |
setPercentage? | (percentage : number ) => void | 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
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
Name | Type | Default value | Description |
---|---|---|---|
fetchWorldEvents | (from : number , to : number ) => Promise <NetworkComponentUpdate | undefined | Function to fetch World events in a block range (createFetchWorldEventsInBlockRange). |
boundFetchStoreEvents | (fromBlock : number , toBlock : number ) => Promise <NetworkComponentUpdate | undefined | - |
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? | (percentage : number ) => void | undefined | - |
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
Name | Type |
---|---|
V | extends ContractSchemaValue |
Parameters
Name | Type |
---|---|
value | string | number | boolean | string [] | number [] | BigNumber | BigNumber [] | boolean [] |
valueType | V |
Returns
Defined in
createDecoder.ts:10 (opens in a new tab)
getCacheId
▸ getCacheId(namespace
, chainId
, worldAddress
): string
Parameters
Name | Type |
---|---|
namespace | string |
chainId | number |
worldAddress | string |
Returns
string
Defined in
workers/CacheStore.ts:15 (opens in a new tab)
getCacheStoreEntries
▸ getCacheStoreEntries<Cm
>(«destructured»
): IterableIterator
<NetworkComponentUpdate
Type parameters
Name | Type |
---|---|
Cm | extends Components |
Parameters
Name | Type |
---|---|
«destructured» | Object |
› blockNumber | number |
› componentToIndex | Map <string , number > |
› components | string [] |
› entities | string [] |
› entityToIndex | Map <string , number > |
› state | State |
Returns
IterableIterator
<NetworkComponentUpdate
Defined in
workers/CacheStore.ts:88 (opens in a new tab)
getIndexDBCacheStoreBlockNumber
▸ getIndexDBCacheStoreBlockNumber(cache
): Promise
<number
>
Parameters
Name | Type |
---|---|
cache | Object |
cache.db | IDBDatabase |
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
Name | Type |
---|---|
chainId | number |
worldAddress | string |
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
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
networkUtils.ts:230 (opens in a new tab)
getSnapshotBlockNumber
▸ getSnapshotBlockNumber(snapshotClient
, worldAddress
): Promise
<number
>
Return the snapshot block number.
Parameters
Name | Type | Description |
---|---|---|
snapshotClient | undefined | ECSStateSnapshotServiceClient <{}> | ECSStateSnapshotServiceClient |
worldAddress | string | Address 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
Name | Type |
---|---|
C | extends Components |
Parameters
Name | Type |
---|---|
e | NetworkEvent |
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
Name | Type |
---|---|
C | extends Components |
Parameters
Name | Type |
---|---|
e | NetworkEvent |
Returns
e is SystemCall<C>
Defined in
types.ts:123 (opens in a new tab)
loadIndexDbCacheStore
▸ loadIndexDbCacheStore(cache
): Promise
<CacheStore
>
Parameters
Name | Type |
---|---|
cache | Object |
cache.db | IDBDatabase |
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
Name | Type |
---|---|
stores | { blockNumber : number ; componentToIndex : Map <string , number > ; components : string [] ; entities : string [] ; entityToIndex : Map <string , number > ; state : State }[] |
Returns
Defined in
workers/CacheStore.ts:117 (opens in a new tab)
messagePayload
▸ messagePayload(msg
): string
Parameters
Name | Type |
---|---|
msg | Message |
Returns
string
Defined in
utils.ts:8 (opens in a new tab)
normalizeComponentID
▸ normalizeComponentID(componentID
): string
Parameters
Name | Type |
---|---|
componentID | string | BigNumber |
Returns
string
Defined in
utils.ts:30 (opens in a new tab)
normalizeEntityID
▸ normalizeEntityID(entityID
): EntityID
Parameters
Name | Type |
---|---|
entityID | string | BigNumber | EntityID |
Returns
EntityID
Defined in
utils.ts:15 (opens in a new tab)
parseSystemCallsFromStreamEvents
▸ parseSystemCallsFromStreamEvents(events
): SystemCall
[]
Parameters
Name | Type |
---|---|
events | NetworkComponentUpdate [] |
Returns
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
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 | (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
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 | (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
Name | Type |
---|---|
cache | Object |
cache.db | IDBDatabase |
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 ]>> |
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
workers/CacheStore.ts:135 (opens in a new tab)
storeEvent
▸ storeEvent<Cm
>(cacheStore
, «destructured»
): 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 |
«destructured» | Omit <NetworkComponentUpdate |
Returns
void
Defined in
workers/CacheStore.ts:30 (opens in a new tab)
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 [] |
Returns
void