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