Skip to content

Commit

Permalink
Make resource accounts not dependent on Mint NFT (#5805)
Browse files Browse the repository at this point in the history
* Make resource accounts not dependent on Mint NFT

* Add clarification from Wolfgang

Addressing Christian's issue in:
#5672
  • Loading branch information
clay-aptos authored Dec 8, 2022
1 parent d280cd0 commit 5adf300
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
17 changes: 11 additions & 6 deletions developer-docs-site/docs/guides/resource-accounts.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,23 @@ Typically, a resource account is used for two main purposes:

## Restrictions

In Aptos, a resource account is created based upon the SHA3-256 hash of the source's address and additional seed data. A resource account can be created only once. An entity may call `create_account` in an attempt to claim an account ahead of the creation of a resource account. But if a resource account is found, Aptos will transition ownership of the account over to the resource account. This is done by validating that the account has yet to execute any transactions and that the `Account::signer_capbility_offer::for` is none. The probability of a collision where someone has legitimately produced a private key that maps to a resource account address is improbably low.
In Aptos, a resource account is created based upon the SHA3-256 hash of the source's address and additional seed data. A resource account can be created only once; for a given source address and seed, there can be only one resource account. That is because the calculation of the resource account address is fully determined by the former.

An entity may call `create_account` in an attempt to claim an account ahead of the creation of a resource account. But if a resource account is found, Aptos will transition ownership of the account over to the resource account. This is done by validating that the account has yet to execute any transactions and that the `Account::signer_capbility_offer::for` is none. The probability of a collision where someone has legitimately produced a private key that maps to a resource account address is improbably low.

## Setup

To properly set a resource account up, you will need to [initialize](https://github.com/aptos-labs/aptos-core/blob/2e9d8ee759fcd3f6e831034f05c1656b1c48efc4/aptos-move/move-examples/mint_nft/sources/minting.move#L73) the `mint_nft` module and retrieve the signer capability from both the resource account and module account. To do so, call `create_resource_account_and_publish_package` to publish the module under the resource account's address.
The easiest way to set up a resource account is by:

You have three options for creating a resource account:
* `create_resource_account_and_publish_package` - creates the resource account and results in loss of access to the resource account by design, because resource accounts are used to make contracts autonomous and immutable.
* `create_resource_account_and_fund` - creates the resource account and funds it, retaining access to the resource account's signer until explicitly calling `retrieve_resource_account_cap`.
1. Using Aptos CLI: `aptos account create-resource-account` creates a resource account, and `aptos move create-resource-account-and-publish-package` creates a resource account and publishes the specified package under the resource account's adddress.
1. Writing custom smart contracts code: in the `resource_account.move` module, developers can find the resource account creation functions `create_resource_account`, `create_resource_account_and_fund`, and `create_resource_account_and_publish_package`. Developers can then call those functions to create resource accounts in their smart contracts.

Each of those options offers slightly different functionality:
* `create_resource_account` - merely creates the resource account but doesn't fund it, retaining access to the resource account's signer until explicitly calling `retrieve_resource_account_cap`.
* `create_resource_account_and_fund` - creates the resource account and funds it, retaining access to the resource account's signer until explicitly calling `retrieve_resource_account_cap`.
* `create_resource_account_and_publish_package` - creates the resource account and results in loss of access to the resource account by design, because resource accounts are used to make contracts autonomous and immutable.

Follow these steps and examples, which assume use of `create_resource_account_and_publish_package`:
In this example, you will [initialize](https://github.com/aptos-labs/aptos-core/blob/2e9d8ee759fcd3f6e831034f05c1656b1c48efc4/aptos-move/move-examples/mint_nft/sources/minting.move#L73) the `mint_nft` module and retrieve the signer capability from both the resource account and module account. To do so, call `create_resource_account_and_publish_package` to publish the module under the resource account's address.

1. Initialize the module as shown in the [`minting.move`](https://github.com/aptos-labs/aptos-core/blob/2e9d8ee759fcd3f6e831034f05c1656b1c48efc4/aptos-move/move-examples/mint_nft/sources/minting.move#L73) example.
1. Call `create_resource_account_and_publish_package` to publish the module under the resource account's address, such as in the [`mint_nft.rs`](https://github.com/aptos-labs/aptos-core/blob/main/aptos-move/e2e-move-tests/src/tests/mint_nft.rs#L62) end-to-end example.
Expand Down
1 change: 1 addition & 0 deletions developer-docs-site/scripts/additional_dict.txt
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ STM
SYNACK
Scalable
SeaLevel
SHA
SignMessagePayload
SignerCap
Skylake
Expand Down

0 comments on commit 5adf300

Please sign in to comment.