Keyboard shortcuts

Press or to navigate between chapters

Press ? to show this help

Press Esc to hide this help

Resource

Resource is the type of the resource that can be registered in the world.

Caching the namespace hash of a contract and model in the world saves gas, instead of re-computing the descriptor each time, which involves several poseidon hash operations.

Namespaced resources: Those resources are scoped by a namespace, which defines a logical separation of resources. Namespaced resources are Model, Event and Contract.

  • World: The world itself, identified by the selector 0.

  • Namespace: ByteArray Namespace is a unique resource type, identified by a ByteArray, to scope models, events and contracts. The poseidon hash of the serialized ByteArray is used as the namespace hash.

  • Model: (ContractAddress, NamespaceHash) A model defines data that can be stored in the world’s storage.

  • Event: (ContractAddress, NamespaceHash) An event is never stored in the world’s storage, but it’s emitted by the world to be consumed by off-chain components.

  • Contract: (ContractAddress, NamespaceHash) A contract defines user logic to interact with the world’s data (models) and to emit events.

  • Library: (ClassHash, NamespaceHash) A library defines user logic.

  • Unregistered: The unregistered state, required to ensure the security of the world to not have operations done on non-existent resources.

WARNING: enum order must be preserved to ensure backward compatibility

Fully qualified path: dojo::world::resource::Resource

pub enum Resource {
    Model: (ContractAddress, felt252),
    Event: (ContractAddress, felt252),
    Contract: (ContractAddress, felt252),
    Namespace: ByteArray,
    World,
    Unregistered,
    Library: (ClassHash, felt252),
    ExternalContract: (ContractAddress, felt252),
}

Variants

Model

Fully qualified path: dojo::world::resource::Resource::Model

Model: (ContractAddress, felt252)

Event

Fully qualified path: dojo::world::resource::Resource::Event

Event: (ContractAddress, felt252)

Contract

Fully qualified path: dojo::world::resource::Resource::Contract

Contract: (ContractAddress, felt252)

Namespace

Fully qualified path: dojo::world::resource::Resource::Namespace

Namespace: ByteArray

World

Fully qualified path: dojo::world::resource::Resource::World

World

Unregistered

Fully qualified path: dojo::world::resource::Resource::Unregistered

Unregistered

Library

Fully qualified path: dojo::world::resource::Resource::Library

Library: (ClassHash, felt252)

ExternalContract

Fully qualified path: dojo::world::resource::Resource::ExternalContract

ExternalContract: (ContractAddress, felt252)