You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following sections describe how to perform read and write operation to view account details.
78
74
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
83
76
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:
86
80
87
81
```cadence
88
82
view fun getAccount(_ address: Address): &Account
89
83
```
90
84
91
-
### Performing write operations
85
+
### Write operations
92
86
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.
95
88
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.
99
90
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.
103
92
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.
107
94
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.
111
96
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.
116
98
117
99
For example, a transaction that deploys a contract to an account can be written as follows:
118
100
@@ -124,45 +106,30 @@ transaction {
124
106
}
125
107
```
126
108
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.
130
110
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:
132
112
133
113
```cadence
134
114
view fun getAuthAccount<T: &Account>(_ address: Address): T
135
115
```
136
116
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.
143
118
144
119
## Creating an account
145
120
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.
149
122
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.
152
124
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):
158
126
159
127
```cadence
160
128
fun Account(payer: auth(BorrowValue | Storage) &Account):
Copy file name to clipboardExpand all lines: docs/language/accounts/paths.mdx
+5-13Lines changed: 5 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,25 +3,17 @@ title: Paths
3
3
sidebar_position: 1
4
4
---
5
5
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.
8
7
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`.
12
9
13
10
There are two valid domains: `storage` and `public`.
14
11
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`.
18
13
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.
22
15
23
-
The `public` domain stores capabilities,
24
-
which are accessible by anyone.
16
+
The `public` domain stores capabilities, which are accessible by anyone.
0 commit comments