Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into nialexsan/docusaurus-3
Browse files Browse the repository at this point in the history
  • Loading branch information
nialexsan committed Oct 31, 2023
2 parents 684bb6f + 3c72f7a commit f10128e
Show file tree
Hide file tree
Showing 28 changed files with 124 additions and 121 deletions.
2 changes: 1 addition & 1 deletion docs/build/basics/_category_.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
label: The Basics
label: Basic Concepts
position: 5
2 changes: 1 addition & 1 deletion docs/build/basics/fees.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ You should see the `computationUsed` field. Take a note of the value, you will u

**On testnet or mainnet**

Once a transaction is completed, you can use an explorer like [Flowscan](https://flowscan.org/) to review the transaction details and events emitted. For Flowscan, you can open the transaction in question and look for the event `FeesDeducted` from the [`FlowFees`](https://github.com/onflow/flow-core-contracts/blob/master/contracts/FlowFees.cdc) contract:
Once a transaction is completed, you can use an explorer like [Flowdiver](https://flowdiver.io/) to review the transaction details and events emitted. For Flowdiver, you can open the transaction in question and look for the event `FeesDeducted` from the [`FlowFees`](https://github.com/onflow/flow-core-contracts/blob/master/contracts/FlowFees.cdc) contract:

![flowscan-fees](./_fees_images/flowscan-fees.png)

Expand Down
2 changes: 1 addition & 1 deletion docs/build/building-vs-other-chains.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ If you’re already familiar with blockchain development, here's a comparison be
- [hardhat](https://hardhat.org/) / [Truffle](https://trufflesuite.com/) / [Foundry](https://github.com/foundry-rs/foundry)
- [Flow CLI](https://github.com/onflow/flow-cli/) provides local development tools and the [Flow Emulator](https://github.com/onflow/flow-emulator)
- [OpenZeppelin](https://www.openzeppelin.com/)
- No equivalent, you can pick contracts from any core Flow contract repository
- [Emerald OZ](https://oz.ecdao.org/overview)
- [go-ethereum](https://geth.ethereum.org/)
- [Flow Go SDK](https://github.com/onflow/flow-go-sdk/)
- [FCL](https://github.com/onflow/fcl-js/) also provides Backend API for Flow in JS
Expand Down
2 changes: 1 addition & 1 deletion docs/build/cadence.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Cadence, a new high-level programming language, observes the following requireme
Security is the prevention of attacks on the network or smart contracts (i.e., unauthorized actions by malicious actors).
Safety and security are critical in smart contracts because of the immutable nature of blockchains,
and because they often deal with high-value assets. While auditing and reviewing code will be a crucial part of smart contract development,
Cadence maximizes efficiency while maintaining the highest levels of safety and security at its foundation.
Cadence maximizes efficiency while maintaining the highest levels of safety and security.
It accomplishes this via a strong static type system, design by contract, and ownership primitives inspired by linear types (which are useful when dealing with assets).
- **Clarity:** Code needs to be easy to read, and its meaning should be as unambiguous as possible.
It should also be suited for verification so that tooling can help with ensuring safety and security guarantees.
Expand Down
2 changes: 1 addition & 1 deletion docs/build/getting-started/quickstarts/fcl-quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sidebar_position: 3

# Hello World Pt. 3 - Interacting with the Blockchain

FCL, or Flow Client Library, is a JavaScript library developed to facilitate interactions with the Flow blockchain. It provides developers with tools to build, integrate, and interact with Flow directly from web applications. This web app quickstart will get you interacting with a contract already deployed to Flow.
Flow Client Library (FCL), is a JavaScript library developed to facilitate interactions with the Flow blockchain. It provides developers with tools to build, integrate, and interact with Flow directly from web applications. This web app quickstart will get you interacting with a contract already deployed to Flow.

For this tutorial, we're going to be making a [React](https://react.dev/learn) app with [Create React App](https://create-react-app.dev/). We'll try and keep the code as simple as possible in case you're coming from another framework.

Expand Down
18 changes: 9 additions & 9 deletions docs/build/getting-started/quickstarts/flow-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sidebar_position: 2

# Hello World Pt. 2 - Local Development

The Flow CLI (Command Line Interface) is a set of tools that developers can use to interact with the Flow blockchain by managing accounts, sending transactions, deploying smart contracts, running the emulator, and more. This quickstart will get you familiar with its main concepts and functionality.
The Flow Command Line Interface (CLI) is a set of tools that developers can use to interact with the Flow blockchain by managing accounts, sending transactions, deploying smart contracts, running the emulator, and more. This quickstart will get you familiar with its main concepts and functionality.

## Installation

Expand All @@ -18,7 +18,7 @@ For other ways of installing, please [refer to the installation guide](../../../

## Configuration

Let's first create a directory, then setup a project.
Let's first create a directory, then set up a project.

```
mkdir cli-quickstart
Expand All @@ -30,13 +30,13 @@ And then let's navigate to our new directory:
cd cli-quickstart
```

Let's first create a `flow.json` file for our project (we'll use this in a later step, but this is a good spot to bring it up). The `flow.json` file is a configuration file used by the Flow CLI when interacting with the Flow blockchain. It helps manage various project-specific settings, such as network configurations, account details, contract names and source files, and deployment targets. To create one, run:
Let's first create a `flow.json` file for our project. We'll use this in a later step, but this is a good spot to bring it up. The `flow.json` file is a configuration file used by the Flow CLI when interacting with the Flow blockchain. It helps manage various project-specific settings, such as network configurations, account details, contract names and source files, and deployment targets. To create one, run:

```
flow init
```

If you look at `flow.json` now you'll see it's listed access nodes for networks and accounts. The default `emulator-account` create will come in handy when we want to run the emulator.
If you look at `flow.json` now, you'll see its listed access nodes for networks and accounts. The default `emulator-account` create will come in handy when we want to run the emulator.

## Running Scripts

Expand Down Expand Up @@ -118,7 +118,7 @@ Next we'll add a contracts section to our `flow.json` configuration that will de
}
```

We're also going to change the imports of our script so that there are no hardcoded network specific addresses. The CLI can figure out how to interact with the network (ie. emulator, testnet or mainnet) based on our configuration.
We're also going to change the imports of our script so that there are no hardcoded network specific addresses. The CLI can figure out how to interact with the network (i.e. emulator, testnet or mainnet) based on our configuration.

```
// script.cdc
Expand Down Expand Up @@ -166,9 +166,9 @@ flow scripts execute script.cdc --network emulator

## Creating an Account and Running a Transaction

To change state on the Flow Blockchain, you need to run a transaction. Let's create a simple transaction file, we can use to modify the `greeting` on the `HelloWorld` contract.
To change state on the Flow Blockchain, you need to run a transaction. Let's create a simple transaction file. We can use to modify the `greeting` on the `HelloWorld` contract.

First, create file called `transaction.cdc` from the root of your project:
First, create a file called `transaction.cdc` from the root of your project:

```
touch transaction.cdc
Expand All @@ -191,9 +191,9 @@ transaction(greeting: String) {
}
```

This will log the account signing the transaction and call the `changeGreeting` method of the `HelloWorld` contract, and pass in the new greeting. (If you want to learn more about writing transactions, please [read here](../../basics/transactions.md)).
This will log the account signing the transaction, call the `changeGreeting` method of the `HelloWorld` contract, and pass in the new greeting. (If you want to learn more about writing transactions, please [read here](../../basics/transactions.md)).

In order to run a transaction, the signing account needs to pay for it. We could run a transaction on emulator using the default `emulator-account` account, let's learn one more command for creating accounts.
In order to run a transaction, the signing account needs to pay for it. We could run a transaction on emulator using the default `emulator-account` account. Let's learn one more command for creating accounts.

The easiest way to create an account using CLI is by running (remember, your emulator should still be running at this point in another terminal):

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ sidebar_position: 3

FCL-JS is the easiest way to start building decentralized applications. FCL (aka Flow Client Library) wraps much of the logic you'd have to write yourself on other blockchains. Follow this quick start and you'll have a solid overview of how to build a shippable dapp on Flow.

We're going to make an assumption that you know or understand React; however, the concepts should be easy to understand and transfer to another framework. While this tutorial will make use of Cadence (Flow's smart contract language), you do not need to know it. Instead, we recommend later diving into [learning the Cadence language](../../build/cadence.md) once you've gotten the core FCL concepts down.
We're going to make an assumption that you know or understand React; however, the concepts should be easy to understand and transfer to another framework. While this tutorial will make use of Cadence (Flow's smart contract language), you do not need to know it. Instead, we recommend later diving into [learning the Cadence language](../cadence.md) once you've gotten the core FCL concepts down.

In this tutorial, we are going to interact with an existing smart contract on Flow's testnet known as the [Profile Contract](https://testnet.flowscan.org/contract/A.ba1132bc08f82fe2.Profile). Using this contract, we will create a new profile and edit the profile information, both via a wallet. In order to do this, the FCL concepts we'll cover are:
In this tutorial, we are going to interact with an existing smart contract on Flow's testnet known as the [Profile Contract](https://testnet.flowdiver.io/contract/A.ba1132bc08f82fe2.Profile). Using this contract, we will create a new profile and edit the profile information, both via a wallet. In order to do this, the FCL concepts we'll cover are:

- [Installation](#installation)
- [Configuration](#configuration)
Expand Down Expand Up @@ -196,7 +196,7 @@ config({
})
```
If you want to see the on chain smart contract we'll be speaking with next, you can view the [Profile Contract](https://testnet.flowscan.org/contract/A.ba1132bc08f82fe2.Profile) source code but again for this tutorial it's not necessary you understand it.
If you want to see the on chain smart contract we'll be speaking with next, you can view the [Profile Contract](https://testnet.flowdiver.io/contract/A.ba1132bc08f82fe2.Profile) source code but again for this tutorial it's not necessary you understand it.
**First, lets query the contract to see what the user's profile name is.**
Expand Down Expand Up @@ -301,13 +301,13 @@ Go ahead and click the "Send Query" button. You should see "No Profile." That's
## Initializing the Account
For the Profile contract to store a Profile in a user's account, it does so by initializing what is called a "resource." A resource is an ownable piece of data and functionality that can live in the user's account storage. This paradigm is known is as "resource-oriented-programming", a principle that is core to Cadence and differentiates its ownership model from other smart contract languages, [read more here](../../build/cadence.md#intuiting-ownership-with-resources). Cadence makes it so that resources can only exist in one place at any time, they must be deliberately created, cannot be copied, and if desired, must be deliberately destroyed.
For the Profile contract to store a Profile in a user's account, it does so by initializing what is called a "resource." A resource is an ownable piece of data and functionality that can live in the user's account storage. This paradigm is known is as "resource-oriented-programming", a principle that is core to Cadence and differentiates its ownership model from other smart contract languages, [read more here](../cadence.md#intuiting-ownership-with-resources). Cadence makes it so that resources can only exist in one place at any time, they must be deliberately created, cannot be copied, and if desired, must be deliberately destroyed.
> There's a lot more to resources in Cadence than we'll cover in this guide, so if you'd like to know more, check out [this Cadence intro](../../build/cadence.md).
> There's a lot more to resources in Cadence than we'll cover in this guide, so if you'd like to know more, check out [this Cadence intro](../cadence.md).
To do this resource initialization on an account, we're going to add another function called `initAccount`. Inside of that function, we're going to add some Cadence code which says, *"Hey, does this account have a profile? If it doesn't, let's add one."* We do that using something called a "transaction." Transactions occur when you want to change the state of the blockchain, in this case, some data in a resource, in a specific account. And there is a cost (transaction fee) in order to do that; unlike a query.
That's where we jump back into FCL code. Instead of `query`, we use `mutate` for transactions. And because there is a cost, we need to add a few fields that tell Flow who is proposing the transaction, who is authorizing it, who is paying for it, and how much they're willing to pay for it. Those fields — not surprisingly — are called: `proposer`, `authorizer`, `payer`, and `limit`. For more information on these signatory roles, check out [this doc](../../build/basics/transactions.md#signer-roles).
That's where we jump back into FCL code. Instead of `query`, we use `mutate` for transactions. And because there is a cost, we need to add a few fields that tell Flow who is proposing the transaction, who is authorizing it, who is paying for it, and how much they're willing to pay for it. Those fields — not surprisingly — are called: `proposer`, `authorizer`, `payer`, and `limit`. For more information on these signatory roles, check out [this doc](../basics/transactions.md#signer-roles).
Let's take a look at what our account initialization function looks like:
Expand Down Expand Up @@ -341,7 +341,7 @@ const initAccount = async () => {
}
```
You can see the new fields we talked about. You'll also notice `fcl.authz`. That's shorthand for "use the current user to authorize this transaction", (you could also write it as `fcl.currentUser.authorization`). If you want to learn more about transactions and signing transactions, you can [view the docs here](../../build/basics/transactions.md). For this example, we'll keep it simple with the user being each of these roles.
You can see the new fields we talked about. You'll also notice `fcl.authz`. That's shorthand for "use the current user to authorize this transaction", (you could also write it as `fcl.currentUser.authorization`). If you want to learn more about transactions and signing transactions, you can [view the docs here](../basics/transactions.md). For this example, we'll keep it simple with the user being each of these roles.
You'll also notice we are awaiting a response with our transaction data by using the syntax `fcl.tx(transactionId).onceSealed()`. This will return when the blockchain has sealed the transaction and it's complete in processing it and verifying it.
Expand Down Expand Up @@ -444,7 +444,7 @@ const styles = StyleSheet.create({

```
Press the "Init Account" button you should see the wallet ask you to approve a transaction. After approving, you will see a transaction response appear in your console (make sure to have that open). It may take a few moments. With the transaction result printed, you can use the `transactionId` to look up the details of the transaction using a [block explorer](https://testnet.flowscan.org).
Press the "Init Account" button you should see the wallet ask you to approve a transaction. After approving, you will see a transaction response appear in your console (make sure to have that open). It may take a few moments. With the transaction result printed, you can use the `transactionId` to look up the details of the transaction using a [block explorer](https://testnet.flowdiver.io/).
## Mutating the Blockchain
Expand Down
16 changes: 16 additions & 0 deletions docs/community-resources/projects.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,20 @@ Explore an array of exciting, grassroots initiatives, and projects that thrive w
githubLink: 'https://github.com/onflowser/flowser'
}
},
{
type: 'link',
label: 'Overflow',
href: 'https://github.com/bjartek/overflow',
description: 'Overflow is a Go-based DSL for testing and running interactive stories',
customProps: {
icon: '',
author: {
name: 'bjartek',
profileImage:
'https://avatars.githubusercontent.com/u/10621?v=4',
},
discordLink: 'https://discord.gg/t6GEtHnWFh',
githubLink: 'https://github.com/bjartek/overflow'
}
},
]} />
2 changes: 1 addition & 1 deletion docs/guides/flow-cli.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Flow CLI
sidebar_label: Flow CLI
sidebar_label: Install Flow CLI
description: Guide to installing and using Flow CLI
sidebar_position: 2
------
Expand Down
45 changes: 2 additions & 43 deletions docs/guides/nft.md
Original file line number Diff line number Diff line change
Expand Up @@ -671,49 +671,8 @@ pub fun borrowFooBarNFT(id: UInt64): &FooBar.NFT? {

### Contract Metadata

For the contract level metadata, we need to create an interface that defines the required methods for the contract. First, let’s create it by adding a new file. In your terminal, run:
For the contract level metadata, we need to create an interface that defines the required methods for the contract. Luckily, there is already a commonly used contract interface called `ViewResolver` deployed both to the Emulator and other networks. This interface requires a `getViews` and a `resolveViews` method. It is also deployed on [Testnet](https://testnet.contractbrowser.com/A.631e88ae7f1d7c20.ViewResolver) and [Mainnet](https://contractbrowser.com/A.1d7e57aa55817448.ViewResolver). You can find its address in the `flow.json` we generated with the `setup` command. To use it, return to your `FooBar` contract, import this new contract, and specify that `FooBar` should implement it.

```bash
touch cadence/contracts/ViewResolver.cdc
```

In it let’s add the following code, which says we need a `getViews` function and a `resolveView` function on our contract (just like we required on our NFT, but this time it’s for our contract):

```cadence
pub contract interface ViewResolver {
pub fun getViews(): [Type] {
return []
}
pub fun resolveView(_ view: Type): AnyStruct? {
return nil
}
}
```

Next, we need do also add this to our `flow.json` config. Run:

```bash
flow config add contract
```

When prompted, enter the following name and location (press `Enter` to skip alias questions):

```
Enter name: ViewResolver
Enter contract file location: cadence/contracts/ViewResolver.cdc
```

Next, configure the deployment settings by running the following command:

```bash
flow config add deployment
```

Like earlier in the guide, choose the `emulator` for the network and `emulator-account` for the account to deploy to. This time, select the `ViewResolver` contract (you may need to scroll down). After that, you can select `No` when asked to deploy another contract.

Now, go back to your `FooBar` contract, import this new contract, and state that `FooBar` should implement it:

```cadence
import "NonFungibleToken"
Expand Down Expand Up @@ -759,7 +718,7 @@ pub fun getViews(): [Type] {
}
```

Finally, we need a way to get read this data like we did with the NFT. Let’s also make a `borrowViewResolver` function that we add below the `borrowFooBarNFT` method inside of the `Collection`:
Finally, we need a way to read this data like we did with the NFT. Let’s also make a `borrowViewResolver` function that we add below the `borrowFooBarNFT` method inside of the `Collection`:

```cadence
pub resource Collection: NonFungibleToken.Provider, NonFungibleToken.Receiver, NonFungibleToken.CollectionPublic, MetadataViews.ResolverCollection {
Expand Down
Loading

0 comments on commit f10128e

Please sign in to comment.