0.6.125 • Published 14 days ago

@dojoengine/core v0.6.125

Weekly downloads
-
License
MIT
Repository
-
Last release
14 days ago

@dojoengine/core

This library abstracts away the world interface and provides a set of helper functions to interact with the world. It is preferred to use this library over interacting with the world directly.

  • World explorers
  • Games
  • Analytics

Getting Started

bun add @dojoengine/core

Example Class Usage

This is an example from Dojo React App

import { defineContractComponents } from "./contractComponents";
import { world } from "./world";
import { RPCProvider, Query, } from "@dojoengine/core";
import { Account, num } from "starknet";
import { GraphQLClient } from 'graphql-request';
import { getSdk } from '../generated/graphql';

// Import the manifest from your project
import manifest from "../../../dojo-starter/target/dev/manifest.json";

export type SetupNetworkResult = Awaited<ReturnType<typeof setupNetwork>>;

export async function setupNetwork() {
    // Extract environment variables for better readability.
    const { VITE_PUBLIC_WORLD_ADDRESS, VITE_PUBLIC_NODE_URL, VITE_PUBLIC_TORII } = import.meta.env;

    // Create a new RPCProvider instance.
    const provider = new RPCProvider(VITE_PUBLIC_WORLD_ADDRESS, manifest, VITE_PUBLIC_NODE_URL);

    // Return the setup object.
    return {
        provider,
        world,

        // Define contract components for the world.
        contractComponents: defineContractComponents(world),

        // Define the graph SDK instance.
        graphSdk: () => getSdk(new GraphQLClient(VITE_PUBLIC_TORII)),

        // Execute function.
        execute: async (signer: Account, contract: string, system: string, call_data: num.BigNumberish[]) => {
            return provider.execute(signer, contract, system, call_data);
        },

        // Read-only function call.
        call: async (contract: string, system: string, call_data: num.BigNumberish[]) => {
            return provider.call(contract, system, call_data);
        },

        // Entity query function.
        entity: async (component: string, query: Query) => {
            return provider.entity(component, query);
        },

        // Entities query function.
        entities: async (component: string, partition: number) => {
            return provider.entities(component, partition);
        }
    };
}

Generating Components

The core package comes bundled with a component generation script that you can use to streamline development. It is exposed via a binary and in your package.json you can include a script.

  "scripts": {
    "create-components": "npx @dojoengine/core src/dojo/manifest.json src/dojo/contractComponents.ts"
  },

You must point the script to your games manifest file and the output file. The output file will be overwritten so make sure you don't have any changes you want to keep.

Note: As of 0.3.0 custom types are not supported, so you will need to manualy adjust these.

Extending the Core

We all aspire to create environments that prioritize easy extensibility. The foundational class, RPCProvider, unveils the API for these worlds. If you're designing a world and wish for developers to seamlessly expand upon it, simply extend the RPCProvider class and introduce your unique methods.

import { RPCProvider } from "@dojoengine/core";

export class EternumProvider extends RPCProvider {
    constructor(world_address: string, url?: string) {
        super(world_address, url);
    }

    //...custom methods
}

New developer will instantly then know how to interact with your world!

0.6.125

14 days ago

0.6.122

29 days ago

0.6.121

1 month ago

0.6.12

1 month ago

0.6.11

1 month ago

0.6.1

1 month ago

0.6.1-alpha.1

1 month ago

0.6.0-alpha.5

1 month ago

0.6.1-alpha.0

2 months ago

0.6.0-alpha.0

2 months ago

0.5.11-alpha.0

3 months ago

0.5.10-alpha.0

3 months ago

0.5.9

3 months ago

0.5.8

3 months ago

0.5.7

3 months ago

0.5.6

3 months ago

0.5.4

3 months ago

0.5.5

3 months ago

0.5.3

3 months ago

0.5.2

3 months ago

0.5.0

3 months ago

0.5.1

3 months ago

0.3.5

3 months ago

0.3.4

4 months ago

0.3.3

4 months ago

0.3.2

4 months ago

0.2.10

5 months ago

0.2.9

5 months ago

0.2.8

5 months ago

0.2.7

5 months ago

0.2.5

5 months ago

0.2.3

5 months ago

0.2.2

5 months ago

0.2.0

5 months ago

0.1.62-alpha.0

5 months ago

0.2.0-alpha.0

5 months ago

0.1.61-alpha.0

5 months ago

0.1.60

5 months ago

0.1.58

5 months ago

0.1.56

5 months ago

0.1.55

6 months ago

0.1.54

6 months ago

0.1.53

6 months ago

0.1.51

6 months ago

0.1.50

6 months ago

0.1.49

6 months ago

0.1.48

6 months ago

0.1.47

6 months ago

0.1.46

6 months ago

0.1.44

6 months ago

0.1.43

6 months ago

0.1.41

6 months ago

0.1.38

6 months ago

0.1.37

6 months ago

0.1.36

6 months ago

0.1.35

6 months ago

0.1.34

6 months ago

0.1.33

6 months ago

0.1.32

6 months ago

0.1.31

6 months ago

0.1.30

7 months ago

0.1.29

7 months ago

0.1.28

7 months ago

0.1.27

7 months ago

0.1.26

7 months ago

0.1.25

7 months ago

0.1.23

7 months ago

0.1.22

7 months ago

0.1.21

7 months ago

0.1.2

7 months ago

0.1.1

7 months ago

0.1.0

7 months ago

0.0.27

7 months ago

0.0.26

7 months ago

0.0.24

7 months ago

0.0.23

7 months ago

0.0.22

7 months ago

0.0.21

7 months ago

0.0.20

8 months ago

0.0.19

8 months ago

0.0.18

8 months ago

0.0.17

8 months ago

0.0.16

8 months ago

0.0.15

9 months ago

0.0.14

9 months ago

0.0.13

9 months ago

0.0.11

9 months ago

0.0.10

9 months ago

0.0.9

9 months ago

0.0.81

9 months ago

0.0.8

9 months ago

0.0.7

9 months ago

0.0.6

10 months ago

0.0.5

10 months ago

0.0.4

10 months ago

0.0.3

10 months ago

0.0.2

10 months ago

0.0.1

10 months ago