Skip to content

Commit b126e4e

Browse files
committed
docs: migrate and improve all documentation for Fumadocs
Restructure: move docs/ → content/docs/, .md → .mdx, remove Docusaurus syntax (admonitions, _category_.json), normalize cross-doc links to relative paths, add meta.json files for sidebar ordering. Content improvements on top of the structural move: - Tutorial series rewritten for Cadence 1.0 (entitlements, updated playground links, correct resource syntax throughout) - Forward-port PR #289: references clarification in language/references.mdx - Forward-port PR #290: ContractUpdateValidator scope fix in language/contract-updatability.mdx - Forward-port PR #291: testing-framework syntax modernization - Add frontmatter descriptions to design-patterns and security-best-practices - Fix Cadence syntax defects found during audit (casing, deprecated keywords)
1 parent 5be7cf5 commit b126e4e

118 files changed

Lines changed: 693 additions & 1007 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
---
22
title: Cadence Anti-Patterns
3-
sidebar_position: 6
4-
sidebar_label: Anti-Patterns
53
---
64

75
This is an opinionated list of issues that can be improved if they are found in Cadence code intended for production.
@@ -50,9 +48,12 @@ fun transferNFT(id: UInt64, owner: auth(Storage) &Account) {
5048
transfer(id)
5149
5250
// Sneakily borrow a reference to the user's Flow Token Vault
53-
// and withdraw a bit of FLOW
51+
// and withdraw a bit of FLOW (modern Cadence 1.0 surface:
52+
// owner.storage.borrow with the Withdraw entitlement)
5453
// BAD
55-
let vaultRef = owner.borrow<&FlowToken.Vault>(/storage/flowTokenVault)!
54+
let vaultRef = owner.storage.borrow<auth(FungibleToken.Withdraw) &FlowToken.Vault>(
55+
from: /storage/flowTokenVault
56+
)!
5657
let stolenTokens <- vaultRef.withdraw(amount: 0.1)
5758
5859
// deposit the stolen funds in the contract owners vault
@@ -83,8 +84,8 @@ Accidentally exposed fields can be a security hole.
8384
### Solution
8485

8586
When writing your smart contract, look at every field and function and make sure
86-
that any functions that you don't want every user to be able to access require access through an [entitlement](./language/access-control.md#entitlements) (`access(E)`),
87-
or use a non-public [access modifier](./language/access-control.md) like `access(self)`, `access(contract)`, or `access(account)`.
87+
that any functions that you don't want every user to be able to access require access through an [entitlement](/docs/language/access-control#entitlements) (`access(E)`),
88+
or use a non-public [access modifier](/docs/language/access-control) like `access(self)`, `access(contract)`, or `access(account)`.
8889
Declaring a function as `access(all)` is a deliberate design decision to allow completely open and unrestricted access to read that field or call that function and should not be taken lightly.
8990

9091
The only functions that should be `access(all)` are `view` functions and functions the everyone should be able to access and the only fields that should be `access(all)` are basic types like numbers or addresses.

docs/cadence-migration-guide/core-contracts-guide.mdx renamed to content/docs/cadence-migration-guide/core-contracts-guide.mdx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
---
22
title: Protocol Smart Contracts 1.0 Changes Guide
3-
sidebar_position: 4
4-
sidebar_label: Core Contracts Guide
53
---
64

75
# Protocol Smart Contracts in Cadence 1.0
86

97
:::important
10-
118
On September 4th, 2024, the Flow Mainnet upgraded to Cadence 1.0. In addition to many changes to the Cadence programming language and the Cadence token standards, the Flow Protocol smart contracts were also updated to be compatible with the changes.
129

1310
All applications that interact with these contracts need to update their transactions and scripts in order to be compatible with these changes.
14-
1511
:::
16-
1712
## Important info
1813

1914
This document assumes you have a basic understanding of the [Cadence 1.0 improvements] and modifications to the Fungible Token Standard. We encourage you to consult those guides for more details on these changes if you are interested.
@@ -51,8 +46,8 @@ The NFT guide covers a lot of common changes that are required for NFT contracts
5146

5247
The core contracts do not have any meaningful changes outside of what is required to be compatible with Cadence 1.0 and the token standard changes. If you have questions about the core contracts changes for Cadence 1.0, please reach out to the Flow team in Discord and we will be happy to help.
5348

54-
<!-- Relative links. Will not render on the page -->
49+
{/* Relative links. Will not render on the page */}
5550

56-
[Cadence 1.0 improvements]: ./improvements.md
51+
[Cadence 1.0 improvements]: /docs/cadence-migration-guide/improvements
5752
[`master` branch of the flow-core-contracts repo]: https://github.com/onflow/flow-core-contracts
5853
[PR that made the changes]: https://github.com/onflow/flow-core-contracts/pull/319

docs/cadence-migration-guide/ft-guide.mdx renamed to content/docs/cadence-migration-guide/ft-guide.mdx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
---
22
title: Fungible Token Cadence 1.0 Migration Guide
3-
sidebar_position: 3
4-
sidebar_label: FT Cadence 1.0 Guide
53
---
64

75
# Fungible Tokens in Cadence 1.0
86

97
:::important
10-
118
On September 4th, 2024, the Flow Mainnet upgraded to Cadence 1.0. In addition to many changes to the Cadence programming language, the Cadence token standards also got streamlined and improved. All applications need to migrate their existing Cadence scripts and transactions for the update. If you do not update your code, your application will not function.
12-
139
:::
14-
1510
This document describes the changes to the Cadence Fungible Token (FT) standard. We'll be using the [`ExampleToken` contract] as an example. Many projects have used `ExampleToken` as a starting point for their projects, so it is widely applicable to most NFT developers on Flow. The upgrades required for `ExampleToken` will cover 90%+ of what you'll need to do to update your contract. Each project most likely has additional logic or features that aren't included in `ExampleToken`, but hopefully, after reading this guide, you'll understand Cadence 1.0 well enough that you can easily make any other changes that are necessary.
1611

1712
As always, there are plenty of people on the Flow team and in the community who are happy to help answer any questions you may have, so please reach out in Discord if you need any help.
@@ -65,7 +60,7 @@ access(all) fun deposit(from: @{FungibleToken.Vault})
6560

6661
If you have any more questions, please ask in discord and the Flow team will be happy to assist!
6762

68-
<!-- Relative links. Will not render on the page -->
63+
{/* Relative links. Will not render on the page */}
6964

7065
[`ExampleToken` contract]: https://github.com/onflow/flow-ft/blob/master/contracts/ExampleToken.cdc
7166
[FLIP]: https://github.com/onflow/flips/pull/55
@@ -75,4 +70,4 @@ If you have any more questions, please ask in discord and the Flow team will be
7570
[this PR in the hybrid custody repo]: https://github.com/onflow/hybrid-custody/pull/164
7671
[This Discord announcement]: https://discord.com/channels/613813861610684416/811693600403357706/1225909248429527140
7772
[Flow Contract Browser]: https://contractbrowser.com/
78-
[NFT Cadence 1.0 migration guide]: ./nft-guide.mdx
73+
[NFT Cadence 1.0 migration guide]: /docs/cadence-migration-guide/nft-guide

docs/cadence-migration-guide/improvements.md renamed to content/docs/cadence-migration-guide/improvements.mdx

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
---
22
title: Cadence 1.0 Improvements & New Features
3-
sidebar_position: 0
4-
sidebar_label: Improvements & New Features
53
---
64

75
## 💫 New features
@@ -1789,40 +1787,40 @@ If you have any questions or need help with the upgrade, feel free to reach out
17891787

17901788
Help is also available during the [Cadence 1.0 Office Hours] each week at 10:00AM PST on the Flow Developer Discord.
17911789

1792-
<!-- Relative links. Will not render on the page -->
1790+
{/* Relative links. Will not render on the page */}
17931791

1794-
[FLIP 1043]: https://github.com/onflow/flips/blob/main/cadence/20220708-resource-reference-invalidation.md
1795-
[FLIP 1056]: https://github.com/onflow/flips/blob/main/cadence/20220715-cadence-purity-analysis.md
1796-
[FLIP 111]: https://github.com/onflow/flips/blob/main/cadence/20230417-events-emitted-from-interfaces.md
1797-
[FLIP 118]: https://github.com/onflow/flips/blob/main/cadence/20230711-remove-type-requirements.md
1798-
[FLIP 13]: https://github.com/onflow/flips/blob/main/cadence/20221011-for-loop-semantics.md
1792+
[FLIP 1043]: https://github.com/onflow/flips/blob/main/cadence/20220708-resource-reference-invalidation
1793+
[FLIP 1056]: https://github.com/onflow/flips/blob/main/cadence/20220715-cadence-purity-analysis
1794+
[FLIP 111]: https://github.com/onflow/flips/blob/main/cadence/20230417-events-emitted-from-interfaces
1795+
[FLIP 118]: https://github.com/onflow/flips/blob/main/cadence/20230711-remove-type-requirements
1796+
[FLIP 13]: https://github.com/onflow/flips/blob/main/cadence/20221011-for-loop-semantics
17991797
[FLIP 131]: https://github.com/onflow/flips/pull/131
1800-
[FLIP 242]: https://github.com/onflow/flips/blob/main/cadence/20240123-capcon-get-capability-api-improvement.md
1801-
[FLIP 262]: https://github.com/onflow/flips/blob/main/cadence/20240415-remove-non-public-entitled-interface-members.md
1802-
[FLIP 40]: https://github.com/onflow/flips/blob/main/cadence/20221024-interface-inheritance.md
1803-
[FLIP 43]: https://github.com/onflow/flips/blob/main/cadence/20221018-change-fun-type-syntax.md
1804-
[FLIP 54]: https://github.com/onflow/flips/blob/main/cadence/20221214-auth-remodel.md
1805-
[FLIP 798]: https://github.com/onflow/flips/blob/main/cadence/20220203-capability-controllers.md
1806-
[FLIP 84]: https://github.com/onflow/flips/blob/main/cadence/20230505-remove-priv-and-pub.md
1807-
[FLIP 85]: https://github.com/onflow/flips/blob/main/cadence/20230505-remove-restricted-types.md
1808-
[FLIP 86: Introduce Built-in Mutability Entitlements]: https://github.com/onflow/flips/blob/main/cadence/20230519-built-in-mutability-entitlements.md
1809-
[FLIP 86]: https://github.com/onflow/flips/blob/main/cadence/20230519-built-in-mutability-entitlements.md
1810-
[FLIP 89: Change Member Access Semantics]: https://github.com/onflow/flips/blob/main/cadence/20230517-member-access-semnatics.md
1811-
[FLIP 89]: https://github.com/onflow/flips/blob/main/cadence/20230517-member-access-semnatics.md
1812-
[FLIP 92]: https://github.com/onflow/flips/blob/main/cadence/20230525-account-type.md
1813-
[FLIP 94]: https://github.com/onflow/flips/blob/main/cadence/20230623-entitlement-improvements.md
1814-
[FLIP 941]: https://github.com/onflow/flips/blob/main/cadence/20220516-reference-creation-semantics.md
1798+
[FLIP 242]: https://github.com/onflow/flips/blob/main/cadence/20240123-capcon-get-capability-api-improvement
1799+
[FLIP 262]: https://github.com/onflow/flips/blob/main/cadence/20240415-remove-non-public-entitled-interface-members
1800+
[FLIP 40]: https://github.com/onflow/flips/blob/main/cadence/20221024-interface-inheritance
1801+
[FLIP 43]: https://github.com/onflow/flips/blob/main/cadence/20221018-change-fun-type-syntax
1802+
[FLIP 54]: https://github.com/onflow/flips/blob/main/cadence/20221214-auth-remodel
1803+
[FLIP 798]: https://github.com/onflow/flips/blob/main/cadence/20220203-capability-controllers
1804+
[FLIP 84]: https://github.com/onflow/flips/blob/main/cadence/20230505-remove-priv-and-pub
1805+
[FLIP 85]: https://github.com/onflow/flips/blob/main/cadence/20230505-remove-restricted-types
1806+
[FLIP 86: Introduce Built-in Mutability Entitlements]: https://github.com/onflow/flips/blob/main/cadence/20230519-built-in-mutability-entitlements
1807+
[FLIP 86]: https://github.com/onflow/flips/blob/main/cadence/20230519-built-in-mutability-entitlements
1808+
[FLIP 89: Change Member Access Semantics]: https://github.com/onflow/flips/blob/main/cadence/20230517-member-access-semnatics
1809+
[FLIP 89]: https://github.com/onflow/flips/blob/main/cadence/20230517-member-access-semnatics
1810+
[FLIP 92]: https://github.com/onflow/flips/blob/main/cadence/20230525-account-type
1811+
[FLIP 94]: https://github.com/onflow/flips/blob/main/cadence/20230623-entitlement-improvements
1812+
[FLIP 941]: https://github.com/onflow/flips/blob/main/cadence/20220516-reference-creation-semantics
18151813
[Account keys]: https://developers.flow.com/cadence/language/accounts#account-keys
18161814
[Cadence 1.0 Office Hours]: https://calendar.google.com/calendar/ical/c_47978f5cd9da636cadc6b8473102b5092c1a865dd010558393ecb7f9fd0c9ad0%40group.calendar.google.com/public/basic.ics
1817-
[Cadence mutability restrictions FLIP]: https://github.com/onflow/flips/blob/main/cadence/20211129-cadence-mutability-restrictions.md
1818-
[Entitlements]: https://cadence-lang.org/docs/1.0/language/access-control#entitlements
1815+
[Cadence mutability restrictions FLIP]: https://github.com/onflow/flips/blob/main/cadence/20211129-cadence-mutability-restrictions
1816+
[Entitlements]: ../language/access-control#entitlements
18191817
[Flow Discord]: https://discord.gg/flowblockchain.
18201818
[Flow forum]: http://forum.flow.com/t/streamlined-token-standards-proposal/3075
18211819
[GitHub]: https://github.com/onflow/flow-nft/pull/126
1822-
[Hashing with a domain tag]: https://cadence-lang.org/docs/1.0/language/crypto#hashing-with-a-domain-tag
1820+
[Hashing with a domain tag]: ../language/crypto#hashing-with-a-domain-tag
18231821
[Nested Type Requirements]: https://docs.onflow.org/cadence/language/interfaces/#nested-type-requirements
1824-
[Signature verification]: https://cadence-lang.org/docs/1.0/language/crypto#signature-verification
1825-
[Upgrading Fungible Token Contracts]: ./ft-guide.mdx
1826-
[Upgrading Non-Fungible Token Contracts]: ./nft-guide.mdx
1827-
[Vision]: https://github.com/onflow/flips/blob/main/cadence/vision/mutability-restrictions.md
1822+
[Signature verification]: ../language/crypto#signature-verification
1823+
[Upgrading Fungible Token Contracts]: /docs/cadence-migration-guide/ft-guide
1824+
[Upgrading Non-Fungible Token Contracts]: /docs/cadence-migration-guide/nft-guide
1825+
[Vision]: https://github.com/onflow/flips/blob/main/cadence/vision/mutability-restrictions
18281826
[V2 FungibleToken Standard by joshuahannan — Pull Request #77 — onflow/flow-ft]: https://github.com/onflow/flow-ft/pull/77

docs/cadence-migration-guide/index.md renamed to content/docs/cadence-migration-guide/index.mdx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
title: Cadence 1.0 Migration Guide
3-
sidebar_position: 1
4-
sidebar_label: Cadence 1.0 Migration Guide
3+
description: "Migrate your Cadence code to 1.0 (Crescendo upgrade, Sep 2024): breaking changes, updated NFT/FT standards, new features, and step-by-step upgrade instructions."
54
---
65

76
On September 4th, 2024, the Flow Mainnet upgraded to Cadence 1.0.
@@ -24,10 +23,10 @@ In addition to changes to the Cadence programming language, the Cadence token st
2423
- [Guide for FT Standard v2]
2524
- [Cadence 1.0 Improvements & New Features]
2625

27-
<!-- Relative links. Will not render on the page -->
26+
{/* Relative links. Will not render on the page */}
2827

2928
[Crescendo]: https://flow.com/upgrade/crescendo
30-
[comprehensive suite of new features and improvements]: ./improvements.md
31-
[Guide for NFT Standard v2]: ./nft-guide.mdx
32-
[Guide for FT Standard v2]: ./ft-guide.mdx
33-
[Cadence 1.0 Improvements & New Features]: ./improvements.md
29+
[comprehensive suite of new features and improvements]: /docs/cadence-migration-guide/improvements
30+
[Guide for NFT Standard v2]: /docs/cadence-migration-guide/nft-guide
31+
[Guide for FT Standard v2]: /docs/cadence-migration-guide/ft-guide
32+
[Cadence 1.0 Improvements & New Features]: /docs/cadence-migration-guide/improvements
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"title": "Cadence 1.0 Migration Guide",
3+
"pages": [
4+
"...",
5+
"core-contracts-guide",
6+
"ft-guide",
7+
"improvements",
8+
"nft-guide"
9+
]
10+
}

docs/cadence-migration-guide/nft-guide.mdx renamed to content/docs/cadence-migration-guide/nft-guide.mdx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
---
22
title: Non-Fungible Token Cadence 1.0 Migration Guide
3-
sidebar_position: 2
4-
sidebar_label: NFT Cadence 1.0 Guide
53
---
64

75
# Non-Fungible Tokens in Cadence 1.0
86

97
:::important
10-
118
On September 4th, 2024, the Flow Mainnet upgraded to Cadence 1.0. In addition to many changes to the Cadence programming language, the Cadence token standards were also streamlined and improved. All applications' scripts and transactions need to be updated. If you do not update your code, your applications will not function properly.
12-
139
:::
14-
1510
This document describes the changes to the Cadence Non-Fungible Token (NFT) standard and gives a step-by-step guide for how to upgrade your NFT contract from Cadence 0.42 to Cadence 1.0.
1611

1712
We'll be using the [`ExampleNFT` contract] as an example. Many projects have used `ExampleNFT` as a starting point for their projects, so it is widely applicable to most NFT developers on Flow. The upgrades required for `ExampleNFT` will cover 90%+ of what you'll need to do to update your contract. Each project most likely has additional logic or features that aren't included in `ExampleNFT`, but hopefully, after reading this guide, you'll understand Cadence 1.0 well enough that you can easily make any other changes that are necessary.
@@ -112,7 +107,7 @@ Since `Collection` is an interface, you will need to update every instance in yo
112107

113108
This guide covered the most important changes that are required for the Cadence 1.0 upgrades to NFT contracts. Please ask any questions about the migrations in the #developer-questions channel in discord and good luck with your upgrades!
114109

115-
<!-- Relative links. Will not render on the page -->
110+
{/* Relative links. Will not render on the page */}
116111

117112
[`ExampleNFT` contract]: https://github.com/onflow/flow-nft/blob/master/contracts/ExampleNFT.cdc
118113
[`master` branch of the flow-nft repo]: https://github.com/onflow/flow-nft
File renamed without changes.

0 commit comments

Comments
 (0)