Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update flix documentation, add verbiage about new flix command package #431

Merged
merged 5 commits into from
Nov 2, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 103 additions & 25 deletions docs/tools/flow-cli/flix.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,124 @@
---
title: Execute Flow Interaction Templates (FLIX) with the Flow CLI
sidebar_title: Execute FLIX
description: How to execute Flow Interaction Templates (FLIX) on Flow from the command line
title: Flow Interaction Templates (FLIX) via the CLI
sidebar_label: Flow Interaction Templates (FLIX)
description: Flow Interaction Templates (FLIX) on Flow from the command line
bthaile marked this conversation as resolved.
Show resolved Hide resolved
sidebar_position: 12
---
## Introduction

The Flow CLI provides a command to execute Flow Interaction Templates (FLIX). FLIX are an easy way to interact with Flow. They are a standard for distributing Cadence scripts and transactions, and metadata about them, in a way that is consumable by tooling and wallets. FLIX are audited for correctness and safety by an ecosystem of auditors.
The Flow CLI provides a `flix` command with a few sub commands `execute` and `package`. Get familiar with Flow Interaction Templates [(FLIX)](https://github.com/onflow/flips/blob/main/application/20220503-interaction-templates.md). FLIX are a standard for distributing Cadence scripts and transactions, and metadata in a way that is consumable by tooling and wallets. FLIX can be audited for correctness and safety by auditors in the ecosystem.

```shell
flow flix <query> [<argument> <argument>...] [flags]
>flow flix
execute, package

Usage:
flow flix [command]

Available Commands:
execute execute FLIX template with a given id, name, or local filename
package package file for FLIX template fcl-js is default


```

Queries can be a FLIX id, name, or path to a local FLIX file.
### Execute

## Example Usage
The Flow CLI provides a `flix` command to `execute` FLIX. The Cadence being execute in the FLIX can be a transaciton or script.

```shell
flow flix execute <query> [<argument> <argument>...] [flags]
```

Queries can be a FLIX `id`, `name`, or `path` to a local FLIX file.

### Execute Usage

```shell
# Execute a FLIX transaction by name on Testnet
flow flix transfer-flow 5.0 "0x123" --network testnet --signer "testnet-account"
flow flix execute transfer-flow 5.0 "0x123" --network testnet --signer "testnet-account"
```

```shell
# Execute a FLIX script by id on Testnet
flow flix bd10ab0bf472e6b58ecc0398e9b3d1bd58a4205f14a7099c52c0640d9589295f --network testnet
flow flix execute bd10ab0bf472e6b58ecc0398e9b3d1bd58a4205f14a7099c52c0640d9589295f --network testnet
```

```shell
# Execute a local FLIX script by path on Testnet
flow flix ./multiply.template.json 2 3 --network testnet
flow flix execute ./multiply.template.json 2 3 --network testnet
```

The Flow CLI provides a `flix` command to `package` up generated plain and simple JavaScript. This JavaScript uses FCL (Flow Client Library) to call the cadence the Flow Interaction Templates (FLIX) is based on.

<Callout type="info">
Currently, flix `package` command only supports generating FCL (Flow Client Library) specific JavaScript, there are plans to support other languages like golang.
</Callout>


```shell
flow flix package <query> [flags]
```

## Package

Queries can be a FLIX `id`, `name`, or `path` to a local FLIX file. This command leverages [@onflow/fcl](https://www.npmjs.com/package/@onflow/fcl) to ingest a template that has Cadence code.
bthaile marked this conversation as resolved.
Show resolved Hide resolved

### Package Usage

```shell
# Generate packaged code that leverages FCL to call the Cadence transaction code, `--save` flag will save the output to a specific file
flow flix package transfer-flow --save ./package/transfer-flow.js
bthaile marked this conversation as resolved.
Show resolved Hide resolved
```

```shell
# Geneate package code for a FLIX script using id, since there is no saving file, the result will display in terminal
flow flix package bd10ab0bf472e6b58ecc0398e9b3d1bd58a4205f14a7099c52c0640d9589295f
```

```shell
# Generate package code using local template file to save in a local file
flow flix package ./multiply.template.json --save ./multiply.js
```

### Example package output
bthaile marked this conversation as resolved.
Show resolved Hide resolved
```shell
flow flix package transfer-flow
```

```javascript

/**
This binding file was auto generated based on FLIX template v1.0.0.
Changes to this file might get overwritten.
Note fcl version 1.3.0 or higher is required to use templates.
**/

import * as fcl from "@onflow/fcl"
const flixTemplate = "transfer-flow"

/**
* Transfer tokens from one account to another
* @param {Object} Parameters - parameters for the cadence
* @param {string} Parameters.amount - The amount of FLOW tokens to send: UFix64
* @param {string} Parameters.to - The Flow account the tokens will go to: Address
* @returns {Promise<string>} - returns a promise which resolves to the transaction id
*/
export async function transferTokens({amount, to}) {
const transactionId = await fcl.mutate({
template: flixTemplate,
args: (arg, t) => [arg(amount, t.UFix64), arg(to, t.Address)]
});

return transactionId
}
```

<Callout type="info">
bthaile marked this conversation as resolved.
Show resolved Hide resolved
SOON: `flix generate` will generate FLIX json files using FLIX specific properties in comment blocks directly in Cadence code, [FLIP - Interaction Template Cadence Doc](https://github.com/onflow/flips/pull/80)
bthaile marked this conversation as resolved.
Show resolved Hide resolved
</Callout>


## Resources

To find out more about FLIX, see the [read the FLIP](https://github.com/onflow/flips/blob/main/application/20220503-interaction-templates.md).
Expand All @@ -40,19 +129,18 @@ To generate a FLIX, see the [FLIX CLI readme](https://github.com/onflow/flow-int

## Arguments
- Name: `argument`
- Valid inputs: valid [cadence values](../../cadence/json-cadence-spec.md)
matching argument type in script code.
- Valid input: valid [FLIX](https://github.com/onflow/flips/blob/main/application/20220503-interaction-templates.md)

Input arguments values matching corresponding types in the source code and passed in the same order.
You can pass a `nil` value to optional arguments by executing the flow script like this: `flow scripts execute script.cdc nil`.
Input argument value matching corresponding types in the source code and passed in the same order.
You can pass a `nil` value to optional arguments by executing the flow FLIX execute script like this: `flow flix execute template.json nil`.

## Flags

### Arguments JSON

- Flag: `--args-json`
- Valid inputs: arguments in JSON-Cadence form.
- Example: `flow scripts execute script.cdc '[{"type": "String", "value": "Hello World"}]'`
- Example: `flow flix execute template.script.json '[{"type": "String", "value": "Hello World"}]'`

Arguments passed to the Cadence script in the Cadence JSON format.
Cadence JSON format contains `type` and `value` keys and is
Expand Down Expand Up @@ -96,16 +184,6 @@ Specify the name of the account that will be used as payer in the transaction.

Specify the name of the account(s) that will be used as authorizer(s) in the transaction. If you want to provide multiple authorizers separate them using commas (e.g. `alice,bob`)

### Arguments JSON

- Flag: `--args-json`
- Valid inputs: arguments in JSON-Cadence form.
- Example: `flow transactions send ./tx.cdc '[{"type": "String", "value": "Hello World"}]'`

Arguments passed to the Cadence transaction in Cadence JSON format.
Cadence JSON format contains `type` and `value` keys and is
[documented here](../../cadence/json-cadence-spec.md).

### Gas Limit

- Flag: `--gas-limit`
Expand Down