Skip to content

Commit 8ce2736

Browse files
Merge pull request #1 from onflow/c1-migration
C1 migration
2 parents 9b8ec78 + 3d74bf7 commit 8ce2736

File tree

14 files changed

+674
-92
lines changed

14 files changed

+674
-92
lines changed

.github/workflows/cadence_lint.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Run Cadence Contract Compilation, Deployment, Transaction Execution, and Lint
2+
on: push
3+
4+
jobs:
5+
run-cadence-lint:
6+
runs-on: macos-latest
7+
steps:
8+
- name: Checkout
9+
uses: actions/checkout@v3
10+
with:
11+
submodules: 'true'
12+
13+
- name: Install Flow CLI
14+
run: |
15+
brew update
16+
brew install flow-cli
17+
18+
- name: Initialize Flow
19+
run: |
20+
if [ ! -f flow.json ]; then
21+
echo "Initializing Flow project..."
22+
flow init
23+
else
24+
echo "Flow project already initialized."
25+
fi
26+
flow dependencies install
27+
28+
- name: Start Flow Emulator
29+
run: |
30+
echo "Starting Flow emulator in the background..."
31+
nohup flow emulator start > emulator.log 2>&1 &
32+
sleep 5 # Wait for the emulator to start
33+
flow project deploy --network=emulator # Deploy the recipe contracts indicated in flow.json
34+
35+
- name: Run All Transactions
36+
run: |
37+
echo "Running all transactions in the transactions folder..."
38+
for file in ./cadence/transactions/*.cdc; do
39+
echo "Running transaction: $file"
40+
TRANSACTION_OUTPUT=$(flow transactions send "$file" --signer emulator-account)
41+
echo "$TRANSACTION_OUTPUT"
42+
if echo "$TRANSACTION_OUTPUT" | grep -q "Transaction Error"; then
43+
echo "Transaction Error detected in $file, failing the action..."
44+
exit 1
45+
fi
46+
done
47+
48+
- name: Run Cadence Lint
49+
run: |
50+
echo "Running Cadence linter on .cdc files in the current repository"
51+
flow cadence lint ./cadence/**/*.cdc

.github/workflows/cadence_tests.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Run Cadence Tests
2+
on: push
3+
4+
jobs:
5+
run-cadence-tests:
6+
runs-on: macos-latest
7+
steps:
8+
- name: Checkout
9+
uses: actions/checkout@v3
10+
with:
11+
submodules: 'true'
12+
13+
- name: Install Flow CLI
14+
run: |
15+
brew update
16+
brew install flow-cli
17+
18+
- name: Initialize Flow
19+
run: |
20+
if [ ! -f flow.json ]; then
21+
echo "Initializing Flow project..."
22+
flow init
23+
else
24+
echo "Flow project already initialized."
25+
fi
26+
27+
- name: Run Cadence Tests
28+
run: |
29+
if test -f "cadence/tests.cdc"; then
30+
echo "Running Cadence tests in the current repository"
31+
flow test cadence/tests.cdc
32+
else
33+
echo "No Cadence tests found. Skipping tests."
34+
fi

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
.DS_Store
1+
.DS_Store
2+
/imports/
3+
/.idea/

README.md

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ This is for minting NFTS. It includes the minting resource that you can use in y
99
- [Description](#description)
1010
- [What is included in this repository?](#what-is-included-in-this-repository)
1111
- [Supported Recipe Data](#recipe-data)
12+
- [Deploying Recipe Contracts and Running Transactions Locally (Flow Emulator)](#deploying-recipe-contracts-and-running-transactions-locally-flow-emulator)
1213
- [License](#license)
1314

1415
## Description
@@ -19,7 +20,6 @@ The Cadence Cookbook is a collection of code examples, recipes, and tutorials de
1920

2021
Each recipe in the Cadence Cookbook is a practical coding example that showcases a specific aspect of Cadence or use-case on Flow, including smart contract development, interaction, and best practices. By following these recipes, you can gain hands-on experience and learn how to leverage Cadence for your blockchain projects.
2122

22-
2323
### Contributing to the Cadence Cookbook
2424

2525
Learn more about the contribution process [here](https://github.com/onflow/cadence-cookbook/blob/main/contribute.md).
@@ -34,17 +34,17 @@ Recipe metadata, such as title, author, and category labels, is stored in `index
3434

3535
```
3636
recipe-name/
37-
├── cadence/ # Cadence files for recipe examples
38-
│ ├── contract.cdc # Contract code
39-
│ ├── transaction.cdc # Transaction code
40-
│ ├── tests.cdc # Tests code
41-
├── explanations/ # Explanation files for recipe examples
42-
│ ├── contract.txt # Contract code explanation
43-
├── transaction.txt # Transaction code explanation
44-
├── tests.txt # Tests code explanation
45-
├── index.js # Root file for storing recipe metadata
46-
├── README.md # This README file
47-
└── LICENSE # License information
37+
├── cadence/ # Cadence files for recipe examples
38+
│ ├── contracts/Recipe.cdc # Contract code
39+
│ ├── transactions/mint_nft.cdc # Transaction code
40+
│ ├── tests/Recipe_test.cdc # Tests code
41+
├── explanations/ # Explanation files for recipe examples
42+
│ ├── contract.txt # Contract code explanation
43+
│ ├── transaction.txt # Transaction code explanation
44+
│ ├── tests.txt # Tests code explanation
45+
├── index.js # Root file for storing recipe metadata
46+
├── README.md # This README file
47+
└── LICENSE # License information
4848
```
4949

5050
## Supported Recipe Data
@@ -66,6 +66,7 @@ recipe-name/
6666
- `filters`: the filters object is used to perform filtering on recipes in the cookbook
6767
- `difficulty`: the difficulty filter supports one of ['beginner', 'intermediate', 'advanced']
6868

69+
6970
```
7071
// Pass the repo name
7172
const recipe = "sample-recipe-name";
@@ -94,6 +95,43 @@ export const sampleRecipe= {
9495
transactionExplanation: transactionExplanationPath,
9596
};
9697
```
98+
## Deploying Recipe Contracts and Running Transactions Locally (Flow Emulator)
99+
100+
This section explains how to deploy the recipe's contracts to the Flow emulator, run the associated transaction with sample arguments, and verify the results.
101+
102+
### Prerequisites
103+
104+
Before deploying and running the recipe:
105+
106+
1. Install the Flow CLI. You can find installation instructions [here](https://docs.onflow.org/flow-cli/install/).
107+
2. Ensure the Flow emulator is installed and ready to use with `flow version`.
108+
109+
### Step 1: Start the Flow Emulator
110+
111+
Start the Flow emulator to simulate the blockchain environment locally
112+
113+
```bash
114+
flow emulator start
115+
```
116+
117+
### Step 2: Install Dependencies and Deploy Project Contracts
118+
119+
Deploy contracts to the emulator. This will deploy all the contracts specified in the _deployments_ section of `flow.json` whether project contracts or dependencies.
120+
121+
```bash
122+
flow dependencies install
123+
flow project deploy --network=emulator
124+
```
125+
126+
### Step 3: Run the Transaction
127+
128+
Transactions associated with the recipe are located in `./cadence/transactions`. To run a transaction, execute the following command:
129+
130+
```bash
131+
flow transactions send cadence/transactions/TRANSACTION_NAME.cdc --signer emulator-account
132+
```
133+
134+
To verify the transaction's execution, check the emulator logs printed during the transaction for confirmation messages. You can add the `--log-level debug` flag to your Flow CLI command for more detailed output during contract deployment or transaction execution.
97135

98136
## License
99137

cadence/contract.cdc

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)