Skip to content

Commit c002134

Browse files
authored
Merge pull request #1547 from onflow/cleanup_docs_cws
Small cleanups reflecting style guide meeting
2 parents 44a8801 + 7b892f6 commit c002134

File tree

11 files changed

+212
-178
lines changed

11 files changed

+212
-178
lines changed

docs/blockchain-development-tutorials/cadence/cadence-advantages/compose-with-cadence-transactions.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ keywords:
1919
- Flowscan
2020
---
2121

22-
# Compose wth Cadence Transactions
23-
24-
## Overview
22+
# Compose wth Cadence transactions
2523

2624
In this tutorial, you'll **compose with someone else's contracts** on Flow testnet. You'll write a Cadence transaction that reads public state from a contract named `Counter` and only increments the counter when it is odd. Then you'll extend the transaction to mint NFTs when the counter is odd, demonstrating how to compose multiple contracts in a single transaction. Everything runs against testnet using the Flow CLI and the dependency manager.
2725

@@ -46,7 +44,7 @@ After you complete this guide, you will be able to:
4644
- Create: https://developers.flow.com/build/tools/flow-cli/commands#create-accounts
4745
- Fund: https://developers.flow.com/build/tools/flow-cli/commands#fund-accounts
4846

49-
## Getting Started
47+
## Get started
5048

5149
Create a [new project] with the [Flow CLI]:
5250

@@ -231,13 +229,13 @@ You could trigger this same transaction **from an app** and **signed by a wallet
231229

232230
---
233231

234-
## Extend with NFT Minting
232+
## Extend with NFT minting
235233

236234
Now let's take our composition to the next level by adding NFT minting functionality when the counter is odd. We'll use an example NFT contract that's already deployed on testnet.
237235

238236
This is a silly use case, but it demonstrates the complex use cases you can add to your apps, after contract deployment, and even if you aren't the author of any of the contracts!
239237

240-
### Install the NFT Contract
238+
### Install the NFT contract
241239

242240
First, let's install the ExampleNFT contract dependency:
243241

@@ -251,7 +249,7 @@ This repository uses different deployments for core contracts than those that th
251249

252250
:::
253251

254-
### Understanding NFT Minting
252+
### Understand NFT minting
255253

256254
Let's look at how NFT minting works with this contract. The [MintExampleNFT transaction] shows the pattern:
257255

