Skip to content

Commit 5fbc815

Browse files
Automated scrape: 2026-05-22 01:21:29
1 parent 5ffab91 commit 5fbc815

10 files changed

Lines changed: 422 additions & 338 deletions

merged_docs/all_merged.md

Lines changed: 183 additions & 148 deletions
Large diffs are not rendered by default.

merged_docs/cadence_docs_merged.md

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5636,13 +5636,14 @@ access(all) resource BankAccount {
56365636
If there are any functions that modify privileged state that also need to be callable from external code, use [entitlements] for the access modifiers for those functions:
56375637

56385638
```cadence
5639-
/// Simplified Vault implementation
5639+
/// Declare Entitlements at the contract level — entitlements are
5640+
/// namespaced to their contract and referenced by access modifiers
5641+
/// on the contract's resources, structs, and functions.
5642+
access(all) entitlement Owner
5643+
56405644
/// Simplified Bank Account implementation
56415645
access(all) resource BankAccount {
56425646

5643-
/// Declare Entitlements for state-modifying functions
5644-
access(all) entitlement Owner
5645-
56465647
/// Fields should default to access(self) just to be safe
56475648
access(self) var balance: UFix64
56485649

@@ -5694,7 +5695,7 @@ When issuing a capability, a capability of the same type might already be presen
56945695
var flowTokenVaultCap: Capability<auth(FungibleToken.Withdraw) &FlowToken.Vault>? = nil
56955696

56965697
// Get all the capabilities that have already been issued for the desired storage path
5697-
let flowTokenVaultCaps = account.capabilities.storage.getControllers(forPath: /storage/flowTokenVault)
5698+
let flowTokenVaultCaps = signer.capabilities.storage.getControllers(forPath: /storage/flowTokenVault)
56985699

56995700
// Iterate through them to see if there is already one of the needed type
57005701
for cap in flowTokenVaultCaps {
@@ -5708,7 +5709,7 @@ When issuing a capability, a capability of the same type might already be presen
57085709
// issue a new one
57095710
if flowTokenVaultCap == nil {
57105711
// issue a new entitled capability to the flow token vault
5711-
flowTokenVaultCap = account.capabilities.storage.issue<auth(FungibleToken.Withdraw) &FlowToken.Vault>(/storage/flowTokenVault)
5712+
flowTokenVaultCap = signer.capabilities.storage.issue<auth(FungibleToken.Withdraw) &FlowToken.Vault>(/storage/flowTokenVault)
57125713
}
57135714
```
57145715

@@ -5718,7 +5719,7 @@ When publishing a capability, a published capability might already be present. I
57185719

57195720
```cadence
57205721
// Check if the published capability already exists
5721-
if account.capabilities.borrow<&FlowToken.Vault>(/public/flowTokenReceiver) == nil {
5722+
if signer.capabilities.borrow<&FlowToken.Vault>(/public/flowTokenReceiver) == nil {
57225723
// since it doesn't exist yet, we should publish a new one that we created earlier
57235724
signer.capabilities.publish(
57245725
receiverCapability,
@@ -5786,7 +5787,7 @@ If given a less-specific type, cast to the more specific type that is expected.
57865787

57875788
<!-- Relative links. Will not render on the page -->
57885789

5789-
[Cadence Anti-Patterns]: ./design-patterns.md
5790+
[Cadence Anti-Patterns]: ./anti-patterns.md
57905791
[References]: ./language/references.mdx
57915792
[account storage]: ./language/accounts/storage.mdx
57925793
[borrow]: ./language/capabilities.md#capabilities-in-accounts
@@ -9220,7 +9221,7 @@ Adding `self.account.save` or `self.account.publish` to `mintNFT` allows anyone
92209221

92219222
Passing a [fully authorized account reference] as a function parameter is a dangerous anti-pattern.
92229223

9223-
::::
9224+
:::
92249225

92259226
### Deploying and testing
92269227

@@ -12071,7 +12072,9 @@ fun transferNFT(id: UInt64, owner: auth(Storage) &Account) {
1207112072
// Sneakily borrow a reference to the user's Flow Token Vault
1207212073
// and withdraw a bit of FLOW
1207312074
// BAD
12074-
let vaultRef = owner.borrow<&FlowToken.Vault>(/storage/flowTokenVault)!
12075+
let vaultRef = owner.storage.borrow<auth(FungibleToken.Withdraw) &FlowToken.Vault>(
12076+
from: /storage/flowTokenVault
12077+
)!
1207512078
let stolenTokens <- vaultRef.withdraw(amount: 0.1)
1207612079

1207712080
// deposit the stolen funds in the contract owners vault
@@ -17904,7 +17907,7 @@ contract NamedFields {
1790417907
init() {
1790517908
// assign and access the field here and in transactions
1790617909
self.testStoragePath = /storage/testStorage
17907-
self.account.storage.save(<-create Test(), to: self.TestStoragePath)
17910+
self.account.storage.save(<-create Test(), to: self.testStoragePath)
1790817911
}
1790917912
}
1791017913

@@ -18214,15 +18217,15 @@ transaction {
1821418217
prepare(acct: auth(LoadValue, SaveValue) &Account) {
1821518218

1821618219
// Removes the vault from storage, a costly operation
18217-
let vault <- acct.storage.load<@ExampleToken.Vault>(from: /storage/exampleToken)
18220+
let vault <- acct.storage.load<@ExampleToken.Vault>(from: /storage/exampleToken)!
1821818221

1821918222
// Withdraws tokens
18220-
let burnVault <- vault.withdraw(amount: 10)
18223+
let burnVault <- vault.withdraw(amount: 10.0)
1822118224

1822218225
destroy burnVault
1822318226

1822418227
// Saves the used vault back to storage, another costly operation
18225-
acct.storage.save(to: /storage/exampleToken)
18228+
acct.storage.save(<-vault, to: /storage/exampleToken)
1822618229

1822718230
}
1822818231
}
@@ -18234,9 +18237,13 @@ transaction {
1823418237
prepare(acct: auth(BorrowValue) &Account) {
1823518238

1823618239
// Borrows a reference to the stored vault, much less costly operation
18237-
let vault <- acct.storage.borrow<&ExampleToken.Vault>(from: /storage/exampleToken)
18240+
// Borrow returns an optional reference; force-unwrap (or null-check) before use.
18241+
// The reference must be authorized to call entitled methods like `withdraw`.
18242+
let vaultRef = acct.storage.borrow<auth(FungibleToken.Withdraw) &ExampleToken.Vault>(
18243+
from: /storage/exampleToken
18244+
)!
1823818245

18239-
let burnVault <- vault.withdraw(amount: 10)
18246+
let burnVault <- vaultRef.withdraw(amount: 10.0)
1824018247

1824118248
destroy burnVault
1824218249

@@ -18358,25 +18365,25 @@ transaction {
1835818365
var capability: Capability<&ExampleToken.Vault>? = nil
1835918366

1836018367
// get the capability to the vault at the given storage path if it exists
18361-
let vaultCaps = account.capabilities.storage.getControllers(forPath: /storage/exampleTokenVault)
18368+
let vaultCaps = signer.capabilities.storage.getControllers(forPath: /storage/exampleTokenVault)
1836218369
for cap in vaultCaps {
18363-
if let cap = cap as? Capability<&ExampleToken.Vault> {
18370+
if let cap = cap.capability as? Capability<&ExampleToken.Vault> {
1836418371
capability = cap
1836518372
break
1836618373
}
1836718374
}
1836818375

1836918376
if capability == nil {
1837018377
// issue a new capability to the vault since it wasn't found
18371-
capability = account.capabilities.storage.issue<&ExampleToken.Vault>(/storage/exampleTokenVault)
18378+
capability = signer.capabilities.storage.issue<&ExampleToken.Vault>(/storage/exampleTokenVault)
1837218379
}
1837318380

1837418381
let publicPath = /public/exampleTokenReceiver
1837518382

18376-
if signer.capabilities.exits(publicPath) {
18383+
if signer.capabilities.exists(publicPath) {
1837718384
signer.capabilities.unpublish(publicPath)
1837818385
}
18379-
signer.capabilities.publish(capability, at: publicPath)
18386+
signer.capabilities.publish(capability!, at: publicPath)
1838018387
}
1838118388
}
1838218389
```

merged_docs/essentials_merged.md

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -457259,13 +457259,14 @@ access(all) resource BankAccount {
457259457259
If there are any functions that modify privileged state that also need to be callable from external code, use [entitlements] for the access modifiers for those functions:
457260457260

457261457261
```cadence
457262-
/// Simplified Vault implementation
457262+
/// Declare Entitlements at the contract level — entitlements are
457263+
/// namespaced to their contract and referenced by access modifiers
457264+
/// on the contract's resources, structs, and functions.
457265+
access(all) entitlement Owner
457266+
457263457267
/// Simplified Bank Account implementation
457264457268
access(all) resource BankAccount {
457265457269

457266-
/// Declare Entitlements for state-modifying functions
457267-
access(all) entitlement Owner
457268-
457269457270
/// Fields should default to access(self) just to be safe
457270457271
access(self) var balance: UFix64
457271457272

@@ -457317,7 +457318,7 @@ When issuing a capability, a capability of the same type might already be presen
457317457318
var flowTokenVaultCap: Capability<auth(FungibleToken.Withdraw) &FlowToken.Vault>? = nil
457318457319

457319457320
// Get all the capabilities that have already been issued for the desired storage path
457320-
let flowTokenVaultCaps = account.capabilities.storage.getControllers(forPath: /storage/flowTokenVault)
457321+
let flowTokenVaultCaps = signer.capabilities.storage.getControllers(forPath: /storage/flowTokenVault)
457321457322

457322457323
// Iterate through them to see if there is already one of the needed type
457323457324
for cap in flowTokenVaultCaps {
@@ -457331,7 +457332,7 @@ When issuing a capability, a capability of the same type might already be presen
457331457332
// issue a new one
457332457333
if flowTokenVaultCap == nil {
457333457334
// issue a new entitled capability to the flow token vault
457334-
flowTokenVaultCap = account.capabilities.storage.issue<auth(FungibleToken.Withdraw) &FlowToken.Vault>(/storage/flowTokenVault)
457335+
flowTokenVaultCap = signer.capabilities.storage.issue<auth(FungibleToken.Withdraw) &FlowToken.Vault>(/storage/flowTokenVault)
457335457336
}
457336457337
```
457337457338

@@ -457341,7 +457342,7 @@ When publishing a capability, a published capability might already be present. I
457341457342

457342457343
```cadence
457343457344
// Check if the published capability already exists
457344-
if account.capabilities.borrow<&FlowToken.Vault>(/public/flowTokenReceiver) == nil {
457345+
if signer.capabilities.borrow<&FlowToken.Vault>(/public/flowTokenReceiver) == nil {
457345457346
// since it doesn't exist yet, we should publish a new one that we created earlier
457346457347
signer.capabilities.publish(
457347457348
receiverCapability,
@@ -457409,7 +457410,7 @@ If given a less-specific type, cast to the more specific type that is expected.
457409457410

457410457411
<!-- Relative links. Will not render on the page -->
457411457412

457412-
[Cadence Anti-Patterns]: ./design-patterns.md
457413+
[Cadence Anti-Patterns]: ./anti-patterns.md
457413457414
[References]: ./language/references.mdx
457414457415
[account storage]: ./language/accounts/storage.mdx
457415457416
[borrow]: ./language/capabilities.md#capabilities-in-accounts
@@ -460843,7 +460844,7 @@ Adding `self.account.save` or `self.account.publish` to `mintNFT` allows anyone
460843460844

460844460845
Passing a [fully authorized account reference] as a function parameter is a dangerous anti-pattern.
460845460846

460846-
::::
460847+
:::
460847460848

460848460849
### Deploying and testing
460849460850

@@ -463694,7 +463695,9 @@ fun transferNFT(id: UInt64, owner: auth(Storage) &Account) {
463694463695
// Sneakily borrow a reference to the user's Flow Token Vault
463695463696
// and withdraw a bit of FLOW
463696463697
// BAD
463697-
let vaultRef = owner.borrow<&FlowToken.Vault>(/storage/flowTokenVault)!
463698+
let vaultRef = owner.storage.borrow<auth(FungibleToken.Withdraw) &FlowToken.Vault>(
463699+
from: /storage/flowTokenVault
463700+
)!
463698463701
let stolenTokens <- vaultRef.withdraw(amount: 0.1)
463699463702

463700463703
// deposit the stolen funds in the contract owners vault
@@ -469527,7 +469530,7 @@ contract NamedFields {
469527469530
init() {
469528469531
// assign and access the field here and in transactions
469529469532
self.testStoragePath = /storage/testStorage
469530-
self.account.storage.save(<-create Test(), to: self.TestStoragePath)
469533+
self.account.storage.save(<-create Test(), to: self.testStoragePath)
469531469534
}
469532469535
}
469533469536

@@ -469837,15 +469840,15 @@ transaction {
469837469840
prepare(acct: auth(LoadValue, SaveValue) &Account) {
469838469841

469839469842
// Removes the vault from storage, a costly operation
469840-
let vault <- acct.storage.load<@ExampleToken.Vault>(from: /storage/exampleToken)
469843+
let vault <- acct.storage.load<@ExampleToken.Vault>(from: /storage/exampleToken)!
469841469844

469842469845
// Withdraws tokens
469843-
let burnVault <- vault.withdraw(amount: 10)
469846+
let burnVault <- vault.withdraw(amount: 10.0)
469844469847

469845469848
destroy burnVault
469846469849

469847469850
// Saves the used vault back to storage, another costly operation
469848-
acct.storage.save(to: /storage/exampleToken)
469851+
acct.storage.save(<-vault, to: /storage/exampleToken)
469849469852

469850469853
}
469851469854
}
@@ -469857,9 +469860,13 @@ transaction {
469857469860
prepare(acct: auth(BorrowValue) &Account) {
469858469861

469859469862
// Borrows a reference to the stored vault, much less costly operation
469860-
let vault <- acct.storage.borrow<&ExampleToken.Vault>(from: /storage/exampleToken)
469863+
// Borrow returns an optional reference; force-unwrap (or null-check) before use.
469864+
// The reference must be authorized to call entitled methods like `withdraw`.
469865+
let vaultRef = acct.storage.borrow<auth(FungibleToken.Withdraw) &ExampleToken.Vault>(
469866+
from: /storage/exampleToken
469867+
)!
469861469868

469862-
let burnVault <- vault.withdraw(amount: 10)
469869+
let burnVault <- vaultRef.withdraw(amount: 10.0)
469863469870

469864469871
destroy burnVault
469865469872

@@ -469981,25 +469988,25 @@ transaction {
469981469988
var capability: Capability<&ExampleToken.Vault>? = nil
469982469989

469983469990
// get the capability to the vault at the given storage path if it exists
469984-
let vaultCaps = account.capabilities.storage.getControllers(forPath: /storage/exampleTokenVault)
469991+
let vaultCaps = signer.capabilities.storage.getControllers(forPath: /storage/exampleTokenVault)
469985469992
for cap in vaultCaps {
469986-
if let cap = cap as? Capability<&ExampleToken.Vault> {
469993+
if let cap = cap.capability as? Capability<&ExampleToken.Vault> {
469987469994
capability = cap
469988469995
break
469989469996
}
469990469997
}
469991469998

469992469999
if capability == nil {
469993470000
// issue a new capability to the vault since it wasn't found
469994-
capability = account.capabilities.storage.issue<&ExampleToken.Vault>(/storage/exampleTokenVault)
470001+
capability = signer.capabilities.storage.issue<&ExampleToken.Vault>(/storage/exampleTokenVault)
469995470002
}
469996470003

469997470004
let publicPath = /public/exampleTokenReceiver
469998470005

469999-
if signer.capabilities.exits(publicPath) {
470006+
if signer.capabilities.exists(publicPath) {
470000470007
signer.capabilities.unpublish(publicPath)
470001470008
}
470002-
signer.capabilities.publish(capability, at: publicPath)
470009+
signer.capabilities.publish(capability!, at: publicPath)
470003470010
}
470004470011
}
470005470012
```

0 commit comments

Comments
 (0)