Using objects

Using objects

Using an object as an entry function argument

0x1::object::Object<T> can be used as an input argument to an entry function. It's encoded as the address of the object, and type checked to the value in T.

For more generic functions, this can be handled as providing a generic T for typing the input:

module my_addr::object_playground {
  use endless_framework::object::Object;

  /// This will fail of the object doesn't have the generic `T` stored
  entry fun do_something<T>(object: Object<T>) {
    // ...
  }
}

Additionally, the individual resources that are at the object can be used. The resource will be checked for existence before the function executes.

module my_addr::object_playground {
  use endless_framework::object::Object;

  struct MyAwesomeStruct has key {}

  /// This will fail if the object doesn't have MyAwesomeStruct stored
  entry fun do_something(object: Object<MyAwesomeStruct>) {
    // ...
  }
}

The resource 0x1::object::ObjectCore is available for all objects

Object Types

Objects can store multiple resources at their address, and you can refer to an Object by any of those types. You can convert an address to an object, or convert an object between types as long as the resource is available.

Object ownership

Objects can be owned by any address, this includes Objects, Accounts, and Resource accounts. This allows composability between objects, as well as complex relationships between objects.

Looking up ownership

Ownership can be found by a few methods:

Transfer of ownership

An object can be transferred as long as ungated transfer has not been disabled. See disabling transfer of an object.

If the ungated transfer is disabled, only transfers can be done with a TransferRef or a LinearTransferRef. When ungated transfers are enabled, objects can be transferred as follows:

Deleting or Burning objects

There are two ways to remove an object:

  • Delete

  • Burn

Deleting

To delete an object, the user must have a DeleteRef see allowing deletion of an object.

Burning

However, if the object is not deletable, you can tombstone and burn the unwanted object.

If a user decided that they did not want to burn it, they can un-burn it

Example contracts

Last updated