11import {
2+ type Abi ,
23 type Account ,
34 type AccountInterface ,
45 type AllowArray ,
@@ -15,7 +16,7 @@ import {
1516
1617import { LOCAL_KATANA } from "../constants" ;
1718import { ConsoleLogger , type LogLevel } from "../logger/logger" ;
18- import { type DojoCall , WorldEntryPoints } from "../types" ;
19+ import { type DojoCall , type DojoManifest , WorldEntryPoints } from "../types" ;
1920import { compileDojoCalldata } from "../utils/compile" ;
2021import { getContractAbi , getContractByName , parseDojoCall } from "../utils" ;
2122import { Provider } from "./provider" ;
@@ -101,17 +102,17 @@ type ActionMethodImplementation = (
101102class DojoProviderBase extends Provider {
102103 public provider : RpcProvider ;
103104 public contract : Contract ;
104- public manifest : any ;
105+ public manifest : DojoManifest ;
105106 public logger : ConsoleLogger ;
106107
107108 /**
108109 * Constructor: Initializes the DojoProvider with the given world address, manifest and URL.
109110 *
110- * @param {string } world_address - Address of the world .
111+ * @param {DojoManifest } manifest - The Dojo manifest object .
111112 * @param {string } [url=LOCAL_KATANA] - RPC URL (defaults to LOCAL_KATANA).
112113 */
113114 constructor (
114- manifest ?: any ,
115+ manifest : DojoManifest ,
115116 url : string = LOCAL_KATANA ,
116117 logLevel : LogLevel = "none"
117118 ) {
@@ -121,7 +122,7 @@ class DojoProviderBase extends Provider {
121122 } ) ;
122123
123124 this . contract = new Contract ( {
124- abi : manifest . world . abi ?? manifest . abis ?? [ ] ,
125+ abi : ( manifest . world . abi ?? manifest . abis ?? [ ] ) as Abi ,
125126 address : this . getWorldAddress ( ) ,
126127 providerOrAccount : this . provider ,
127128 } ) ;
@@ -292,13 +293,24 @@ class DojoProviderBase extends Provider {
292293 nameSpace ,
293294 call . contractName
294295 ) ;
296+
297+ if ( ! contractInfos ) {
298+ throw new Error (
299+ `Contract "${ call . contractName } " not found in namespace "${ nameSpace } "`
300+ ) ;
301+ }
302+
303+ const contractAbi = getContractAbi (
304+ this . manifest ,
305+ contractInfos
306+ ) ;
295307 const contract = new Contract ( {
296- abi : contractInfos . abi ,
308+ abi : contractAbi ,
297309 address : contractInfos . address ,
298310 providerOrAccount : this . provider ,
299311 } ) ;
300312 const compiledCalldata = compileDojoCalldata (
301- contractInfos . abi ,
313+ contractAbi ,
302314 nameSpace ,
303315 call . contractName ,
304316 call . entrypoint ,
@@ -357,9 +369,9 @@ class DojoProviderBase extends Provider {
357369 > ;
358370
359371 const functionCounts = new Map < string , number > ( ) ;
360- for ( const contract of this . manifest . contracts as Array < any > ) {
372+ for ( const contract of this . manifest . contracts ?? [ ] ) {
361373 if ( ! contract ?. systems ?. length ) continue ;
362- for ( const systemName of contract . systems as Array < string > ) {
374+ for ( const systemName of contract . systems ) {
363375 functionCounts . set (
364376 systemName ,
365377 ( functionCounts . get ( systemName ) || 0 ) + 1
@@ -374,7 +386,7 @@ class DojoProviderBase extends Provider {
374386 value !== null &&
375387 "execute" in ( value as Record < string , unknown > ) ;
376388
377- for ( const contract of this . manifest . contracts as Array < any > ) {
389+ for ( const contract of this . manifest . contracts ?? [ ] ) {
378390 if (
379391 ! contract ?. systems ?. length ||
380392 typeof contract . tag !== "string"
@@ -507,7 +519,7 @@ export type DojoProviderInstance<Actions = never> = DojoProviderBase &
507519export type DojoProvider < Actions = never > = DojoProviderInstance < Actions > ;
508520
509521type DojoProviderConstructor = new < Actions = never > (
510- manifest ?: any ,
522+ manifest : DojoManifest ,
511523 url ?: string ,
512524 logLevel ?: LogLevel
513525) => DojoProvider < Actions > ;
0 commit comments