@@ -291,7 +289,7 @@ transaction(
291289

292290
You can copy this functionality and adapt it for our use case.
293291

294-
### Update the IncrementIfOdd Transaction
292+
### Update the IncrementIfOdd transaction
295293

296294
Now let's update our `IncrementIfOdd` transaction to mint an NFT when the counter is odd. You can either modify the existing transaction or create a new one:
297295

@@ -341,7 +339,7 @@ transaction() {
341339
}
342340
```
343341

344-
### Setup NFT Collection
342+
### Setup NFT collection
345343

346344
Before you can mint NFTs, set up an NFT collection in your account. Create a transaction to do this:
347345

@@ -392,7 +390,7 @@ You may need to run the regular `IncrementCounter` transaction first to get an o
392390
flow transactions send cadence/transactions/IncrementCounter.cdc --signer testnet-account --network testnet
393391
```
394392

395-
### View Your NFT
393+
### View your NFT
396394

397395
Click the transaction link in the console to view the transaction in [testnet Flowscan]. After you run the transaction **while the counter is odd**, you'll see an NFT in the `Asset Transfers` tab.
398396

docs/blockchain-development-tutorials/cadence/cadence-advantages/native-data-availibility-with-cadence-scripts.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ keywords:
2323

2424
# Native Data Availability With Cadence Scripts
2525

26-
## Overview
27-
2826
In Solidity, you can only retrieve data from **view** functions that the contract author anticipated and included in the original contract. If the exact query you want is not exposed, teams typically rely on a _data availability service_ such as The Graph, Covalent, Alchemy Enhanced APIs, Reservoir, or NFTScan to compute and serve that view.
2927

3028
In Cadence, **scripts** are general-purpose read programs. They can traverse public account storage, read public capabilities, and compose types from multiple contracts to answer new questions without modifying those contracts. You are not limited to the pre-written surface area of a single contract's views.
@@ -62,7 +60,7 @@ If you are new to [_Hybrid Custody_], the high-level idea is that in Cadence, a
6260

6361
:::
6462

65-
## Getting Started
63+
## Get started
6664

6765
Create a new Flow project and generate a script file:
6866

@@ -83,7 +81,7 @@ We will **revise one script file** in four passes, and run it after each step. T
8381

8482
---
8583

86-
## Querying the account to find child accounts
84+
## Query the account to find child accounts
8785

8886
To start, write a script that borrows the parent's _Hybrid Custody_ manager and returns the child addresses it controls. This verifies that imports resolve and that the parent account is configured as expected.
8987

@@ -427,7 +425,7 @@ This demonstrates how you can easily modify Cadence scripts to answer different
427425
- If you see empty results in Step 4, confirm `isTopShot` matches the identifiers you observed in Step 3.
428426
- If you are not using _Hybrid Custody_, you can adapt Steps 2-4 to use `getAccount(child)` and scan **publicly exposed** `{NonFungibleToken.CollectionPublic}` capabilities, but you will not be able to assert provider access.
429427

430-
## How This Compares to Solidity
428+
## How This compares to Solidity
431429

432430
- **Solidity views are fixed**: You can only retrieve what the contract author exposed via `view` or `pure` functions. If you need a different aggregation or cross-contract traversal, you typically rely on a _data availability service_ or write a new contract to expose that view.
433431
- **Cadence scripts are flexible**: You compose types across modules, traverse account storage, and read public capabilities at query time. You do not need to redeploy contracts to answer new questions.

docs/blockchain-development-tutorials/cadence/cadence-advantages/upgrading-cadence-contracts.md

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ keywords:
1818

1919
# Upgrading Cadence Contracts
2020

21-
## Overview
22-
2321
In Cadence, you can upgrade deployed contracts by adding new functionality while preserving existing state and maintaining the same contract address. Unlike other blockchain platforms that require complex proxy patterns or complete redeployment, Cadence allows you to seamlessly extend your contracts with new functions and events through multiple incremental upgrades.
2422

2523
This tutorial demonstrates how to upgrade a deployed contract through two scenarios:
@@ -45,11 +43,11 @@ After you complete this guide, you will be able to:
4543
- A **funded testnet account** to deploy and update contracts.
4644
- See [Create accounts] and [Fund accounts] in the Flow CLI commands.
4745

48-
## Contract Upgrade Overview
46+
## Contract upgrade overview
4947

5048
Cadence provides a sophisticated contract upgrade system that allows you to modify deployed contracts while ensuring data consistency and preventing runtime crashes. It's crucial for successful upgrades that you understand what you can and can't change.
5149

52-
### What You CAN Upgrade
50+
### What you CAN upgrade
5351

5452
- **Add new functions** - Extend contract functionality with new methods.
5553
- **Add new events** - Emit additional events for monitoring and indexing.
@@ -59,15 +57,15 @@ Cadence provides a sophisticated contract upgrade system that allows you to modi
5957
- **Change access modifiers** - Update visibility of functions and fields.
6058
- **Reorder existing fields** - Field order doesn't affect storage.
6159

62-
### What You CANNOT Upgrade
60+
### What you CANNOT upgrade
6361

6462
- **Add new fields** - Would cause runtime crashes when loading existing data.
6563
- **Change field types** - Would cause deserialization errors.
6664
- **Remove existing fields** - Fields become inaccessible, but data remains.
6765
- **Change enum structures** - Raw values must remain consistent.
6866
- **Change contract name** - Contract address must remain the same.
6967

70-
### Why These Restrictions Exist
68+
### Why these restrictions exist
7169

7270
The [Cadence Contract Updatability documentation](https://cadence-lang.org/docs/language/contract-updatability) explains that these restrictions prevent:
7371

@@ -78,7 +76,7 @@ The [Cadence Contract Updatability documentation](https://cadence-lang.org/docs/
7876

7977
The validation system ensures that existing stored data remains valid and accessible after upgrades.
8078

81-
## Getting Started
79+
## Get started
8280

8381
Create a new Flow project for this tutorial:
8482

@@ -89,7 +87,7 @@ flow init upgrading-contracts-tutorial
8987

9088
Follow the prompts and create a `Basic Cadence project (no dependencies)` then open the new project in your editor.
9189

92-
### Create and Fund Testnet Account
90+
### Create and fund testnet account
9391

9492
You'll need a funded testnet account to deploy and update contracts. In a terminal in the root of your project folder:
9593

@@ -120,7 +118,7 @@ The faucet provides free testnet tokens for development and testing purposes. Th
120118

121119
---
122120

123-
## Deploy the Initial Counter Contract
121+
## Deploy the initial counter contract
124122

125123
To start, let's deploy a simple Counter contract to testnet.
126124

@@ -165,7 +163,7 @@ access(all) contract Counter {
165163
}
166164
```
167165

168-
### Configure Deployment
166+
### Configure deployment
169167

170168
Add testnet deployment configuration to your `flow.json`:
171169

@@ -210,7 +208,7 @@ Counter -> 0x9942a81bc6c3c5b7 (contract deployed successfully)
210208
🎉 All contracts deployed successfully
211209
```
212210

213-
### Test the Initial Contract
211+
### Test the initial contract
214212

215213
Use the provided transaction to test initial functionality:
216214

@@ -280,11 +278,11 @@ Events:
280278

281279
---
282280

283-
## Upgrade the Contract - Part 1: Adding Event for Even Numbers
281+
## Upgrade the contract - Part 1: Add event for even numbers
284282

285283
Let's start with a realistic scenario: What if we've realized it's very important to our users that they know when the counter reaches an even number, but we forgot to add an event for that case? Let's add that functionality first.
286284

287-
### Modify the Counter Contract - First Upgrade
285+
### Modify the Counter contract - first upgrade
288286

289287
Update `cadence/contracts/Counter.cdc` to add the new event and enhance the existing `increment()` function:
290288

@@ -330,7 +328,7 @@ access(all) contract Counter {
330328
}
331329
```
332330

333-
### Key Changes Made - Part 1
331+
### Key changes made - part 1
334332

335333
This first upgrade adds:
336334

@@ -346,11 +344,11 @@ This demonstrates how you can add new behavior and modify existing function beha
346344

347345
---
348346

349-
## Update the Deployed Contract - Part 1
347+
## Update the deployed contract - Part 1
350348

351349
Now let's update the deployed contract on testnet using the Flow CLI update command with our first upgrade.
352350

353-
### Update the Contract
351+
### Update the contract
354352

355353
Use the [Flow CLI update contract command] to upgrade your deployed contract:
356354

@@ -389,7 +387,7 @@ The contract successfully updated! Notice that:
389387

390388
:::
391389

392-
### Test the First Upgrade
390+
### Test the first upgrade
393391

394392
Let's test the new event functionality. Create a simple transaction to test the enhanced `increment()` function:
395393

@@ -429,11 +427,11 @@ Notice that:
429427

430428
---
431429

432-
## Upgrade the Contract - Part 2: Adding More Functionality
430+
## Upgrade the contract - Part 2: add more functionality
433431

434432
Now that we've successfully added the even number event, let's add more functionality to our contract. This demonstrates how you can make multiple incremental upgrades to extend your contract's capabilities.
435433

436-
### Modify the Counter Contract - Second Upgrade
434+
### Modify the Counter contract - second upgrade
437435

438436
Update `cadence/contracts/Counter.cdc` to add the additional functionality:
439437

@@ -502,7 +500,7 @@ access(all) contract Counter {
502500
}
503501
```
504502

505-
### Key Changes Made - Part 2
503+
### Key changes made - part 2
506504

507505
This second upgrade adds:
508506

@@ -513,11 +511,11 @@ This second upgrade adds:
513511

514512
---
515513

516-
## Update the Deployed Contract - Part 2
514+
## Update the deployed contract - Part 2
517515

518516
Now let's update the deployed contract with our second upgrade.
519517

520-
### Update the Contract Again
518+
### Update the contract again
521519

522520
Use the [Flow CLI update contract command] to upgrade your deployed contract with the additional functionality:
523521

@@ -557,7 +555,7 @@ The contract successfully updated again! Notice that:
557555

558556
:::
559557

560-
### Verify the Update
558+
### Verify the update
561559

562560
Let's verify that the existing functionality still works and the new functionality is available.
563561

@@ -599,11 +597,11 @@ Notice that:
599597

600598
---
601599

602-
## Test the New Functionality
600+
## Test the new functionality
603601

604602
Now let's create a transaction to test the new even counter functionality.
605603

606-
### Create Test Transaction
604+
### Create test transaction
607605

608606
Create a new transaction to test the upgraded functionality:
609607

@@ -651,7 +649,7 @@ transaction {
651649
}
652650
```
653651

654-
### Run the Test Transaction
652+
### Run the test transaction
655653

656654
Execute the transaction to test the new functionality:
657655

@@ -667,7 +665,7 @@ You will see logs that show:
667665
- The original `increment()` function still working normally
668666
- The new `CounterIncrementedToEven` event being emitted when incrementing results in an even number
669667

670-
### Verify Final State
668+
### Verify final state
671669

672670
Run the check script again to see the final state:
673671

@@ -689,11 +687,11 @@ This confirms that:
689687

690688
---
691689

692-
## Understanding Contract Upgrades in Cadence
690+
## Understand contract upgrades in Cadence
693691

694692
Cadence provides a sophisticated contract upgrade system that ensures data consistency while allowing controlled modifications. The [Cadence Contract Updatability documentation] provides comprehensive details about the validation rules and restrictions.
695693

696-
### What You Can Upgrade
694+
### What you can upgrade
697695

698696
When you upgrade Cadence contracts, you can:
699697

@@ -707,7 +705,7 @@ When you upgrade Cadence contracts, you can:
707705
- **Change access modifiers** of fields and functions
708706
- **Reorder existing fields** (order doesn't affect storage)
709707

710-
### What You Cannot Change
708+
### What You cannot change
711709

712710
There are important limitations to contract upgrades:
713711

@@ -734,9 +732,9 @@ The validation system focuses on preventing runtime inconsistencies with stored
734732

735733
:::
736734

737-
### Advanced Upgrade Patterns
735+
### Advanced upgrade patterns
738736

739-
#### The `#removedType` Pragma
737+
#### The `#removedType` pragma
740738

741739
For cases where you need to remove a type declaration (which is normally invalid), Cadence provides the `#removedType` pragma. This allows you to "tombstone" a type, which prevents it from being re-added with the same name:
742740

@@ -755,7 +753,7 @@ This pragma:
755753
- **Cannot be removed** after you add it (prevents circumventing restrictions).
756754
- **Only works with composite types**, not interfaces.
757755

758-
#### Enum Upgrade Restrictions
756+
#### Enum upgrade restrictions
759757

760758
Enums have special restrictions due to their raw value representation:
761759

@@ -764,7 +762,7 @@ Enums have special restrictions due to their raw value representation:
764762
- **Cannot change the raw type** of an enum.
765763
- **Cannot change enum case names** (would change stored values' meaning).
766764

767-
### Best Practices
765+
### Best practices
768766

769767
When you upgrade contracts:
770768

@@ -779,7 +777,7 @@ When you upgrade contracts:
779777

780778
---
781779

782-
## Why This Matters
780+
## Why this matters
783781

784782
Cadence's contract upgrade model provides several advantages:
785783

0 commit comments

Comments
 (0)