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
Copy file name to clipboardExpand all lines: docs/blockchain-development-tutorials/cadence/cadence-advantages/compose-with-cadence-transactions.md
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,7 @@ keywords:
19
19
- Flowscan
20
20
---
21
21
22
-
# Compose wth Cadence Transactions
22
+
# Compose wth Cadence transactions
23
23
24
24
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.
25
25
@@ -44,7 +44,7 @@ After you complete this guide, you will be able to:
@@ -229,13 +229,13 @@ You could trigger this same transaction **from an app** and **signed by a wallet
229
229
230
230
---
231
231
232
-
## Extend with NFT Minting
232
+
## Extend with NFT minting
233
233
234
234
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.
235
235
236
236
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!
237
237
238
-
### Install the NFT Contract
238
+
### Install the NFT contract
239
239
240
240
First, let's install the ExampleNFT contract dependency:
241
241
@@ -249,7 +249,7 @@ This repository uses different deployments for core contracts than those that th
249
249
250
250
:::
251
251
252
-
### Understanding NFT Minting
252
+
### Understand NFT minting
253
253
254
254
Let's look at how NFT minting works with this contract. The [MintExampleNFT transaction] shows the pattern:
255
255
@@ -289,7 +289,7 @@ transaction(
289
289
290
290
You can copy this functionality and adapt it for our use case.
291
291
292
-
### Update the IncrementIfOdd Transaction
292
+
### Update the IncrementIfOdd transaction
293
293
294
294
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:
295
295
@@ -339,7 +339,7 @@ transaction() {
339
339
}
340
340
```
341
341
342
-
### Setup NFT Collection
342
+
### Setup NFT collection
343
343
344
344
Before you can mint NFTs, set up an NFT collection in your account. Create a transaction to do this:
345
345
@@ -390,7 +390,7 @@ You may need to run the regular `IncrementCounter` transaction first to get an o
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.
Copy file name to clipboardExpand all lines: docs/blockchain-development-tutorials/cadence/cadence-advantages/native-data-availibility-with-cadence-scripts.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -60,7 +60,7 @@ If you are new to [_Hybrid Custody_], the high-level idea is that in Cadence, a
60
60
61
61
:::
62
62
63
-
## Getting Started
63
+
## Get started
64
64
65
65
Create a new Flow project and generate a script file:
66
66
@@ -81,7 +81,7 @@ We will **revise one script file** in four passes, and run it after each step. T
81
81
82
82
---
83
83
84
-
## Querying the account to find child accounts
84
+
## Query the account to find child accounts
85
85
86
86
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.
87
87
@@ -425,7 +425,7 @@ This demonstrates how you can easily modify Cadence scripts to answer different
425
425
- If you see empty results in Step 4, confirm `isTopShot` matches the identifiers you observed in Step 3.
426
426
- 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.
427
427
428
-
## How This Compares to Solidity
428
+
## How This compares to Solidity
429
429
430
430
-**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.
431
431
-**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.
Copy file name to clipboardExpand all lines: docs/blockchain-development-tutorials/cadence/cadence-advantages/upgrading-cadence-contracts.md
+33-33Lines changed: 33 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -43,11 +43,11 @@ After you complete this guide, you will be able to:
43
43
- A **funded testnet account** to deploy and update contracts.
44
44
- See [Create accounts] and [Fund accounts] in the Flow CLI commands.
45
45
46
-
## Contract Upgrade Overview
46
+
## Contract upgrade overview
47
47
48
48
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.
49
49
50
-
### What You CAN Upgrade
50
+
### What you CAN upgrade
51
51
52
52
-**Add new functions** - Extend contract functionality with new methods.
53
53
-**Add new events** - Emit additional events for monitoring and indexing.
@@ -57,15 +57,15 @@ Cadence provides a sophisticated contract upgrade system that allows you to modi
57
57
-**Change access modifiers** - Update visibility of functions and fields.
58
58
-**Reorder existing fields** - Field order doesn't affect storage.
59
59
60
-
### What You CANNOT Upgrade
60
+
### What you CANNOT upgrade
61
61
62
62
-**Add new fields** - Would cause runtime crashes when loading existing data.
63
63
-**Change field types** - Would cause deserialization errors.
64
64
-**Remove existing fields** - Fields become inaccessible, but data remains.
65
65
-**Change enum structures** - Raw values must remain consistent.
66
66
-**Change contract name** - Contract address must remain the same.
67
67
68
-
### Why These Restrictions Exist
68
+
### Why these restrictions exist
69
69
70
70
The [Cadence Contract Updatability documentation](https://cadence-lang.org/docs/language/contract-updatability) explains that these restrictions prevent:
71
71
@@ -76,7 +76,7 @@ The [Cadence Contract Updatability documentation](https://cadence-lang.org/docs/
76
76
77
77
The validation system ensures that existing stored data remains valid and accessible after upgrades.
Use the provided transaction to test initial functionality:
214
214
@@ -278,11 +278,11 @@ Events:
278
278
279
279
---
280
280
281
-
## Upgrade the Contract - Part 1: Adding Event for Even Numbers
281
+
## Upgrade the contract - Part 1: Add event for even numbers
282
282
283
283
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.
284
284
285
-
### Modify the Counter Contract - First Upgrade
285
+
### Modify the Counter contract - first upgrade
286
286
287
287
Update `cadence/contracts/Counter.cdc` to add the new event and enhance the existing `increment()` function:
@@ -344,11 +344,11 @@ This demonstrates how you can add new behavior and modify existing function beha
344
344
345
345
---
346
346
347
-
## Update the Deployed Contract - Part 1
347
+
## Update the deployed contract - Part 1
348
348
349
349
Now let's update the deployed contract on testnet using the Flow CLI update command with our first upgrade.
350
350
351
-
### Update the Contract
351
+
### Update the contract
352
352
353
353
Use the [Flow CLI update contract command] to upgrade your deployed contract:
354
354
@@ -387,7 +387,7 @@ The contract successfully updated! Notice that:
387
387
388
388
:::
389
389
390
-
### Test the First Upgrade
390
+
### Test the first upgrade
391
391
392
392
Let's test the new event functionality. Create a simple transaction to test the enhanced `increment()` function:
393
393
@@ -427,11 +427,11 @@ Notice that:
427
427
428
428
---
429
429
430
-
## Upgrade the Contract - Part 2: Adding More Functionality
430
+
## Upgrade the contract - Part 2: add more functionality
431
431
432
432
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.
433
433
434
-
### Modify the Counter Contract - Second Upgrade
434
+
### Modify the Counter contract - second upgrade
435
435
436
436
Update `cadence/contracts/Counter.cdc` to add the additional functionality:
Let's verify that the existing functionality still works and the new functionality is available.
561
561
@@ -597,11 +597,11 @@ Notice that:
597
597
598
598
---
599
599
600
-
## Test the New Functionality
600
+
## Test the new functionality
601
601
602
602
Now let's create a transaction to test the new even counter functionality.
603
603
604
-
### Create Test Transaction
604
+
### Create test transaction
605
605
606
606
Create a new transaction to test the upgraded functionality:
607
607
@@ -649,7 +649,7 @@ transaction {
649
649
}
650
650
```
651
651
652
-
### Run the Test Transaction
652
+
### Run the test transaction
653
653
654
654
Execute the transaction to test the new functionality:
655
655
@@ -665,7 +665,7 @@ You will see logs that show:
665
665
- The original `increment()` function still working normally
666
666
- The new `CounterIncrementedToEven` event being emitted when incrementing results in an even number
667
667
668
-
### Verify Final State
668
+
### Verify final state
669
669
670
670
Run the check script again to see the final state:
671
671
@@ -687,11 +687,11 @@ This confirms that:
687
687
688
688
---
689
689
690
-
## Understanding Contract Upgrades in Cadence
690
+
## Understand contract upgrades in Cadence
691
691
692
692
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.
693
693
694
-
### What You Can Upgrade
694
+
### What you can upgrade
695
695
696
696
When you upgrade Cadence contracts, you can:
697
697
@@ -705,7 +705,7 @@ When you upgrade Cadence contracts, you can:
705
705
-**Change access modifiers** of fields and functions
There are important limitations to contract upgrades:
711
711
@@ -732,9 +732,9 @@ The validation system focuses on preventing runtime inconsistencies with stored
732
732
733
733
:::
734
734
735
-
### Advanced Upgrade Patterns
735
+
### Advanced upgrade patterns
736
736
737
-
#### The `#removedType`Pragma
737
+
#### The `#removedType`pragma
738
738
739
739
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:
740
740
@@ -753,7 +753,7 @@ This pragma:
753
753
-**Cannot be removed** after you add it (prevents circumventing restrictions).
754
754
-**Only works with composite types**, not interfaces.
755
755
756
-
#### Enum Upgrade Restrictions
756
+
#### Enum upgrade restrictions
757
757
758
758
Enums have special restrictions due to their raw value representation:
759
759
@@ -762,7 +762,7 @@ Enums have special restrictions due to their raw value representation:
762
762
-**Cannot change the raw type** of an enum.
763
763
-**Cannot change enum case names** (would change stored values' meaning).
764
764
765
-
### Best Practices
765
+
### Best practices
766
766
767
767
When you upgrade contracts:
768
768
@@ -777,7 +777,7 @@ When you upgrade contracts:
777
777
778
778
---
779
779
780
-
## Why This Matters
780
+
## Why this matters
781
781
782
782
Cadence's contract upgrade model provides several advantages:
0 commit comments