Resource Account
Resource accounts in Move offer a revolutionary approach to smart contract deployment and resource management. Unlike traditional object code deployment, these accounts provide enhanced control and flexibility for on-chain operations.
At its core, a resource account in Move functions as an autonomous entity, separate from user-controlled accounts. This separation allows for more robust module publishing and sophisticated access control mechanisms.
Resource accounts serve two primary functions:
- Asset Isolation: They create a dedicated environment for hosting and managing specific resources within a module, ensuring better organization and security.
- Autonomous Module Deployment: By establishing independent accounts for module deployment, resource accounts enhance the decentralization of smart contracts. This approach eliminates the need for private key management, with governance potentially handled through separate modules.
Setup Process
Developers can establish resource accounts through two main methods:
Movement Command Line Interface (CLI)
Streamlined commands like movement account create-resource-account
and movement move create-resource-account-and-publish-package
simplify the creation of resource accounts and associated package publishing.
Here are the CLI commands to run for each method:
# For create_resource_account
movement account create-resource-account --seed hello
- Result
Transaction submitted: https://explorer.aptoslabs.com/txn/0x4b4628d7bb0c17754cfdfcd97a62c3191e31023f587191f1ed151988df98fa34?network=devnet
{
"Result": {
"resource_account": "a7b49a0b410256e1f4e4fd5fbbbc39c6f75d754c26fb96714b484820a3dcd43e",
"transaction_hash": "0x4b4628d7bb0c17754cfdfcd97a62c3191e31023f587191f1ed151988df98fa34",
"gas_used": 973,
"gas_unit_price": 100,
"sender": "3ebfa1047b74a82ee98b272abd6c83461007d4bc50ffe2ea363c61abe0ee89c9",
"sequence_number": 0,
"success": true,
"timestamp_us": 1728287140564035,
"version": 41288052,
"vm_status": "Executed successfully"
}
}
Here, you will initialize a resource_account
with the address: 0xa7b49a0b410256e1f4e4fd5fbbbc39c6f75d754c26fb96714b484820a3dcd43e
. It functions similarly to a regular account but lacks a private key
. To interact with this account, you must go through its owner—the default account that created it.
Smart Contract Integration
Aptos Move provides functions such as create_resource_account
, create_resource_account_and_fund
, and create_resource_account_and_publish_package
for programmatic management of resource accounts.
Each method provides distinct capabilities:
create_resource_account
: Generates an unfunded account, retaining signer access until explicitly released.create_resource_account_and_fund
: Establishes and funds the account, maintaining signer access until voluntarily relinquished.create_resource_account_and_publish_package
: Creates the account and immediately withdraws access, ideal for deploying self-governing and immutable contracts.
Critical Aspects
The creation of resource accounts in Aptos follows a unique protocol. It utilizes a SHA3-256 hash derived from the source address and additional seed data. This method guarantees the uniqueness of each resource account and prevents duplicate creation for a given source and seed pair.
Aptos implements protective measures for cases where an entity attempts to claim an address matching a potential resource account. If such an account is identified, ownership transfers to the resource account, provided the claimed account is transaction-free and lacks specific capabilities.