Skip to content

Commit 4b54704

Browse files
authored
Merge pull request #244 from onflow/accounts-index
Edit Accounts Index and Paths articles
2 parents 4af26b1 + 642f638 commit 4b54704

2 files changed

Lines changed: 39 additions & 69 deletions

File tree

docs/language/accounts/index.mdx

Lines changed: 34 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,10 @@
22
title: Accounts
33
---
44

5-
The type `Account` provides access to accounts,
6-
Accounts are only accessed through [references](../references.mdx),
7-
which might be [authorized](../references.mdx#authorized-references).
5+
The type `Account` provides access to accounts. Accounts are only accessed through [references], which might be [authorized].
86

9-
Account objects provide information about and allow the management of
10-
different aspects of the account, such as [account storage](./storage.mdx),
11-
[keys](./keys.mdx), [contracts](./contracts.mdx),
12-
and [capabilities](./capabilities.mdx).
7+
Account objects provide information about and allow the management of different aspects of the account, such as [account storage],
8+
[keys], [contracts], and [capabilities].
139

1410
```cadence
1511
access(all)
@@ -72,47 +68,33 @@ entitlement mapping AccountMapping {
7268
}
7369
```
7470

75-
## Account access
71+
## Accessing an account
7672

77-
### Performing read operations
73+
The following sections describe how to perform read and write operation to view account details.
7874

79-
Access to an `&Account` means having "read access" to it.
80-
For example, the `address` and `balance` fields have the `access(all)` modifier,
81-
so are always accessible, which is safe because this information is public,
82-
and the fields are read-only.
75+
### Read operations
8376

84-
Any code can get a "read-only" reference to an account (`&Account`)
85-
at a given address by using the built-in `getAccount` function:
77+
Access to an `&Account` means having _read access_ to it. For example, the `address` and `balance` fields have the `access(all)` modifier, so they are always accessible, which is safe because this information is public, and the fields are read-only.
78+
79+
Any code can get a read-only reference to an account (`&Account`) at a given address by using the built-in `getAccount` function:
8680

8781
```cadence
8882
view fun getAccount(_ address: Address): &Account
8983
```
9084

91-
### Performing write operations
85+
### Write operations
9286

93-
Access to an authorized account reference (`auth(...) &Account`)
94-
means having certain "write access" to it.
87+
Access to an authorized account reference (`auth(...) &Account`) means having a certain **write access** to it.
9588

96-
[Entitlements](../access-control.md#entitlements) authorize access to accounts.
97-
Cadence provides both coarse-grained and fine-grained entitlements,
98-
which decide what management functions are accessible on the account.
89+
[Entitlements] authorize access to accounts. Cadence provides both coarse-grained and fine-grained entitlements, which decide what management functions are accessible on the account.
9990

100-
For example, the coarse-grained entitlement `Storage` grants access to all
101-
storage related functions, such as `save` and `load`, which save a value to storage,
102-
and load a value from storage respectively.
91+
For example, the coarse-grained entitlement `Storage` grants access to all storage related functions, such as `save` and `load`, which save a value to storage, and load a value from storage respectively.
10392

104-
The fine-grained entitlement `AddKey` for instance,
105-
grants access to only the `add` function of the `Account.Keys` value,
106-
that is, it grants access to adding a key to the account.
93+
The fine-grained entitlement `AddKey`, for instance, grants access to only the `add` function of the `Account.Keys` value — that is, it grants access to adding a key to the account.
10794

108-
An authorized account reference like `auth(Storage, AddKey) &Account`
109-
therefore provides read access, as well as write access to storage,
110-
and the ability to add a new key to that account.
95+
An authorized account reference like `auth(Storage, AddKey) &Account` therefore provides read access, as well as write access to storage, and the ability to add a new key to that account.
11196

112-
[Signed transactions](../transactions.md) can get authorized account references
113-
for each signer of the transaction that signs as an authorizer.
114-
The `prepare` phase of the transaction can specify exactly which entitlements
115-
it needs to perform its work.
97+
[Signed transactions] can get authorized account references for each signer of the transaction that signs as an authorizer. The `prepare` phase of the transaction can specify exactly which entitlements it needs to perform its work.
11698

11799
For example, a transaction that deploys a contract to an account can be written as follows:
118100

@@ -124,45 +106,30 @@ transaction {
124106
}
125107
```
126108

127-
Here, the transaction requests an authorized reference with the `AddContract` entitlement.
128-
That means that the transaction is entitled to add a contract to the account,
129-
but is not able to add another key to the account, for example.
109+
In this example, the transaction requests an authorized reference with the `AddContract` entitlement. That means that the transaction is entitled to add a contract to the account, but is not able to add another key to the account, for example.
130110

131-
Script can get any kind of access to any account, using the built-in `getAuthAccount` function:
111+
The following Script can get any kind of access to any account, using the built-in `getAuthAccount` function:
132112

133113
```cadence
134114
view fun getAuthAccount<T: &Account>(_ address: Address): T
135115
```
136116

137-
This function is only available in scripts.
138-
Though scripts can perform write operations,
139-
they discard their changes upon completion.
140-
Attempting to use this function outside of a script,
141-
for example in a transaction,
142-
causes a type error.
117+
This function is only available in scripts. Though scripts can perform write operations, they discard their changes upon completion. Attempting to use this function outside of a script (e.g., in a transaction) causes a type error.
143118

144119
## Creating an account
145120

146-
The `Account` constructor allows creating new accounts.
147-
The function requires a reference to a _payer_ account,
148-
which should pay for the account creation.
121+
The `Account` constructor allows the creation of new accounts. The function requires a reference to a _payer_ account, which should pay for the account creation.
149122

150-
The payer account must have enough funds to be able to create an account.
151-
If the account does not have the required funds, the program aborts.
123+
The payer account must have enough funds to be able to create an account. If the account does not have the required funds, the program aborts.
152124

153-
The constructor returns a reference to the new account
154-
which has all coarse-grained account entitlements
155-
(it has the type `auth(Storage, Contracts, Keys, Inbox, Capabilities) &Account`).
156-
This provides write access to all parts fo the new account,
157-
for example, storage, contracts, and keys.
125+
The constructor returns a reference to the new account, which has all coarse-grained account entitlements (it has the type `auth(Storage, Contracts, Keys, Inbox, Capabilities) Account`). This provides write access to all parts fo the new account (e.g., storage, contracts, and keys):
158126

159127
```cadence
160128
fun Account(payer: auth(BorrowValue | Storage) &Account):
161129
auth(Storage, Contracts, Keys, Inbox, Capabilities) &Account
162130
```
163131

164-
For example, the following transaction creates a new account
165-
and has the signer of the transaction pay for it:
132+
For example, the following transaction creates a new account and has the signer of the transaction pay for it:
166133

167134
```cadence
168135
transaction {
@@ -171,3 +138,14 @@ transaction {
171138
}
172139
}
173140
```
141+
142+
<!-- Relative links. Will not render on the page -->
143+
144+
[references]: ../references.mdx
145+
[authorized]: ../references.mdx#authorized-references
146+
[account storage]: ./storage.mdx
147+
[keys]: ./keys.mdx
148+
[contracts]: ../contracts.mdx
149+
[capabilities]: ../capabilities.md
150+
[Entitlements]: ../access-control.md#entitlements
151+
[Signed transactions]: ../transactions.md

docs/language/accounts/paths.mdx

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,17 @@ title: Paths
33
sidebar_position: 1
44
---
55

6-
Account storage stores objects under paths.
7-
Paths consist of a domain and an identifier.
6+
Account storage stores objects under paths. Paths consist of a domain and an identifier.
87

9-
Paths start with the character `/`, followed by the domain, the path separator `/`,
10-
and finally the identifier. The identifier must start with a letter and can only be followed by letters, numbers, or the underscore `_`.
11-
For example, the path `/storage/test` has the domain `storage` and the identifier `test`.
8+
Paths start with the character `/`, followed by the domain, the path separator `/`, and finally the identifier. The identifier must start with a letter and can only be followed by letters, numbers, or the underscore `_`. For example, the path `/storage/test` has the domain `storage` and the identifier `test`.
129

1310
There are two valid domains: `storage` and `public`.
1411

15-
Paths in the storage domain have type `StoragePath`,
16-
and paths in the public domain have the type `PublicPath`.
17-
Both `StoragePath` and `PublicPath` are subtypes of `Path`.
12+
Paths in the storage domain have type `StoragePath`, and paths in the public domain have the type `PublicPath`. Both `StoragePath` and `PublicPath` are subtypes of `Path`.
1813

19-
The `storage` domain stores storable objects, such as resources and structs.
20-
Objects stored under the `storage` domain are only accessible through account references
21-
which are authorized with a storage entitlement.
14+
The `storage` domain stores storable objects, such as resources and structs. Objects stored under the `storage` domain are only accessible through account references, which are authorized with a storage entitlement.
2215

23-
The `public` domain stores capabilities,
24-
which are accessible by anyone.
16+
The `public` domain stores capabilities, which are accessible by anyone.
2517

2618
## Path functions
2719

0 commit comments

Comments
 (0)