docs/content/guides/developer/objects/object-ownership/address-owned.mdx
Address-owned objects are owned by a 32-byte address. 32-byte addresses are either an account address derived from a particular signature scheme or an object ID. An address-owned object is only accessible to its owner. You can transfer objects that you own to different addresses.
Use these transfer module functions to create address-owned objects:
Use the sui::transfer::transfer function if you are defining custom transfer rules for the object.
Use the sui::transfer::public_transfer function to create an address-owned object if the object has the store capability.
public fun transfer<T: key>(obj: T, recipient: address)
public fun public_transfer<T: key + store>(obj: T, recipient: address)
An object's ownership can change over the life of that object, either by adding it as a dynamic object field, transferring it to a different address, or making it immutable. However, after you create an object and set its ownership, it cannot be shared.
<ImportContent source="examples/move/basics/sources/object_basics.move" mode="code" fun="create" noComments />Use address-owned objects when you need:
Single ownership
Better performance than shared objects
Avoidance of consensus sequencing
You can access address-owned objects in 2 different ways depending on whether the address owner of the object corresponds to an address or an object ID.
If the address owner of the object is an account address, then you can use and access it directly as an owned object during the execution of a transaction signed by that address. Other addresses cannot access owned objects in any way.
If the address owner of the object corresponds to an object ID, then you must access and dynamically authenticate it during the execution of the transaction using the mechanisms defined in Transfer to Object.
To interact with an address-owned object through the CLI, first view the objects you own:
$ export ADDR=`sui client active-address`
$ sui client objects $ADDR
You can see sui::transfer::public_transfer function used in the color_object example module tests. The test creates a new address-owned ColorObject object, then calls public_transfer to transfer it to the owner's address.
Save the color_object example code, then publish the ColorObject code on-chain using the Sui CLI:
$ sui client publish $ROOT/examples/move/color_object --gas-budget <GAS-AMOUNT>
Set the package object ID to the $PACKAGE environment variable, if you have it set. Then create a new ColorObject:
$ sui client call --gas-budget <GAS-AMOUNT> --package $PACKAGE --module "color_object" --function "create" --args 0 255 0
Set the newly created object ID to $OBJECT. To view the objects in the current active address:
$ sui client objects $ADDR
You can see that it is now owned by your address by querying the object information and viewing the Owner field in the output:
$ sui client object $OBJECT
The following test creates an address-owned object, transfers it to the owner, then verifies that the owner field is correct:
<ImportContent source="examples/move/color_object/sources/example.move" mode="code" fun="test_transfer"/>